formatters.cpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Includes
00013 *****************************************************************************/
00014 
00015 #include <iostream>
00016 #include <string>
00017 #include "../../include/ecl/formatters/common.hpp"
00018 #include "../../include/ecl/formatters/floats.hpp"
00019 #include "../../include/ecl/formatters/number.hpp"
00020 #include "../../include/ecl/formatters/strings.hpp"
00021 
00022 /*****************************************************************************
00023 ** Using
00024 *****************************************************************************/
00025 
00026 using std::string;
00027 using ecl::Format;
00028 using ecl::Dec;
00029 using ecl::Fixed;
00030 using ecl::Hex;
00031 using ecl::CentreAlign;
00032 using ecl::LeftAlign;
00033 using ecl::NoAlign;
00034 using ecl::RightAlign;
00035 
00036 /*****************************************************************************
00037 ** Main
00038 *****************************************************************************/
00039 
00040 int main() {
00041 
00042     unsigned char c = 69;
00043     Format<unsigned char> format(8,RightAlign,Hex); // Initialisation
00044 
00045     std::cout << std::endl;
00046     std::cout << "***********************************************************" << std::endl;
00047     std::cout << "               Temporary Formatting [Number]" << std::endl;
00048     std::cout << "***********************************************************" << std::endl;
00049     std::cout << std::endl;
00050 
00051     std::cout << "NoAlign    : " << format(c,8,NoAlign,Hex) << std::endl;
00052     std::cout << "LeftAlign  : " << format(c,8,LeftAlign,Hex) << std::endl;
00053     std::cout << "CentreAlign: " << format(c,8,CentreAlign,Hex) << std::endl;
00054     std::cout << "RightAlign : " << format(c,8,RightAlign,Hex) << std::endl;
00055 
00056     std::cout << std::endl;
00057     std::cout << "***********************************************************" << std::endl;
00058     std::cout << "               Temporary Formatting [Number]" << std::endl;
00059     std::cout << "***********************************************************" << std::endl;
00060     std::cout << std::endl;
00061 
00062     std::cout << "NoAlign    : " << format(c,8,NoAlign,Hex) << std::endl;
00063     std::cout << "LeftAlign  : " << format(c,8,LeftAlign,Hex) << std::endl;
00064     std::cout << "CentreAlign: " << format(c,8,CentreAlign,Hex) << std::endl;
00065     std::cout << "RightAlign : " << format(c,8,RightAlign,Hex) << std::endl;
00066 
00067     std::cout << std::endl;
00068     std::cout << "***********************************************************" << std::endl;
00069     std::cout << "               Permanent Formatting [Number]" << std::endl;
00070     std::cout << "***********************************************************" << std::endl;
00071     std::cout << std::endl;
00072 
00073     std::cout << "NoAlign    : " << format(8,NoAlign,Hex)(c) << std::endl;
00074     std::cout << "LeftAlign  : " << format(8,LeftAlign,Hex)(c) << std::endl;
00075     std::cout << "CentreAlign: " << format(8,CentreAlign,Hex)(c) << std::endl;
00076     std::cout << "RightAlign : " << format(8,RightAlign,Hex)(c) << std::endl;
00077 
00078     std::cout << std::endl;
00079     std::cout << "***********************************************************" << std::endl;
00080     std::cout << "             Single Parameter Formatting [Number]" << std::endl;
00081     std::cout << "***********************************************************" << std::endl;
00082     std::cout << std::endl;
00083 
00084     std::cout << "Width      : " << format.width(14)(c) << std::endl;
00085     std::cout << "Align      : " << format.align(CentreAlign)(c) << std::endl;
00086     std::cout << "Base       : " << format.base(Dec)(c) << std::endl;
00087 
00088     std::cout << std::endl;
00089     std::cout << "***********************************************************" << std::endl;
00090     std::cout << "                   Integral Types" << std::endl;
00091     std::cout << "***********************************************************" << std::endl;
00092     std::cout << std::endl;
00093 
00094     std::cout << "char          : " << Format<unsigned char>(8,RightAlign,Dec)('c') << std::endl;
00095     std::cout << "short         : " << Format<short>(8,RightAlign,Dec)(123) << std::endl;
00096     std::cout << "unsigned short: " << Format<unsigned short>(8,RightAlign,Dec)(123) << std::endl;
00097     std::cout << "int           : " << Format<int>(8,RightAlign,Dec)(-111123) << std::endl;
00098     std::cout << "unsigned int  : " << Format<unsigned int>(8,RightAlign,Dec)(111123) << std::endl;
00099     std::cout << "long          : " << Format<long>(8,RightAlign,Dec)(-1111123) << std::endl;
00100     std::cout << "unsigned long : " << Format<unsigned long>(8,RightAlign,Dec)(1111123) << std::endl;
00101 
00102     std::cout << std::endl;
00103     std::cout << "***********************************************************" << std::endl;
00104     std::cout << "                   String Formats" << std::endl;
00105     std::cout << "***********************************************************" << std::endl;
00106     std::cout << std::endl;
00107 
00108     Format<string> sformat(10,RightAlign);
00109     std::cout << "Strings: " << sformat(string("Dude")) << std::endl;
00110     std::cout << "Strings: " << sformat(string("Dudette")) << std::endl;
00111     std::cout << "Strings: " << sformat(string("Dudonimous")) << std::endl;
00112     std::cout << "CString: " << sformat("Dude") << std::endl;
00113     std::cout << "TmpFrmt: " << sformat("Dude",10,CentreAlign) << std::endl;
00114     std::cout << "PrmFrmt: " << sformat(10,CentreAlign)("Dude") << std::endl;
00115 
00116     std::cout << std::endl;
00117     std::cout << "***********************************************************" << std::endl;
00118     std::cout << "                   Float Formats" << std::endl;
00119     std::cout << "***********************************************************" << std::endl;
00120     std::cout << std::endl;
00121 
00122     Format<float> fformat;
00123     float f = -12235.135;
00124     fformat.base(Fixed);
00125     fformat.width(15);
00126     fformat.precision(3);
00127     fformat.align(LeftAlign);
00128     fformat.align(CentreAlign);
00129     fformat.align(RightAlign);
00130     fformat(2,15,RightAlign,Fixed);
00131     fformat(2,15);
00132     std::cout << "TmpFrmt: " << fformat(f,2,15,CentreAlign,Fixed) << std::endl;
00133     std::cout << "TmpFrmt: " << fformat(f,2,15) << std::endl;
00134     std::cout << "Format : " << fformat(f) << std::endl;
00135 
00136     std::cout << std::endl;
00137     std::cout << "***********************************************************" << std::endl;
00138     std::cout << "                   Double Formats" << std::endl;
00139     std::cout << "***********************************************************" << std::endl;
00140     std::cout << std::endl;
00141 
00142     Format<double> dformat;
00143     double d = 134.2352;
00144     dformat.base(Fixed); // Format setters
00145     dformat.width(15);
00146     dformat.precision(3);
00147     dformat.align(LeftAlign);
00148     dformat.align(CentreAlign);
00149     dformat.align(RightAlign);
00150     dformat(2,15,RightAlign,Fixed); // Combo format operators
00151     dformat(4,15);
00152     std::cout << "TmpFrmt: " << dformat(d,2,15,CentreAlign,Fixed) << std::endl;
00153     std::cout << "TmpFrmt: " << dformat(d,3,15) << std::endl;
00154     std::cout << "Format : " << dformat(d) << std::endl;
00155 
00156     std::cout << std::endl;
00157     std::cout << "***********************************************************" << std::endl;
00158     std::cout << "                      Passed" << std::endl;
00159     std::cout << "***********************************************************" << std::endl;
00160     std::cout << std::endl;
00161 
00162     return 0;
00163 }


ecl_formatters
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:36