formatters.cpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Includes
00013 *****************************************************************************/
00014 
00015 #include <iostream>
00016 #include <ecl/formatters.hpp>
00017 #include "../../include/ecl/containers/array.hpp"
00018 #include "../../include/ecl/containers/push_and_pop.hpp"
00019 #include "../../include/ecl/containers/stencil.hpp"
00020 
00021 /*****************************************************************************
00022 ** Using
00023 *****************************************************************************/
00024 
00025 using ecl::Array;
00026 using ecl::Format;
00027 using ecl::Hex;
00028 using ecl::NoAlign;
00029 using ecl::Stencil;
00030 
00031 /*****************************************************************************
00032 ** Main program
00033 *****************************************************************************/
00034 
00035 int main(int argc, char **argv) {
00036 
00037     std::cout << std::endl;
00038     std::cout << "***********************************************************" << std::endl;
00039     std::cout << "                         Arrays" << std::endl;
00040     std::cout << "***********************************************************" << std::endl;
00041     std::cout << std::endl;
00042 
00043     Array<int,4> int_array;
00044     int_array << 1,2,3,4;
00045     Array<float,4> float_array;
00046     float_array << 1,2,3.32235,-324;
00047     Format< Array<int,4> > format_array;
00048 //    Format< Array<float,4> > format_array_float;
00049     Array<float,4>::Formatter format_array_float;
00050     format_array_float.precision(3);
00051     std::cout << format_array(int_array) << std::endl;
00052     std::cout << format_array_float(float_array) << std::endl;
00053 
00054     std::cout << std::endl;
00055     std::cout << "***********************************************************" << std::endl;
00056     std::cout << "                    Dynamic Arrays" << std::endl;
00057     std::cout << "***********************************************************" << std::endl;
00058     std::cout << std::endl;
00059 
00060     Array<float> float_array_dynamic(4);
00061     Format< Array<float> > format_array_dynamic_float;
00062     format_array_dynamic_float.precision(3);
00063     float_array_dynamic << 1,2,3.32235,-324;
00064     std::cout << format_array_dynamic_float(float_array_dynamic) << std::endl;
00065 
00066     std::cout << std::endl;
00067     std::cout << "***********************************************************" << std::endl;
00068     std::cout << "                      Float Stencils" << std::endl;
00069     std::cout << "***********************************************************" << std::endl;
00070     std::cout << std::endl;
00071 
00072     Array<float> float_array_under(20);
00073     float_array_under << 1,2,3.32235,-324;
00074     Format< Stencil< Array<float> > > format_stencil;
00075     format_stencil.precision(3);
00076     std::cout << format_stencil(float_array_under.stencil(1,2)) << std::endl;
00077     Array<double> double_array_under(20);
00078     double_array_under << 1,2,3.32235,-324;
00079     Format< Stencil< Array<double> > > format_double_stencil;
00080     format_double_stencil.precision(3);
00081     std::cout << format_double_stencil(double_array_under.stencil(1,2)) << std::endl;
00082 
00083     std::cout << std::endl;
00084     std::cout << "***********************************************************" << std::endl;
00085     std::cout << "                         Byte Arrays" << std::endl;
00086     std::cout << "***********************************************************" << std::endl;
00087     std::cout << std::endl;
00088 
00089     Array<signed char,4> schar_array;
00090     schar_array << 'a','b','c','d';
00091     Format< Array<signed char,4> > format_sbytes;
00092     std::cout << schar_array << std::endl;
00093     std::cout << format_sbytes(schar_array) << std::endl;
00094     std::cout << format_sbytes(schar_array.stencil(0,2)) << std::endl;
00095     Array<char,4> char_array;
00096     char_array << 'a','b','c','d';
00097     Array<char,4>::Formatter format_bytes;
00098 //    Format< Array<char,4> > format_bytes;
00099     std::cout << char_array << std::endl;
00100     std::cout << format_bytes(char_array) << std::endl;
00101     std::cout << format_bytes(char_array.stencil(0,2)) << std::endl;
00102     Array<unsigned char,4> uchar_array;
00103     uchar_array << 0x01, 0x02, 0x03, 0x04;
00104     Format< Array<unsigned char,4> > format_ubytes;
00105     Format<unsigned char> format_uchar(-1,NoAlign,Hex);
00106     std::cout << "[ ";
00107     for ( unsigned int i = 0; i < uchar_array.size(); ++i ) {
00108         std::cout << format_uchar(uchar_array[i]) << " ";
00109     }
00110     std::cout << "]" << std::endl;
00111     std::cout << format_ubytes(uchar_array) << std::endl;
00112     std::cout << format_ubytes(uchar_array.stencil(0,2)) << std::endl;
00113 
00114     std::cout << std::endl;
00115     std::cout << "***********************************************************" << std::endl;
00116     std::cout << "                 Push and Pop Byte Arrays" << std::endl;
00117     std::cout << "***********************************************************" << std::endl;
00118     std::cout << std::endl;
00119 
00120     std::cout << "Dynamic" << std::endl;
00121     std::cout << std::endl;
00122 
00123     ecl::PushAndPop<unsigned char> push_and_pop(4);
00124     ecl::PushAndPop<unsigned char>::Formatter format_push_pop;
00125     //push_and_pop.resize(4);
00126     push_and_pop.push_back(0x01);
00127     std::cout << "Push 0x01: " << format_push_pop(push_and_pop) << std::endl;
00128     push_and_pop.push_back(0x02);
00129     std::cout << "Push 0x02: " << format_push_pop(push_and_pop) << std::endl;
00130     push_and_pop.push_back(0x03);
00131     std::cout << "Push 0x03: " << format_push_pop(push_and_pop) << std::endl;
00132     push_and_pop.push_back(0x04);
00133     std::cout << "Push 0x04: " << format_push_pop(push_and_pop) << std::endl;
00134     push_and_pop.pop_front();
00135     std::cout << "Pop front: " << format_push_pop(push_and_pop) << std::endl;
00136     push_and_pop.pop_front();
00137     std::cout << "Pop front: " << format_push_pop(push_and_pop) << std::endl;
00138     push_and_pop.push_back(0x05);
00139     std::cout << "Push 0x05: " << format_push_pop(push_and_pop) << std::endl;
00140     push_and_pop.push_back(0x06);
00141     std::cout << "Push 0x06: " << format_push_pop(push_and_pop) << std::endl;
00142     push_and_pop.push_back(0x07);
00143     std::cout << "Push 0x07: " << format_push_pop(push_and_pop) << std::endl;
00144     push_and_pop.push_back(0x08);
00145     std::cout << "Push 0x08: " << format_push_pop(push_and_pop) << std::endl;
00146 
00147     std::cout << "Size: " << push_and_pop.size() << std::endl;
00148     std::cout << "[ ";
00149     for ( unsigned int i = 0; i < push_and_pop.size(); ++i) {
00150       std::cout << static_cast<int>(push_and_pop[i]) << " ";
00151     }
00152     std::cout << "]" << std::endl;
00153 
00154     std::cout << std::endl;
00155     std::cout << "Fixed" << std::endl;
00156     std::cout << std::endl;
00157 
00158     ecl::PushAndPop<unsigned char,4> push_and_pop_fixed;
00159     ecl::PushAndPop<unsigned char,4>::Formatter format_push_pop_fixed;
00160     push_and_pop_fixed.push_back(0x01);
00161     std::cout << "Push 0x01: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00162     push_and_pop_fixed.push_back(0x02);
00163     std::cout << "Push 0x02: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00164     push_and_pop_fixed.push_back(0x03);
00165     std::cout << "Push 0x03: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00166     push_and_pop_fixed.push_back(0x04);
00167     std::cout << "Push 0x04: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00168     push_and_pop_fixed.pop_front();
00169     std::cout << "Pop front: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00170     push_and_pop_fixed.pop_front();
00171     std::cout << "Pop front: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00172     push_and_pop_fixed.push_back(0x05);
00173     std::cout << "Push 0x05: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00174     push_and_pop_fixed.push_back(0x06);
00175     std::cout << "Push 0x06: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00176     push_and_pop_fixed.push_back(0x07);
00177     std::cout << "Push 0x07: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00178     push_and_pop_fixed.push_back(0x08);
00179     std::cout << "Push 0x08: " << format_push_pop_fixed(push_and_pop_fixed) << std::endl;
00180 
00181     std::cout << std::endl;
00182     std::cout << "***********************************************************" << std::endl;
00183     std::cout << "                      Passed" << std::endl;
00184     std::cout << "***********************************************************" << std::endl;
00185     std::cout << std::endl;
00186     return 0;
00187 }
00188 


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:29