1 | #ifndef __XMLIO_CBuffer__ |
---|
2 | #define __XMLIO_CBuffer__ |
---|
3 | |
---|
4 | /// xmlioserver headers /// |
---|
5 | #include "xmlioserver_spl.hpp" |
---|
6 | #include "exception.hpp" |
---|
7 | #include "array.hpp" |
---|
8 | |
---|
9 | namespace xmlioserver |
---|
10 | { |
---|
11 | namespace comm |
---|
12 | { |
---|
13 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
14 | class CBuffer |
---|
15 | { |
---|
16 | public : |
---|
17 | |
---|
18 | //-------------------------------------------------------------- |
---|
19 | |
---|
20 | typedef enum buffer_data_type |
---|
21 | { TBOOL8 = 0, TINT32, TCHAR8, TFLOAT32, TDOUBLE64 |
---|
22 | } CBufferDataType; |
---|
23 | |
---|
24 | typedef struct buffer_data |
---|
25 | { CBufferDataType type; bool isArray; StdSize size; StdSize position; |
---|
26 | } CBufferData; |
---|
27 | |
---|
28 | //-------------------------------------------------------------- |
---|
29 | |
---|
30 | /// Operateurs /// |
---|
31 | operator char * (void); |
---|
32 | char * operator[](StdSize position); |
---|
33 | |
---|
34 | /// Accesseurs /// |
---|
35 | StdSize getSize(StdSize position = 0) const; |
---|
36 | char * getData(StdSize position = 0) const; |
---|
37 | |
---|
38 | template <class T> |
---|
39 | inline StdSize getRequestedSize(T data) const; |
---|
40 | template <class T> |
---|
41 | inline StdSize getRequestedSize(ARRAY(T, 1) data) const; |
---|
42 | |
---|
43 | StdSize getNextDataPosition(StdSize position) const; |
---|
44 | |
---|
45 | //-------------------------------------------------------------- |
---|
46 | |
---|
47 | char getChar (StdSize position) const; |
---|
48 | bool getBool (StdSize position) const; |
---|
49 | float getFloat (StdSize position) const; |
---|
50 | double getDouble(StdSize position) const; |
---|
51 | long int getInt (StdSize position) const; |
---|
52 | |
---|
53 | StdString getString(StdSize position) const; |
---|
54 | |
---|
55 | ARRAY(char, 1) getCharArray (StdSize position) const; |
---|
56 | ARRAY(bool, 1) getBoolArray (StdSize position) const; |
---|
57 | ARRAY(float, 1) getFloatArray (StdSize position) const; |
---|
58 | ARRAY(double, 1) getDoubleArray(StdSize position) const; |
---|
59 | ARRAY(long int, 1) getIntArray (StdSize position) const; |
---|
60 | |
---|
61 | //-------------------------------------------------------------- |
---|
62 | |
---|
63 | /// Mutateurs /// |
---|
64 | void setChar (char value, StdSize position) ; |
---|
65 | void setBool (bool value, StdSize position) ; |
---|
66 | void setFloat (float value, StdSize position) ; |
---|
67 | void setDouble(double value, StdSize position) ; |
---|
68 | void setInt (long int value, StdSize position) ; |
---|
69 | |
---|
70 | void setString(const StdString & value, StdSize position) ; |
---|
71 | |
---|
72 | void setCharArray (ARRAY(char, 1) value, StdSize position) ; |
---|
73 | void setBoolArray (ARRAY(bool, 1) value, StdSize position) ; |
---|
74 | void setFloatArray (ARRAY(float, 1) value, StdSize position) ; |
---|
75 | void setDoubleArray(ARRAY(double, 1) value, StdSize position) ; |
---|
76 | void setIntArray (ARRAY(long int, 1) value, StdSize position) ; |
---|
77 | |
---|
78 | //-------------------------------------------------------------- |
---|
79 | |
---|
80 | virtual void clear(void) = 0; |
---|
81 | |
---|
82 | /// Sortie fichier binaire /// |
---|
83 | void printToBinaryFile (const StdString & filename); |
---|
84 | void printToBinaryStream (StdOStream & ostr); |
---|
85 | |
---|
86 | /// Sortie fichier ascii /// |
---|
87 | virtual void printToTextFile (const StdString & filename) = 0; |
---|
88 | virtual void printToTextStream (StdOStream & ostr) = 0; |
---|
89 | |
---|
90 | /// Destructeur /// |
---|
91 | virtual ~CBuffer(void); |
---|
92 | |
---|
93 | protected : |
---|
94 | |
---|
95 | /// Construteurs /// |
---|
96 | CBuffer(char * data, StdSize size); |
---|
97 | explicit CBuffer(StdSize size); |
---|
98 | CBuffer(const CBuffer & buffer); // Not implemented yet. |
---|
99 | CBuffer(const CBuffer * const buffer); // Not implemented yet. |
---|
100 | |
---|
101 | /// Accesseurs protégés /// |
---|
102 | void getBufferData(CBufferData & bufdata, StdSize position) const; |
---|
103 | |
---|
104 | template <class T> |
---|
105 | inline void getData(T & data, StdSize position) const; |
---|
106 | template <class T> |
---|
107 | inline void getDataArray(ARRAY(T, 1) data, StdSize position) const; |
---|
108 | |
---|
109 | /// Mutateurs protégés /// |
---|
110 | |
---|
111 | template <class T> |
---|
112 | inline void setData(const T & data, StdSize position); |
---|
113 | template <class T> |
---|
114 | inline void setDataArray(const ARRAY(T, 1) data, StdSize position); |
---|
115 | |
---|
116 | void setData(const char * data, StdSize size, StdSize position); |
---|
117 | |
---|
118 | private : |
---|
119 | |
---|
120 | //-------------------------------------------------------------- |
---|
121 | |
---|
122 | /// Accesseurs privés /// |
---|
123 | void getData(char * data, StdSize size, StdSize position) const; |
---|
124 | template <class T> |
---|
125 | CBufferDataType getBufferDataType(void) const; |
---|
126 | |
---|
127 | /// Mutateurs privés /// |
---|
128 | void setBufferData(const CBufferData & bufdata, StdSize position); |
---|
129 | |
---|
130 | //-------------------------------------------------------------- |
---|
131 | |
---|
132 | /// Propriétés privées /// |
---|
133 | StdSize size; |
---|
134 | char * idata; |
---|
135 | bool delIdata; |
---|
136 | |
---|
137 | }; // class CBuffer |
---|
138 | } // namespace comm |
---|
139 | } // namespace xmlioserver |
---|
140 | |
---|
141 | #endif // __XMLIO_CBuffer__ |
---|