source: XMLIO_V2/dev/common/src/xmlio/buffer.hpp @ 286

Last change on this file since 286 was 286, checked in by ymipsl, 13 years ago

reprise en main de la version de H. Ozdoba. Correction de différentes erreurs de conception et bug.
Version NEMO operationnel en client/server, interoperabilita avec OASIS, reconstition de fichiers via netcdf4/HDF5

YM

File size: 5.3 KB
Line 
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
9namespace 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);
44            static inline StdSize getDataHeaderSize(void) { return sizeof(CBufferDataType) + 2 * sizeof(StdSize) + sizeof(bool) ; }
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            void updateBufferData(StdSize position);
82
83            /// Sortie fichier binaire ///
84            void printToBinaryFile (const StdString & filename);
85            void printToBinaryStream (StdOStream & ostr);
86
87            /// Sortie fichier ascii ///
88            virtual void printToTextFile (const StdString & filename) = 0;
89            virtual void printToTextStream (StdOStream & ostr) = 0;
90
91            /// Destructeur ///
92            virtual ~CBuffer(void);
93
94         protected :
95
96            /// Construteurs ///
97            CBuffer(char * data, StdSize size);
98            explicit CBuffer(StdSize size);
99            CBuffer(const CBuffer & buffer);
100            CBuffer(const CBuffer * const buffer);
101
102            /// Accesseurs protégés ///
103            void getBufferData(CBufferData & bufdata, StdSize position) const;
104
105            template <class T>
106               inline void getData(T & data, StdSize position) const;
107            template <class T>
108               inline void getDataArray(ARRAY(T, 1) data, StdSize position) const;
109
110            /// Mutateurs protégés ///
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            void fillData(char data, StdSize size, StdSize position);
118
119         private :
120
121         //--------------------------------------------------------------
122
123            /// Accesseurs privés ///
124            void getData(char * data, StdSize size, StdSize position) const;
125            template <class T>
126               CBufferDataType getBufferDataType(void) const;
127
128            /// Mutateurs privés ///
129            void setBufferData(const CBufferData & bufdata, StdSize position);
130           
131         //--------------------------------------------------------------
132
133            /// Propriétés privées ///
134            StdSize size;
135            char * idata;
136            bool delIdata;
137
138      }; // class CBuffer
139   } // namespace comm
140} // namespace xmlioserver
141
142#endif // __XMLIO_CBuffer__
Note: See TracBrowser for help on using the repository browser.