Line data Source code
1 : #ifndef EndianStream_CLASS 2 : #define EndianStream_CLASS 3 : 4 : #include <stdint.h> 5 : #include <iostream> 6 : #include <fstream> 7 : #include <sstream> 8 : #include <string> 9 : 10 : #include <alma/ASDM/Misc.h> 11 : 12 : namespace asdm { 13 : 14 : class EndianOSStream : public std::ostringstream { 15 : protected : 16 : //ostringstream _oss(stringstream::out | stringstream::binary); 17 : 18 : public : 19 : EndianOSStream() ; 20 : EndianOSStream(const asdm::ByteOrder* byteOrder); 21 : ~EndianOSStream(); 22 : 23 : const asdm::ByteOrder* byteOrder() const; 24 : 25 : void writeBoolean(bool b); 26 : void writeBool(bool b); 27 : void writeByte(char c); 28 : void writeShort(short int s); 29 : void writeUShort(unsigned short int s); 30 : void writeInt(int i); 31 : void writeUInt(unsigned int ui); 32 : void writeLongLong(int64_t li); 33 : void writeLong(int64_t li); 34 : void writeULongLong(uint64_t li); 35 : void writeFloat(float f); 36 : void writeDouble(double d); 37 : void writeString(const std::string& s); 38 : 39 : private: 40 : const asdm::ByteOrder* byteOrder_; 41 : 42 : }; 43 : 44 : class EndianIStream { 45 : public: 46 : virtual const asdm::ByteOrder* byteOrder() const = 0; 47 : virtual bool readBoolean() = 0; 48 : virtual char readByte() = 0; 49 : virtual short int readShort() = 0; 50 : virtual unsigned short int readUShort() = 0; 51 : virtual int readInt() = 0 ; 52 : virtual unsigned int readUInt() = 0 ; 53 : virtual int64_t readLongLong() = 0 ; 54 : virtual int64_t readLong() = 0 ; 55 : virtual uint64_t readULongLong() = 0 ; 56 : virtual float readFloat() = 0 ; 57 : virtual double readDouble() = 0 ; 58 : virtual std::string readString() = 0 ; 59 84 : virtual ~EndianIStream() { ; } 60 : }; 61 : 62 : class EndianISStream : public std::istringstream, EndianIStream { 63 : public : 64 : EndianISStream(const std::string& s) ; 65 : EndianISStream(const std::string& s, const asdm::ByteOrder* byteOrder); 66 : ~EndianISStream(); 67 : 68 : const asdm::ByteOrder* byteOrder() const ; 69 : bool readBoolean(); 70 : char readByte(); 71 : short int readShort(); 72 : unsigned short int readUShort(); 73 : int readInt(); 74 : unsigned int readUInt(); 75 : int64_t readLongLong(); 76 : int64_t readLong(); 77 : uint64_t readULongLong(); 78 : float readFloat(); 79 : double readDouble(); 80 : std::string readString(); 81 : 82 : private : 83 : const asdm::ByteOrder* byteOrder_; 84 : }; 85 : 86 : class EndianIFStream : EndianIStream { 87 : public : 88 : EndianIFStream(); 89 : EndianIFStream(std::ifstream* ifs_p) ; 90 : EndianIFStream(std::ifstream* ifs_p, const asdm::ByteOrder* byteOrder); 91 : ~EndianIFStream(); 92 : 93 : const asdm::ByteOrder* byteOrder() const ; 94 : bool readBoolean(); 95 : char readByte(); 96 : short int readShort(); 97 : unsigned short int readUShort(); 98 : int readInt(); 99 : unsigned int readUInt(); 100 : int64_t readLongLong(); 101 : int64_t readLong(); 102 : uint64_t readULongLong(); 103 : float readFloat(); 104 : double readDouble(); 105 : std::string readString(); 106 : 107 : private : 108 : std::ifstream* ifs_p; 109 : const asdm::ByteOrder* byteOrder_; 110 : }; 111 : 112 : /** 113 : * A pure virtual class whose derived classes are expected to be functors 114 : * whose behaviours will be to read the differents types of data stored into an EndianIStream. 115 : * 116 : */ 117 : class BinaryAttributeReaderFunctor { 118 : public : 119 : virtual void operator()(EndianIStream& eis) = 0; 120 : virtual ~BinaryAttributeReaderFunctor() = 0; 121 : }; 122 : 123 : }; // end namespace asdm 124 : 125 : #endif // EndianStream_CLASS