Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JManip.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 
6 #include "JLang/JManip.hh"
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JMessage.hh"
10 
11 namespace {
12 
13  struct A {
14 
15  A(const double value) : value(value) {}
16 
17  friend inline std::ostream& operator<<(std::ostream& out, const A& object)
18  {
19  const JFormat format(out, getFormat<A>(JFormat_t(5, 2, std::ios::fixed | std::ios::showpos)));
20 
21  return out << format << object.value;
22  }
23 
24  double value;
25  };
26 
27  struct B {
28 
29  B(const double value) : value(value) {}
30 
31  friend inline std::ostream& operator<<(std::ostream& out, const B& object)
32  {
33  const JFormat format(out, getFormat<B>(JFormat_t(12, 3, std::ios::scientific | std::ios::showpos)));
34 
35  return out << format << object.value;
36  }
37 
38  double value;
39  };
40 
41 
42  inline void print(std::ostream& out, const JFormat_t& format)
43  {
44  out << "(" << format.width << "," << format.precision << ")";
45  }
46 }
47 
48 
49 /**
50  * \file
51  * Example program to test I/O manipulators.
52  * \author mdejong
53  */
54 int main(int argc, char* argv[])
55 {
56  using namespace std;
57  using namespace JPP;
58 
59  int debug;
60 
61  try {
62 
63  JParser<> zap;
64 
65  zap['d'] = make_field(debug) = 1;
66 
67  zap(argc, argv);
68  }
69  catch(const exception &error) {
70  FATAL(error.what() << endl);
71  }
72 
73  for (int value = 1; value < 1000000000; value *= 10) {
74  cout << "CENTER <" << CENTER(12) << value << ">" << endl;
75  }
76 
77  for (int value = 1; value < 1000000000; value *= 10) {
78  cout << "FILL <" << FILL(12,'.') << value << ">" << FILL() << endl;
79  }
80 
81  for (int value = 1; value < 1000000000; value *= 10) {
82  cout << "RIGHT <" << RIGHT(12) << value << ">" << endl;
83  }
84 
85  for (int value = 1; value < 1000000000; value *= 10) {
86  cout << "LEFT <" << LEFT(12) << value << ">" << endl;
87  }
88 
89  for (double value = 0.123456; value < 100000; value *= 10) {
90  cout << "FIXED <" << FIXED(12,6) << value << ">" << endl;
91  }
92 
93 
94  {
95  const double c = 12.34;
96 
97  const A a(c);
98  const B b(c);
99 
100  cout << "A "; print(cout, getFormat<A>()); cout << " <" << a << ">" << endl;
101  cout << "c "; cout << setw(5) << " "; cout << " <" << c << ">" << endl;
102  cout << "B "; print(cout, getFormat<B>()); cout << " <" << b << ">" << endl;
103  cout << "c "; cout << setw(5) << " "; cout << " <" << c << ">" << endl;
104 
105  setFormat<A>(JFormat_t(7, 3, std::ios::fixed));
106  setFormat<B>(JFormat_t(7, 3, std::ios::fixed));
107 
108  cout << "A "; print(cout, getFormat<A>()); cout << " <" << a << ">" << endl;
109  cout << "c "; cout << setw(5) << " "; cout << " <" << c << ">" << endl;
110  cout << "B "; print(cout, getFormat<B>()); cout << " <" << b << ">" << endl;
111  cout << "c "; cout << setw(5) << " "; cout << " <" << c << ">" << endl;
112  }
113 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int width
Definition: JManip.hh:619
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:445
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:631
Auxiliary data structure for alignment of data.
Definition: JManip.hh:365
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int precision
Definition: JManip.hh:620
int debug
debug level
Definition: JSirene.cc:63
print
Definition: JConvertDusj.sh:44
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
I/O manipulators.
#define FATAL(A)
Definition: JMessage.hh:67
then $JPP_DIR software JCalibrate JCalibrateToT a
Definition: JTuneHV.sh:108
Utility class to parse command line options.
std::ostream & operator<<(std::ostream &stream, const CLBCommonHeader &header)
Data structure for format specifications.
Definition: JManip.hh:521
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
int main(int argc, char *argv[])
Definition: Main.cpp:15