formatters.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <iostream>
16 #include <ecl/formatters.hpp>
17 #include "../../include/ecl/containers/array.hpp"
18 #include "../../include/ecl/containers/push_and_pop.hpp"
19 #include "../../include/ecl/containers/stencil.hpp"
20 
21 /*****************************************************************************
22 ** Using
23 *****************************************************************************/
24 
25 using ecl::Array;
26 using ecl::Format;
27 using ecl::Hex;
28 using ecl::NoAlign;
29 using ecl::Stencil;
30 
31 /*****************************************************************************
32 ** Main program
33 *****************************************************************************/
34 
35 int main(int argc, char **argv) {
36 
37  std::cout << std::endl;
38  std::cout << "***********************************************************" << std::endl;
39  std::cout << " Arrays" << std::endl;
40  std::cout << "***********************************************************" << std::endl;
41  std::cout << std::endl;
42 
43  Array<int,4> int_array;
44  int_array << 1,2,3,4;
45  Array<float,4> float_array;
46  float_array << 1,2,3.32235,-324;
47  Format< Array<int,4> > format_array;
48 // Format< Array<float,4> > format_array_float;
49  Array<float,4>::Formatter format_array_float;
50  format_array_float.precision(3);
51  std::cout << format_array(int_array) << std::endl;
52  std::cout << format_array_float(float_array) << std::endl;
53 
54  std::cout << std::endl;
55  std::cout << "***********************************************************" << std::endl;
56  std::cout << " Dynamic Arrays" << std::endl;
57  std::cout << "***********************************************************" << std::endl;
58  std::cout << std::endl;
59 
60  Array<float> float_array_dynamic(4);
61  Format< Array<float> > format_array_dynamic_float;
62  format_array_dynamic_float.precision(3);
63  float_array_dynamic << 1,2,3.32235,-324;
64  std::cout << format_array_dynamic_float(float_array_dynamic) << std::endl;
65 
66  std::cout << std::endl;
67  std::cout << "***********************************************************" << std::endl;
68  std::cout << " Float Stencils" << std::endl;
69  std::cout << "***********************************************************" << std::endl;
70  std::cout << std::endl;
71 
72  Array<float> float_array_under(20);
73  float_array_under << 1,2,3.32235,-324;
74  Format< Stencil< Array<float> > > format_stencil;
75  format_stencil.precision(3);
76  std::cout << format_stencil(float_array_under.stencil(1,2)) << std::endl;
77  Array<double> double_array_under(20);
78  double_array_under << 1,2,3.32235,-324;
79  Format< Stencil< Array<double> > > format_double_stencil;
80  format_double_stencil.precision(3);
81  std::cout << format_double_stencil(double_array_under.stencil(1,2)) << std::endl;
82 
83  std::cout << std::endl;
84  std::cout << "***********************************************************" << std::endl;
85  std::cout << " Byte Arrays" << std::endl;
86  std::cout << "***********************************************************" << std::endl;
87  std::cout << std::endl;
88 
89  Array<signed char,4> schar_array;
90  schar_array << 'a','b','c','d';
91  Format< Array<signed char,4> > format_sbytes;
92  std::cout << schar_array << std::endl;
93  std::cout << format_sbytes(schar_array) << std::endl;
94  std::cout << format_sbytes(schar_array.stencil(0,2)) << std::endl;
95  Array<char,4> char_array;
96  char_array << 'a','b','c','d';
97  Array<char,4>::Formatter format_bytes;
98 // Format< Array<char,4> > format_bytes;
99  std::cout << char_array << std::endl;
100  std::cout << format_bytes(char_array) << std::endl;
101  std::cout << format_bytes(char_array.stencil(0,2)) << std::endl;
102  Array<unsigned char,4> uchar_array;
103  uchar_array << 0x01, 0x02, 0x03, 0x04;
104  Format< Array<unsigned char,4> > format_ubytes;
105  Format<unsigned char> format_uchar(-1,NoAlign,Hex);
106  std::cout << "[ ";
107  for ( unsigned int i = 0; i < uchar_array.size(); ++i ) {
108  std::cout << format_uchar(uchar_array[i]) << " ";
109  }
110  std::cout << "]" << std::endl;
111  std::cout << format_ubytes(uchar_array) << std::endl;
112  std::cout << format_ubytes(uchar_array.stencil(0,2)) << std::endl;
113 
114  std::cout << std::endl;
115  std::cout << "***********************************************************" << std::endl;
116  std::cout << " Push and Pop Byte Arrays" << std::endl;
117  std::cout << "***********************************************************" << std::endl;
118  std::cout << std::endl;
119 
120  std::cout << "Dynamic" << std::endl;
121  std::cout << std::endl;
122 
123  ecl::PushAndPop<unsigned char> push_and_pop(4);
125  //push_and_pop.resize(4);
126  push_and_pop.push_back(0x01);
127  std::cout << "Push 0x01: " << format_push_pop(push_and_pop) << std::endl;
128  push_and_pop.push_back(0x02);
129  std::cout << "Push 0x02: " << format_push_pop(push_and_pop) << std::endl;
130  push_and_pop.push_back(0x03);
131  std::cout << "Push 0x03: " << format_push_pop(push_and_pop) << std::endl;
132  push_and_pop.push_back(0x04);
133  std::cout << "Push 0x04: " << format_push_pop(push_and_pop) << std::endl;
134  push_and_pop.pop_front();
135  std::cout << "Pop front: " << format_push_pop(push_and_pop) << std::endl;
136  push_and_pop.pop_front();
137  std::cout << "Pop front: " << format_push_pop(push_and_pop) << std::endl;
138  push_and_pop.push_back(0x05);
139  std::cout << "Push 0x05: " << format_push_pop(push_and_pop) << std::endl;
140  push_and_pop.push_back(0x06);
141  std::cout << "Push 0x06: " << format_push_pop(push_and_pop) << std::endl;
142  push_and_pop.push_back(0x07);
143  std::cout << "Push 0x07: " << format_push_pop(push_and_pop) << std::endl;
144  push_and_pop.push_back(0x08);
145  std::cout << "Push 0x08: " << format_push_pop(push_and_pop) << std::endl;
146 
147  std::cout << "Size: " << push_and_pop.size() << std::endl;
148  std::cout << "[ ";
149  for ( unsigned int i = 0; i < push_and_pop.size(); ++i) {
150  std::cout << static_cast<int>(push_and_pop[i]) << " ";
151  }
152  std::cout << "]" << std::endl;
153 
154  std::cout << std::endl;
155  std::cout << "Fixed" << std::endl;
156  std::cout << std::endl;
157 
158  ecl::PushAndPop<unsigned char,4> push_and_pop_fixed;
159  ecl::PushAndPop<unsigned char,4>::Formatter format_push_pop_fixed;
160  push_and_pop_fixed.push_back(0x01);
161  std::cout << "Push 0x01: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
162  push_and_pop_fixed.push_back(0x02);
163  std::cout << "Push 0x02: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
164  push_and_pop_fixed.push_back(0x03);
165  std::cout << "Push 0x03: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
166  push_and_pop_fixed.push_back(0x04);
167  std::cout << "Push 0x04: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
168  push_and_pop_fixed.pop_front();
169  std::cout << "Pop front: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
170  push_and_pop_fixed.pop_front();
171  std::cout << "Pop front: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
172  push_and_pop_fixed.push_back(0x05);
173  std::cout << "Push 0x05: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
174  push_and_pop_fixed.push_back(0x06);
175  std::cout << "Push 0x06: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
176  push_and_pop_fixed.push_back(0x07);
177  std::cout << "Push 0x07: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
178  push_and_pop_fixed.push_back(0x08);
179  std::cout << "Push 0x08: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
180 
181  std::cout << std::endl;
182  std::cout << "***********************************************************" << std::endl;
183  std::cout << " Passed" << std::endl;
184  std::cout << "***********************************************************" << std::endl;
185  std::cout << std::endl;
186  return 0;
187 }
188 
ecl::Hex
Hex
ecl::NoAlign
NoAlign
formatters.hpp
main
int main(int argc, char **argv)
Definition: formatters.cpp:35
ecl::Stencil
A safe windowing class that opens onto array-like containers.
Definition: stencil/formatters.hpp:46
ecl::Array::stencil
Stencil< Array< Type, Size > > stencil(const unsigned int &start_index, const unsigned int &n)
Open a window (stencil) onto the array.
Definition: array_no_mem_check.hpp:271
ecl::PushAndPop::push_back
void push_back(const Type &datum)
Pushes an element onto the back of the container.
Definition: push_and_pop_fixed.hpp:135
ecl::Format
ecl::PushAndPop::pop_front
Type pop_front()
Definition: push_and_pop_fixed.hpp:147
ecl::PushAndPop
Surpport push and pack operation.
Definition: push_and_pop_fixed.hpp:82
ecl::formatters::PushAndPopFormatter
Pseudo formatter for integral type arrays.
Definition: push_and_pop/formatters.hpp:78
ecl::Array
Fixed size container with a few bells and whistles.
Definition: array_no_mem_check.hpp:112
ecl::PushAndPop::size
unsigned int size() const
Definition: push_and_pop_fixed.hpp:170
ecl::Array::size
static size_type size()
Definition: array_no_mem_check.hpp:348


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:34