storage.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __SHAWN_APPS_TCPIP_STORAGE_H
00013 #define __SHAWN_APPS_TCPIP_STORAGE_H
00014
00015 #ifdef SHAWN
00016 #include <shawn_config.h>
00017 #include "_apps_enable_cmake.h"
00018 #ifdef ENABLE_TCPIP
00019 #define BUILD_TCPIP
00020 #endif
00021 #else
00022 #define BUILD_TCPIP
00023 #endif
00024
00025
00026 #ifdef BUILD_TCPIP
00027
00028 #include <vector>
00029 #include <string>
00030 #include <stdexcept>
00031
00032 namespace tcpip
00033 {
00034
00035 class Storage
00036 {
00037
00038 public:
00039 typedef std::vector<unsigned char> StorageType;
00040
00041 private:
00042 StorageType store;
00043
00044 unsigned int pos_;
00045 bool iterValid_;
00046
00047 bool iterEndValid_;
00048
00049
00050 StorageType::const_iterator iter_;
00051 StorageType::const_iterator iterEnd_;
00052
00053
00054 bool bigEndian_;
00055
00057 void init();
00058
00059 public:
00060
00062 Storage();
00063
00065 Storage(unsigned char[], int length=-1);
00066
00067
00068 virtual ~Storage();
00069
00070 virtual bool valid_pos();
00071 virtual unsigned int position() const;
00072
00073 void reset();
00074
00075 virtual unsigned char readChar() throw(std::invalid_argument);
00076 virtual void writeChar(unsigned char) throw();
00077
00078 virtual int readByte() throw(std::invalid_argument);
00079 virtual void writeByte(int) throw(std::invalid_argument);
00080
00081
00082 virtual int readUnsignedByte() throw(std::invalid_argument);
00083 virtual void writeUnsignedByte(int) throw(std::invalid_argument);
00084
00085 virtual std::string readString() throw(std::invalid_argument);
00086 virtual void writeString(std::string s) throw();
00087
00088 virtual std::vector<std::string> readStringList() throw(std::invalid_argument);
00089 virtual void writeStringList(const std::vector<std::string> &s) throw();
00090
00091 virtual int readShort() throw(std::invalid_argument);
00092 virtual void writeShort(int) throw(std::invalid_argument);
00093
00094 virtual int readInt() throw(std::invalid_argument);
00095 virtual void writeInt(int) throw();
00096
00097 virtual float readFloat() throw(std::invalid_argument);
00098 virtual void writeFloat( float ) throw();
00099
00100 virtual double readDouble() throw(std::invalid_argument);
00101 virtual void writeDouble( double ) throw();
00102
00103 virtual void writePacket(unsigned char* packet, int length);
00104
00105 virtual void writeStorage(tcpip::Storage& store);
00106
00107
00108 size_t size() const { return store.size(); }
00109
00110 StorageType::const_iterator begin() const { return store.begin(); }
00111 StorageType::const_iterator end() const { return store.end(); }
00112
00113 };
00114
00115 }
00116
00117 #endif // BUILD_TCPIP
00118
00119 #endif
00120
00121
00122
00123
00124
00125
00126