rtcBinaryInputHandler.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 .......: rtcBinaryBinaryInputHandler.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/rtcBinaryInputHandler.h"
00022 #include <vector>
00023 
00024 //== NAMESPACES ================================================================
00025 namespace rtc {
00026 
00027 //== IMPLEMENTATION ============================================================
00028 
00030 BinaryInputHandler::BinaryInputHandler()
00031 : InputHandler()
00032 {
00033 }
00034 
00036 BinaryInputHandler::BinaryInputHandler(std::istream& is)
00037 : InputHandler(is)
00038 {
00039 }
00040 
00042 BinaryInputHandler::~BinaryInputHandler()
00043 {
00044 }
00045 
00047 bool BinaryInputHandler::binary() const
00048 {
00049   return true;
00050 }
00051 
00053 bool BinaryInputHandler::readName(const std::string& name)
00054 {
00055   return true;
00056 }
00057 
00059 bool BinaryInputHandler::readSeparator()
00060 {
00061   return true;
00062 }
00063 
00064 bool BinaryInputHandler::read(std::string& data) {
00065   if(!inStream) return false;
00066   size_t size;
00067   inStream->read(reinterpret_cast<char*>(&size),sizeof(size));
00068   if(size>0) {
00069     std::vector<char> tmp(size);
00070     inStream->read(&tmp[0], size); //deserialize characters of string
00071     data.assign(&tmp[0], size);
00072   }
00073   return inStream->good();
00074 }
00075 
00076 bool BinaryInputHandler::read(double& data) {
00077   if(!inStream) return false;
00078   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00079   return inStream->good();
00080 }
00081 
00082 bool BinaryInputHandler::read(float& data)  {
00083   if(!inStream) return false;
00084   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00085   return inStream->good();
00086 }
00087 
00088 bool BinaryInputHandler::read(int& data)  {
00089   if(!inStream) return false;
00090   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00091   return inStream->good();
00092 }
00093 
00094 bool BinaryInputHandler::read(unsigned int& data)  {
00095   if(!inStream) return false;
00096   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00097   return inStream->good();
00098 }
00099 
00100 bool BinaryInputHandler::read(char& data)  {
00101   if(!inStream) return false;
00102   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00103   return inStream->good();
00104 }
00105 
00106 bool BinaryInputHandler::read(unsigned char& data)  {
00107   if(!inStream) return false;
00108   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00109   return inStream->good();
00110 }
00111 
00112 bool BinaryInputHandler::read(bool& data) {
00113   if(!inStream) return false;
00114   char tmp;
00115   BinaryInputHandler::read(tmp);
00116   if (tmp == 0 || tmp == 1) {
00117     data=(tmp == 1);
00118     return inStream->good();
00119   } else {
00120     return false;
00121   }
00122 }
00123 
00124 bool BinaryInputHandler::read(long& data)  {
00125   if(!inStream) return false;
00126   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00127   return inStream->good();
00128 }
00129 
00130 bool BinaryInputHandler::read(unsigned long& data)  {
00131   if(!inStream) return false;
00132   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00133   return inStream->good();
00134 }
00135 
00136 bool BinaryInputHandler::read(short& data)  {
00137   if(!inStream) return false;
00138   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00139   return inStream->good();
00140 }
00141 
00142 bool BinaryInputHandler::read(unsigned short& data)  {
00143   if(!inStream) return false;
00144   inStream->read(reinterpret_cast<char*>(&data),sizeof(data));
00145   return inStream->good();
00146 }
00147 
00148 bool BinaryInputHandler::read(char* data, long n) {
00149   if(!inStream) return false;
00150   inStream->read(data,n);
00151   return inStream->good();
00152 }
00153 
00154 //==============================================================================
00155 } // namespace rtc
00156 //==============================================================================


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