casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
EndianStream.h
Go to the documentation of this file.
00001 #ifndef EndianStream_CLASS
00002 #define EndianStream_CLASS
00003 
00004 #include <stdint.h>
00005 #include <iostream>
00006 #include <fstream>
00007 #include <sstream>
00008 #include <string>
00009 
00010 #include "Misc.h"
00011 
00012 using  namespace std;
00013 
00014 namespace asdm {
00015         
00016   class EndianOSStream : public ostringstream {
00017   protected :
00018     //ostringstream _oss(stringstream::out | stringstream::binary);
00019                         
00020   public :
00021     EndianOSStream() ;
00022     EndianOSStream(const asdm::ByteOrder* byteOrder);
00023     ~EndianOSStream();
00024    
00025     const asdm::ByteOrder* byteOrder() const;
00026                 
00027     void writeBoolean(bool b);
00028     void writeBool(bool b);
00029     void writeByte(char c);
00030     void writeShort(short int s);
00031     void writeUShort(unsigned short int s);
00032     void writeInt(int i);
00033     void writeUInt(unsigned int ui);
00034     void writeLongLong(int64_t li);
00035     void writeLong(int64_t li);
00036     void writeULongLong(uint64_t li);
00037     void writeFloat(float f);
00038     void writeDouble(double d); 
00039     void writeString(const string& s);
00040 
00041   private:
00042     const asdm::ByteOrder* byteOrder_;
00043                         
00044   };    
00045         
00046   class EndianIStream {
00047   public:
00048     virtual const asdm::ByteOrder* byteOrder() const = 0;
00049     virtual bool readBoolean() = 0;
00050     virtual char readByte() = 0;
00051     virtual short int readShort() = 0;
00052     virtual unsigned short int readUShort() = 0;
00053     virtual int readInt() = 0 ;
00054     virtual unsigned int readUInt() = 0 ;
00055     virtual int64_t readLongLong() = 0 ;
00056     virtual int64_t readLong() = 0 ;
00057     virtual uint64_t readULongLong() = 0 ;
00058     virtual float readFloat() = 0 ;
00059     virtual double readDouble() = 0 ;
00060     virtual string readString() = 0 ;
00061     virtual ~EndianIStream() { ; }
00062   };
00063 
00064   class EndianISStream : public istringstream, EndianIStream {                  
00065   public :
00066     EndianISStream(const string& s) ;
00067     EndianISStream(const string& s, const asdm::ByteOrder* byteOrder);
00068     ~EndianISStream();
00069     
00070     const asdm::ByteOrder* byteOrder() const ;
00071     bool readBoolean();
00072     char readByte();
00073     short int readShort();
00074     unsigned short int readUShort();
00075     int readInt();
00076     unsigned int readUInt();
00077     int64_t readLongLong();
00078     int64_t readLong();
00079     uint64_t readULongLong();
00080     float readFloat();
00081     double readDouble();
00082     string readString();
00083     
00084   private :
00085     const asdm::ByteOrder* byteOrder_;
00086   };
00087 
00088   class EndianIFStream : EndianIStream  {                       
00089   public :
00090     EndianIFStream();
00091     EndianIFStream(ifstream*  ifs_p) ;
00092     EndianIFStream(ifstream* ifs_p, const asdm::ByteOrder* byteOrder);
00093     ~EndianIFStream();
00094     
00095     const asdm::ByteOrder* byteOrder() const ;
00096     bool readBoolean();
00097     char readByte();
00098     short int readShort();
00099     unsigned short int readUShort();
00100     int readInt();
00101     unsigned int readUInt();
00102     int64_t readLongLong();
00103     int64_t readLong();
00104     uint64_t readULongLong();
00105     float readFloat();
00106     double readDouble();
00107     string readString();
00108     
00109   private :
00110     ifstream* ifs_p;
00111     const asdm::ByteOrder* byteOrder_;
00112   };
00113 
00119   class BinaryAttributeReaderFunctor {
00120   public :
00121     virtual void operator()(EndianIStream& eis) = 0;
00122     virtual ~BinaryAttributeReaderFunctor() = 0;
00123   };
00124 
00125 }; // end namespace asdm
00126 
00127 #endif  // EndianStream_CLASS