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
00015 public:
00016 CSVOutput(Type const& type, std::string const& sep);
00017
00019 void header(std::ostream& out, std::string const& basename);
00020 void display(std::ostream& out, void* value);
00021 };
00022
00023
00024 namespace details {
00025 struct csvheader
00026 {
00027 CSVOutput output;
00028 std::string basename;
00029
00030 csvheader(Type const& type, std::string const& basename_, std::string const& sep = " ")
00031 : output(type, sep), basename(basename_) {}
00032 };
00033 struct csvline
00034 {
00035 CSVOutput output;
00036 void* value;
00037
00038 csvline(Type const& type_, void* value_, std::string const& sep_ = " ")
00039 : output(type_, sep_), value(value_) {}
00040 };
00041 inline std::ostream& operator << (std::ostream& stream, csvheader header)
00042 {
00043 header.output.header(stream, header.basename);
00044 return stream;
00045 }
00046 inline std::ostream& operator << (std::ostream& stream, csvline line)
00047 {
00048 line.output.display(stream, line.value);
00049 return stream;
00050 }
00051 }
00052
00058 inline details::csvheader csv_header(Type const& type, std::string const& basename, std::string const& sep = " ")
00059 { return details::csvheader(type, basename, sep); }
00060
00066 inline details::csvline csv(Type const& type, void* value, std::string const& sep = " ")
00067 { return details::csvline(type, value, sep); }
00068 };
00069
00070 #endif
00071