rtcBinaryOutputHandler.cpp
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 .......: rtcBinaryOutputHandler.cpp
00012  * authors ....: Benjamin Pitzer
00013  * organization: Robert Bosch LLC
00014  * creation ...: 01/20/2009
00015  * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $
00016  * changed by .: $Author: benjaminpitzer $
00017  * revision ...: $Revision: 14 $
00018  */
00019 
00020 //== INCLUDES =================================================================
00021 #include "rtc/rtcBinaryOutputHandler.h"
00022 
00023 //== NAMESPACES ===============================================================
00024 namespace rtc {
00025 
00026 //== IMPLEMENTATION ==========================================================
00027 
00029 BinaryOutputHandler::BinaryOutputHandler()
00030 : OutputHandler()
00031 {
00032 }
00033 
00035 BinaryOutputHandler::BinaryOutputHandler(std::ostream& os)
00036 : OutputHandler(os)
00037 {
00038 }
00039 
00041 BinaryOutputHandler::~BinaryOutputHandler()
00042 {
00043 }
00044 
00046 bool BinaryOutputHandler::binary() const
00047 {
00048   return true;
00049 }
00050 
00052 bool BinaryOutputHandler::writeName(const std::string& name)
00053 {
00054   return true;
00055 }
00057 bool BinaryOutputHandler::writeSeparator()
00058 {
00059   return true;
00060 }
00061 
00063 bool BinaryOutputHandler::writeEOL()
00064 {
00065   return true;
00066 }
00067 
00068 bool BinaryOutputHandler::write(const std::string& data) {
00069   if(!outStream) return false;
00070   size_t size = data.size();
00071   //  *outStream << size;
00072   outStream->write(reinterpret_cast<const char*>(&size),sizeof(size));
00073  
00074   if(size>0) {
00075     *outStream << data;
00076     //alternative:
00077     //outStream->write(data.c_str(),size);
00078   }
00079   return outStream->good();
00080 };
00081 
00082 bool BinaryOutputHandler::write(const double& data) {
00083   if(!outStream) return false;
00084   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00085   return outStream->good();
00086 }
00087 
00088 bool BinaryOutputHandler::write(const float& data) {
00089   if(!outStream) return false;
00090   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00091   return outStream->good();
00092 }
00093 
00094 bool BinaryOutputHandler::write(const int& data) {
00095   if(!outStream) return false;
00096   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00097   return outStream->good();
00098 }
00099 
00100 bool BinaryOutputHandler::write(const unsigned int& data) {
00101   if(!outStream) return false;
00102   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00103   return outStream->good();
00104 }
00105 
00106 bool BinaryOutputHandler::write(const char& data) {
00107   if(!outStream) return false;
00108   outStream->put(data);
00109   return outStream->good();
00110 }
00111 
00112 bool BinaryOutputHandler::write(const unsigned char& data) {
00113   if(!outStream) return false;
00114   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00115   return outStream->good();
00116 }
00117 
00118 bool BinaryOutputHandler::write(const bool& data) {
00119   if(!outStream) return false;
00120   if (data) {
00121     return BinaryOutputHandler::write(char(1));
00122   } else {
00123     return BinaryOutputHandler::write(char(0));
00124   }
00125 }
00126 
00127 bool BinaryOutputHandler::write(const long& data) {
00128   if(!outStream) return false;
00129   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00130   return outStream->good();
00131 }
00132 
00133 bool BinaryOutputHandler::write(const unsigned long& data) {
00134   if(!outStream) return false;
00135   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00136   return outStream->good();
00137 }
00138 
00139 bool BinaryOutputHandler::write(const short& data) {
00140   if(!outStream) return false;
00141   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00142   return outStream->good();
00143 }
00144 
00145 bool BinaryOutputHandler::write(const unsigned short& data) {
00146   if(!outStream) return false;
00147   outStream->write(reinterpret_cast<const char*>(&data),sizeof(data));
00148   return outStream->good();
00149 }
00150 
00151 bool BinaryOutputHandler::write(const char* data, long n) {
00152   if(!outStream) return false;
00153   outStream->write(data,n);
00154   return outStream->good();
00155 }
00156 
00157 //=============================================================================
00158 } // namespace rtc
00159 //=============================================================================


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