rtcOutputHandler.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009
00003  * Robert Bosch LLC
00004  * Research and Technology Center North America
00005  * Palo Alto, California
00006  *
00007  * All rights reserved.
00008  *
00009  *------------------------------------------------------------------------------
00010  * project ....: Autonomous Technologies
00011  * file .......: rtcOutputHandler.h
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 12/12/2008
00015  * modified ...: $Date: 2009-03-20 11:36:51 -0700 (Fri, 20 Mar 2009) $
00016  * changed by .: $Author: wg75pal $
00017  * revision ...: $Revision: 105 $
00018  */
00019 #ifndef RTC_OUTPUT_HANDLER_H
00020 #define RTC_OUTPUT_HANDLER_H
00021 
00022 //== INCLUDES ==================================================================
00023 #include <string>
00024 #include <iostream>
00025 #include <sstream>
00026 
00027 //== NAMESPACES ================================================================
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 } // namespace rtc
00104 //==============================================================================
00105 #endif // RTC_OUTPUT_HANDLER_H defined
00106 //==============================================================================
00107 


rtc
Author(s): Benjamin Pitzer
autogenerated on Thu Jan 2 2014 11:04:53