Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef RTC_OUTPUT_HANDLER_H
00020 #define RTC_OUTPUT_HANDLER_H
00021
00022
00023 #include <string>
00024 #include <iostream>
00025 #include <sstream>
00026
00027
00028 namespace rtc {
00029
00040 class OutputHandler {
00041 public:
00043 OutputHandler();
00045 OutputHandler(std::ostream& os);
00047 virtual ~OutputHandler();
00049 virtual bool binary() const = 0;
00051 virtual void use(std::ostream& os);
00053 virtual bool writeName(const std::string& name) = 0;
00055 virtual bool writeSeparator() = 0;
00057 virtual bool writeEOL() = 0;
00059
00062 virtual bool write(const std::string& data) = 0;
00063 virtual bool write(const double& data) = 0;
00064 virtual bool write(const float& data) = 0;
00065 virtual bool write(const int& data) = 0;
00066 virtual bool write(const unsigned int& data) = 0;
00067 virtual bool write(const char& data) = 0;
00068 virtual bool write(const unsigned char& data) = 0;
00069 virtual bool write(const bool& data) = 0;
00070 virtual bool write(const long& data) = 0;
00071 virtual bool write(const unsigned long& data) = 0;
00072 virtual bool write(const short& data) = 0;
00073 virtual bool write(const unsigned short& data) = 0;
00074 virtual bool write(const char* data, long n) = 0;
00076
00077 std::ostream& stream();
00079 bool good() const;
00080 protected:
00082 std::ostream* outStream;
00083 };
00084
00088 template <class T>
00089 bool rtc_write(OutputHandler& oh, const std::string& name, const T& data)
00090 {
00091 bool res = true;
00092 res = res && oh.writeName(name);
00093 res = res && oh.writeSeparator();
00094 if(oh.binary())
00095 res = res && oh.write(data);
00096 else
00097 oh.stream() << data;
00098 res = res && oh.writeEOL();
00099 return res;
00100 };
00101
00102
00103 }
00104
00105 #endif // RTC_OUTPUT_HANDLER_H defined
00106
00107