1 | /* ************************************************************************** * |
---|
2 | * Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011 * |
---|
3 | * ************************************************************************** */ |
---|
4 | |
---|
5 | #ifndef __BUFFER_HPP__ |
---|
6 | #define __BUFFER_HPP__ |
---|
7 | |
---|
8 | #ifndef __XIOS_NO_EXTERN |
---|
9 | |
---|
10 | // C++ standard headers |
---|
11 | #include <vector> |
---|
12 | |
---|
13 | // boost Headers |
---|
14 | #include <boost/multi_array.hpp> |
---|
15 | |
---|
16 | #endif // __XIOS_NO_EXTERN |
---|
17 | |
---|
18 | // XMLIOServer headers |
---|
19 | #include "xmlioserver_spl.hpp" |
---|
20 | |
---|
21 | // ////////////////////////////// Déclarations ///////////////////////////// // |
---|
22 | |
---|
23 | namespace xmlioserver |
---|
24 | { |
---|
25 | namespace comm |
---|
26 | { |
---|
27 | class CBuffer |
---|
28 | { |
---|
29 | public : // Définition de types |
---|
30 | |
---|
31 | typedef enum buffer_data_type |
---|
32 | { TBOOL8 = 0, TCHAR8, TINT32, TFLOAT32, TDOUBLE64 |
---|
33 | } CBufferDataType; |
---|
34 | |
---|
35 | typedef struct buffer_data |
---|
36 | { CBufferDataType type; bool isArray; std::size_t size; std::size_t pos; |
---|
37 | } CBufferData; |
---|
38 | |
---|
39 | protected : // Construteurs |
---|
40 | |
---|
41 | explicit CBuffer(std::size_t _size); |
---|
42 | CBuffer(char * _data, std::size_t _size); |
---|
43 | CBuffer(const CBuffer & _buffer_ref); // NIY |
---|
44 | CBuffer(const CBuffer * const _buffer_ptr); // NIY |
---|
45 | |
---|
46 | protected : // Destructeur |
---|
47 | |
---|
48 | virtual ~CBuffer(void); |
---|
49 | |
---|
50 | public : // Operateurs d'accÚs |
---|
51 | |
---|
52 | operator char * (void); |
---|
53 | char * operator[](std::size_t _position); |
---|
54 | |
---|
55 | public : // Accesseurs statiques |
---|
56 | |
---|
57 | template <class T> |
---|
58 | static inline std::size_t getRequestedSize(T _data); |
---|
59 | |
---|
60 | template <class T> |
---|
61 | static inline std::size_t getRequestedSize(boost::multi_array<T, 1> & _data); |
---|
62 | |
---|
63 | template <class T> static CBufferDataType getBufferDataType(void); |
---|
64 | |
---|
65 | std::size_t getNextDataPosition(std::size_t _position); |
---|
66 | |
---|
67 | public : // Accesseurs |
---|
68 | |
---|
69 | std::size_t getSize(std::size_t _position = 0) const; |
---|
70 | char * getData(std::size_t _position = 0) const; |
---|
71 | |
---|
72 | public : // Accesseurs de données |
---|
73 | |
---|
74 | template <class T> |
---|
75 | inline void getData(T & data, std::size_t position) const; |
---|
76 | |
---|
77 | template <class T> |
---|
78 | inline void getDataArray |
---|
79 | (boost::multi_array<T, 1> & _data, std::size_t _position) const; |
---|
80 | |
---|
81 | //-------------------------------------------------------------- |
---|
82 | |
---|
83 | char getChar (std::size_t position) const; |
---|
84 | bool getBool (std::size_t position) const; |
---|
85 | float getFloat (std::size_t position) const; |
---|
86 | double getDouble(std::size_t position) const; |
---|
87 | long int getInt (std::size_t position) const; |
---|
88 | |
---|
89 | std::string getString(std::size_t position) const; |
---|
90 | |
---|
91 | boost::shared_ptr<boost::multi_array<char, 1> > |
---|
92 | getCharArray (std::size_t _position) const; |
---|
93 | boost::shared_ptr<boost::multi_array<bool, 1> > |
---|
94 | getBoolArray (std::size_t _position) const; |
---|
95 | boost::shared_ptr<boost::multi_array<float, 1> > |
---|
96 | getFloatArray (std::size_t _position) const; |
---|
97 | boost::shared_ptr<boost::multi_array<double, 1> > |
---|
98 | getDoubleArray(std::size_t _position) const; |
---|
99 | boost::shared_ptr<boost::multi_array<long int, 1> > |
---|
100 | getIntArray (std::size_t _position) const; |
---|
101 | |
---|
102 | //-------------------------------------------------------------- |
---|
103 | |
---|
104 | public : // Mutateurs de données |
---|
105 | |
---|
106 | template <class T> |
---|
107 | inline CBufferData setData(const T & _data, std::size_t _position); |
---|
108 | |
---|
109 | template <class T> |
---|
110 | inline CBufferData setDataArray |
---|
111 | (const boost::multi_array<T, 1> & _data, std::size_t _position); |
---|
112 | |
---|
113 | //-------------------------------------------------------------- |
---|
114 | |
---|
115 | void setChar (char value, std::size_t position) ; |
---|
116 | void setBool (bool value, std::size_t position) ; |
---|
117 | void setFloat (float value, std::size_t position) ; |
---|
118 | void setDouble(double value, std::size_t position) ; |
---|
119 | void setInt (long int value, std::size_t position) ; |
---|
120 | |
---|
121 | void setString(const std::string & value, std::size_t position) ; |
---|
122 | |
---|
123 | void setCharArray |
---|
124 | (boost::shared_ptr<boost::multi_array<char, 1> > _value, std::size_t _position) ; |
---|
125 | void setBoolArray |
---|
126 | (boost::shared_ptr<boost::multi_array<bool, 1> > _value, std::size_t _position) ; |
---|
127 | void setFloatArray |
---|
128 | (boost::shared_ptr<boost::multi_array<float, 1> > _value, std::size_t _position) ; |
---|
129 | void setDoubleArray |
---|
130 | (boost::shared_ptr<boost::multi_array<double, 1> > _value, std::size_t _position) ; |
---|
131 | void setIntArray |
---|
132 | (boost::shared_ptr<boost::multi_array<long int, 1> > _value, std::size_t _position) ; |
---|
133 | |
---|
134 | //-------------------------------------------------------------- |
---|
135 | |
---|
136 | virtual void clear(void) = 0; |
---|
137 | void updateBufferData(std::size_t _position); |
---|
138 | |
---|
139 | public : // Sortie fichier binaire |
---|
140 | |
---|
141 | void printToBinaryFile (const std::string & _filename); |
---|
142 | |
---|
143 | void printToBinaryStream (std::ostream & _ostr); |
---|
144 | |
---|
145 | public : // Sortie fichier ascii |
---|
146 | |
---|
147 | virtual void printToTextFile (const std::string & _filename) = 0; |
---|
148 | |
---|
149 | virtual void printToTextStream (std::ostream & _ostr) = 0; |
---|
150 | |
---|
151 | protected : // Mutateurs de données privés |
---|
152 | |
---|
153 | void setData(const char * _data, std::size_t _size, std::size_t _position); |
---|
154 | |
---|
155 | void fillData(char _data, std::size_t _size, std::size_t _position); |
---|
156 | |
---|
157 | void setBufferData(const CBufferData & _bufdata, std::size_t _position); |
---|
158 | |
---|
159 | protected : // Accesseurs de données privés |
---|
160 | |
---|
161 | void getData(char * _data, std::size_t _size, std::size_t _position) const; |
---|
162 | |
---|
163 | void getBufferData(CBufferData & _bufdata, std::size_t _position) const; |
---|
164 | |
---|
165 | private: // Propriétés privées |
---|
166 | |
---|
167 | std::size_t size; |
---|
168 | bool delIdata; |
---|
169 | char * idata; |
---|
170 | |
---|
171 | }; // class CBuffer |
---|
172 | } // namespace comm |
---|
173 | } // namespace xmlioserver |
---|
174 | #endif //__BUFFER_HPP__ |
---|