$search
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 .......: rtcInputHandler.h 00012 * authors ....: Benjamin Pitzer 00013 * organization: Robert Bosch LLC 00014 * creation ...: 01/20/2009 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_INPUT_HANDLER_H 00020 #define RTC_INPUT_HANDLER_H 00021 00022 //== INCLUDES ================================================================== 00023 #include <string> 00024 #include <iostream> 00025 00026 //== NAMESPACES ================================================================ 00027 namespace rtc { 00028 00039 class InputHandler { 00040 public: 00042 InputHandler(); 00044 InputHandler(std::istream& is); 00046 virtual ~InputHandler(); 00048 virtual bool binary() const = 0; 00050 virtual void use(std::istream& is); 00052 virtual bool readName(const std::string& name) = 0; 00054 virtual bool readSeparator() = 0; 00056 00059 virtual bool read(std::string& data) = 0; 00060 virtual bool read(double& data) = 0; 00061 virtual bool read(float& data) = 0; 00062 virtual bool read(int& data) = 0; 00063 virtual bool read(unsigned int& data) = 0; 00064 virtual bool read(char& data) = 0; 00065 virtual bool read(unsigned char& data) = 0; 00066 virtual bool read(bool& data) = 0; 00067 virtual bool read(long& data) = 0; 00068 virtual bool read(unsigned long& data) = 0; 00069 virtual bool read(short& data) = 0; 00070 virtual bool read(unsigned short& data) = 0; 00071 virtual bool read(char* data, long n) = 0; 00073 00074 std::istream& stream(); 00076 bool good() const; 00077 protected: 00079 std::istream* inStream; 00080 }; 00081 00085 template <class T> 00086 bool rtc_read(InputHandler& ih, const std::string& name, T& data) 00087 { 00088 bool res = true; 00089 res = res && ih.readName(name); 00090 res = res && ih.readSeparator(); 00091 if(ih.binary()) 00092 res = res && ih.read(data); 00093 else 00094 ih.stream() >> data; 00095 return res; 00096 }; 00097 00098 //============================================================================== 00099 } // namespace rtc 00100 //============================================================================== 00101 #endif // RTC_INPUT_HANDLER_H defined 00102 //============================================================================== 00103