formatters.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <iostream>
16 #include <string>
17 #include "../../include/ecl/formatters/common.hpp"
18 #include "../../include/ecl/formatters/floats.hpp"
19 #include "../../include/ecl/formatters/number.hpp"
20 #include "../../include/ecl/formatters/strings.hpp"
21 
22 /*****************************************************************************
23 ** Using
24 *****************************************************************************/
25 
26 using std::string;
27 using ecl::Format;
28 using ecl::Dec;
29 using ecl::Fixed;
30 using ecl::Hex;
31 using ecl::CentreAlign;
32 using ecl::LeftAlign;
33 using ecl::NoAlign;
34 using ecl::RightAlign;
35 
36 /*****************************************************************************
37 ** Main
38 *****************************************************************************/
39 
40 int main() {
41 
42  unsigned char c = 69;
43  Format<unsigned char> format(8,RightAlign,Hex); // Initialisation
44 
45  std::cout << std::endl;
46  std::cout << "***********************************************************" << std::endl;
47  std::cout << " Temporary Formatting [Number]" << std::endl;
48  std::cout << "***********************************************************" << std::endl;
49  std::cout << std::endl;
50 
51  std::cout << "NoAlign : " << format(c,8,NoAlign,Hex) << std::endl;
52  std::cout << "LeftAlign : " << format(c,8,LeftAlign,Hex) << std::endl;
53  std::cout << "CentreAlign: " << format(c,8,CentreAlign,Hex) << std::endl;
54  std::cout << "RightAlign : " << format(c,8,RightAlign,Hex) << std::endl;
55 
56  std::cout << std::endl;
57  std::cout << "***********************************************************" << std::endl;
58  std::cout << " Temporary Formatting [Number]" << std::endl;
59  std::cout << "***********************************************************" << std::endl;
60  std::cout << std::endl;
61 
62  std::cout << "NoAlign : " << format(c,8,NoAlign,Hex) << std::endl;
63  std::cout << "LeftAlign : " << format(c,8,LeftAlign,Hex) << std::endl;
64  std::cout << "CentreAlign: " << format(c,8,CentreAlign,Hex) << std::endl;
65  std::cout << "RightAlign : " << format(c,8,RightAlign,Hex) << std::endl;
66 
67  std::cout << std::endl;
68  std::cout << "***********************************************************" << std::endl;
69  std::cout << " Permanent Formatting [Number]" << std::endl;
70  std::cout << "***********************************************************" << std::endl;
71  std::cout << std::endl;
72 
73  std::cout << "NoAlign : " << format(8,NoAlign,Hex)(c) << std::endl;
74  std::cout << "LeftAlign : " << format(8,LeftAlign,Hex)(c) << std::endl;
75  std::cout << "CentreAlign: " << format(8,CentreAlign,Hex)(c) << std::endl;
76  std::cout << "RightAlign : " << format(8,RightAlign,Hex)(c) << std::endl;
77 
78  std::cout << std::endl;
79  std::cout << "***********************************************************" << std::endl;
80  std::cout << " Single Parameter Formatting [Number]" << std::endl;
81  std::cout << "***********************************************************" << std::endl;
82  std::cout << std::endl;
83 
84  std::cout << "Width : " << format.width(14)(c) << std::endl;
85  std::cout << "Align : " << format.align(CentreAlign)(c) << std::endl;
86  std::cout << "Base : " << format.base(Dec)(c) << std::endl;
87 
88  std::cout << std::endl;
89  std::cout << "***********************************************************" << std::endl;
90  std::cout << " Integral Types" << std::endl;
91  std::cout << "***********************************************************" << std::endl;
92  std::cout << std::endl;
93 
94  std::cout << "char : " << Format<unsigned char>(8,RightAlign,Dec)('c') << std::endl;
95  std::cout << "short : " << Format<short>(8,RightAlign,Dec)(123) << std::endl;
96  std::cout << "unsigned short: " << Format<unsigned short>(8,RightAlign,Dec)(123) << std::endl;
97  std::cout << "int : " << Format<int>(8,RightAlign,Dec)(-111123) << std::endl;
98  std::cout << "unsigned int : " << Format<unsigned int>(8,RightAlign,Dec)(111123) << std::endl;
99  std::cout << "long : " << Format<long>(8,RightAlign,Dec)(-1111123) << std::endl;
100  std::cout << "unsigned long : " << Format<unsigned long>(8,RightAlign,Dec)(1111123) << std::endl;
101 
102  std::cout << std::endl;
103  std::cout << "***********************************************************" << std::endl;
104  std::cout << " String Formats" << std::endl;
105  std::cout << "***********************************************************" << std::endl;
106  std::cout << std::endl;
107 
108  Format<string> sformat(10,RightAlign);
109  std::cout << "Strings: " << sformat(string("Dude")) << std::endl;
110  std::cout << "Strings: " << sformat(string("Dudette")) << std::endl;
111  std::cout << "Strings: " << sformat(string("Dudonimous")) << std::endl;
112  std::cout << "CString: " << sformat("Dude") << std::endl;
113  std::cout << "TmpFrmt: " << sformat("Dude",10,CentreAlign) << std::endl;
114  std::cout << "PrmFrmt: " << sformat(10,CentreAlign)("Dude") << std::endl;
115 
116  std::cout << std::endl;
117  std::cout << "***********************************************************" << std::endl;
118  std::cout << " Float Formats" << std::endl;
119  std::cout << "***********************************************************" << std::endl;
120  std::cout << std::endl;
121 
122  Format<float> fformat;
123  float f = -12235.135;
124  fformat.base(Fixed);
125  fformat.width(15);
126  fformat.precision(3);
127  fformat.align(LeftAlign);
128  fformat.align(CentreAlign);
129  fformat.align(RightAlign);
130  fformat(2,15,RightAlign,Fixed);
131  fformat(2,15);
132  std::cout << "TmpFrmt: " << fformat(f,2,15,CentreAlign,Fixed) << std::endl;
133  std::cout << "TmpFrmt: " << fformat(f,2,15) << std::endl;
134  std::cout << "Format : " << fformat(f) << std::endl;
135 
136  std::cout << std::endl;
137  std::cout << "***********************************************************" << std::endl;
138  std::cout << " Double Formats" << std::endl;
139  std::cout << "***********************************************************" << std::endl;
140  std::cout << std::endl;
141 
142  Format<double> dformat;
143  double d = 134.2352;
144  dformat.base(Fixed); // Format setters
145  dformat.width(15);
146  dformat.precision(3);
147  dformat.align(LeftAlign);
148  dformat.align(CentreAlign);
149  dformat.align(RightAlign);
150  dformat(2,15,RightAlign,Fixed); // Combo format operators
151  dformat(4,15);
152  std::cout << "TmpFrmt: " << dformat(d,2,15,CentreAlign,Fixed) << std::endl;
153  std::cout << "TmpFrmt: " << dformat(d,3,15) << std::endl;
154  std::cout << "Format : " << dformat(d) << std::endl;
155 
156  std::cout << std::endl;
157  std::cout << "***********************************************************" << std::endl;
158  std::cout << " Passed" << std::endl;
159  std::cout << "***********************************************************" << std::endl;
160  std::cout << std::endl;
161 
162  return 0;
163 }
Align to the left.
Definition: common.hpp:32
Primary template for all formatter classes.
Definition: common.hpp:99
Hex representation for integral types.
Definition: number.hpp:40
int main()
Definition: formatters.cpp:40
No alignment used.
Definition: common.hpp:31
Fixed formatting for floats (i.e. normal decimal representation).
Definition: floats.hpp:44
Align to the right.
Definition: common.hpp:33
void f(int i) ecl_debug_throw_decl(StandardException)
Decimal (i.e. normal) representation for integral types.
Definition: number.hpp:41
Align in the centre.
Definition: common.hpp:34


ecl_formatters
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:24