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_INPUT_HANDLER_H
00020 #define RTC_INPUT_HANDLER_H
00021
00022
00023 #include <string>
00024 #include <iostream>
00025
00026
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 }
00100
00101 #endif // RTC_INPUT_HANDLER_H defined
00102
00103