csvoutput.hh
Go to the documentation of this file.
00001 #ifndef TYPELIB_DISPLAY_HH
00002 #define TYPELIB_DISPLAY_HH
00003 #include <string>
00004 #include <iosfwd>
00005 
00006 namespace Typelib
00007 {
00008     class Type;
00009 
00010     class CSVOutput
00011     {
00012         Type const& m_type;
00013         std::string m_separator;
00014         bool m_char_as_numeric;
00015 
00016     public:
00017         CSVOutput(Type const& type, std::string const& sep, bool char_as_numeric);
00018 
00020         void header(std::ostream& out, std::string const& basename);
00021         void display(std::ostream& out, void* value);
00022     };
00023 
00024     
00025     namespace details {
00026         struct csvheader
00027         {
00028             CSVOutput output;
00029             std::string basename;
00030             
00031             csvheader(Type const& type, std::string const& basename_, std::string const& sep = " ")
00032                 : output(type, sep, true), basename(basename_) {}
00033         };
00034         struct csvline
00035         {
00036             CSVOutput output;
00037             void* value;
00038             bool char_as_numeric;
00039             
00040             csvline(Type const& type_, void* value_, std::string const& sep_ = " ", bool char_as_numeric = true)
00041                 : output(type_, sep_, char_as_numeric), value(value_), char_as_numeric(char_as_numeric) {}
00042         };
00043         inline std::ostream& operator << (std::ostream& stream, csvheader header)
00044         {
00045             header.output.header(stream, header.basename);
00046             return stream;
00047         }
00048         inline std::ostream& operator << (std::ostream& stream, csvline line)
00049         {
00050             line.output.display(stream, line.value);
00051             return stream;
00052         }
00053     }
00054 
00060     inline details::csvheader csv_header(Type const& type, std::string const& basename, std::string const& sep = " ")
00061     { return details::csvheader(type, basename, sep); }
00062 
00068     inline details::csvline   csv(Type const& type, void* value, std::string const& sep = " ", bool char_as_numeric = true)
00069     { return details::csvline(type, value, sep, char_as_numeric); }
00070 };
00071 
00072 #endif
00073 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Mon Oct 6 2014 03:17:12