Changeset 259
- Timestamp:
- 08/24/11 11:17:45 (12 years ago)
- Location:
- XMLIO_V2/dev/dev_rv
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/Makefile.wk
r258 r259 411 411 ifeq ($(VERSION), 4) 412 412 ELEMS_CPP = object exception xml_node xml_parser inetcdf4 inetcdf4_adv onetcdf4 mpi_interface\ 413 attribute attribute_template attribute_map 413 attribute attribute_template attribute_map buffer 414 414 415 415 endif -
XMLIO_V2/dev/dev_rv/src/xmlio/buffer.cpp
r198 r259 98 98 CBuffer::getBufferDataType<ARRAY(type, 1)>(void) const { return (type_enum); }; 99 99 100 BufferDataTypeGetter(bool, TBOOL8);101 BufferDataTypeGetter(char, TCHAR8);102 BufferDataTypeGetter(float, TFLOAT32);103 BufferDataTypeGetter(double, TDOUBLE64);100 BufferDataTypeGetter(bool, TBOOL8); 101 BufferDataTypeGetter(char, TCHAR8); 102 BufferDataTypeGetter(float, TFLOAT32); 103 BufferDataTypeGetter(double, TDOUBLE64); 104 104 BufferDataTypeGetter(long int, TINT32); 105 105 -
XMLIO_V2/dev/dev_rv/src4/xmlio/buffer/buffer.cpp
r258 r259 3 3 * ************************************************************************** */ 4 4 5 #ifndef __XIOS_NO_EXTERN 6 7 // C++ standard headers 8 #include <fstream> 9 10 #endif // __XIOS_NO_EXTERN 11 5 12 // XMLIOServer headers 6 13 #include "buffer.hpp" 14 #include "buffer_impl.hpp" 7 15 8 16 // /////////////////////////////// Définitions ////////////////////////////// // … … 10 18 namespace xmlioserver { 11 19 namespace comm { 12 13 20 21 // ------------------------------ Constructeurs ----------------------------- 22 23 CBuffer::CBuffer(std::size_t _size) 24 : size(_size), delIdata(true) 25 { 26 this->idata = new char[_size](); 27 //CMPIManager::AllocMem(&idata, size); 28 } 29 30 CBuffer::CBuffer(char * _data, std::size_t _size) 31 : size(_size), delIdata(false) 32 { 33 this->idata = _data; 34 } 35 36 CBuffer::CBuffer(const CBuffer & _buffer_ref) 37 : size(_buffer_ref.size), delIdata(true) 38 { 39 this->idata = new char[size](); 40 std::copy (_buffer_ref.idata, _buffer_ref.idata+size, this->idata); 41 } 42 43 CBuffer::CBuffer(const CBuffer * const _buffer_ptr) 44 : size(_buffer_ptr->size), delIdata(true) 45 { 46 this->idata = new char[size](); 47 std::copy (_buffer_ptr->idata, _buffer_ptr->idata+size, this->idata); 48 } 49 50 // ------------------------------- Destructeur ------------------------------ 51 52 CBuffer::~CBuffer(void) 53 { 54 if (delIdata) delete [] this->idata; 55 else this->fillData('\0', this->getSize(), 0); 56 //CMPIManager::FreeMem(idata); 57 } 58 59 // ------------------------------- Opérateurs ------------------------------- 60 61 CBuffer::operator char * (void) 62 { 63 return (this->getData()); 64 } 65 66 char * CBuffer::operator[](std::size_t _position) 67 { 68 return (this->getData(_position)); 69 } 70 71 // ------------------------------- Mutateurs -------------------------------- 72 73 void CBuffer::setData(const char * _data, std::size_t _size, std::size_t _position) 74 { 75 if (this->size < (_size + _position)) 76 XIOS_ERROR("CBuffer::getData(data, size, position)", 77 << " Buffer size < size + position !"); 78 std::copy(&(_data[0]), &(_data[size]), this->getData(_position)); 79 } 80 81 void CBuffer::setBufferData(const CBufferData & _bufdata, std::size_t _position) 82 { 83 std::size_t currposition = _position; 84 this->setData( reinterpret_cast<const char*>(&(_bufdata.type)) 85 , sizeof(CBufferDataType), currposition); 86 this->setData( reinterpret_cast<const char*>(&(_bufdata.isArray)) 87 , sizeof(bool), currposition += sizeof(CBufferDataType)); 88 this->setData( reinterpret_cast<const char*>(&(_bufdata.size)) 89 , sizeof(std::size_t), currposition += sizeof(bool)); 90 this->setData( reinterpret_cast<const char*>(&(_bufdata.pos)) 91 , sizeof(std::size_t), currposition += sizeof(std::size_t)); 92 } 93 94 void CBuffer::updateBufferData(std::size_t _position) 95 { 96 CBufferData bufdata; 97 this->getBufferData(bufdata, _position); 98 bufdata.pos = _position + DATA_HEADER_SIZE; 99 this->setBufferData(bufdata, _position); 100 } 101 102 void CBuffer::fillData(char _data, std::size_t _size, std::size_t _position) 103 { 104 if (this->size < (_size + _position)) 105 XIOS_ERROR("CBuffer::getData(data, size, position)", << " Buffer size < size + position !"); 106 std::fill_n(this->getData(_position), _size, _data); 107 } 108 109 // ------------------------------- Accesseurs ------------------------------- 110 111 std::size_t CBuffer::getSize(std::size_t _position) const 112 { 113 if (_position > this->size) 114 XIOS_ERROR("CBuffer::getSize(position)", << " Buffer size < size + position !"); 115 return (this->size - _position); 116 } 117 118 char * CBuffer::getData(std::size_t _position) const 119 { 120 if (_position > this->size) 121 XIOS_ERROR("CBuffer::getData(position)", << " Buffer size < position !"); 122 return &(this->idata[_position]); 123 } 124 125 void CBuffer::getData(char * _data, std::size_t _size, std::size_t _position) const 126 { 127 if (this->size < (_size + _position)) 128 XIOS_ERROR("CBuffer::getData(data, size, position)", << " Buffer size < size + position !"); 129 std::copy(this->getData(_position), this->getData(_position + _size), _data); 130 } 131 132 void CBuffer::getBufferData(CBufferData & _bufdata, std::size_t _position) const 133 { 134 std::size_t currposition = _position; 135 this->getData( reinterpret_cast<char*>(&(_bufdata.type)) 136 , sizeof(CBufferDataType), currposition); 137 this->getData( reinterpret_cast<char*>(&(_bufdata.isArray)) 138 , sizeof(bool), currposition += sizeof(CBufferDataType)); 139 this->getData( reinterpret_cast<char*>(&(_bufdata.size)) 140 , sizeof(std::size_t), currposition += sizeof(bool)); 141 this->getData( reinterpret_cast<char*>(&(_bufdata.pos)) 142 , sizeof(std::size_t), currposition += sizeof(std::size_t)); 143 } 144 145 std::size_t CBuffer::getNextDataPosition(std::size_t _position) 146 { 147 CBufferData bufdata; 148 this->updateBufferData(_position); 149 this->getBufferData(bufdata, _position); 150 return (bufdata.size + bufdata.pos); 151 } 152 153 template <> 154 std::size_t CBuffer::getRequestedSize(std::string data) 155 { 156 return (DATA_HEADER_SIZE + data.size() * sizeof (char)); 157 } 158 159 // -------------------------------------------------------------------------- 160 161 #define BufferDataTypeGetter(type, type_enum)\ 162 template <> CBuffer::CBufferDataType \ 163 CBuffer::getBufferDataType<type>(void) { return (type_enum); }; \ 164 template <> CBuffer::CBufferDataType \ 165 CBuffer::getBufferDataType<boost::multi_array<type, 1> >(void) { return (type_enum); }; 166 167 BufferDataTypeGetter(bool, TBOOL8); 168 BufferDataTypeGetter(char, TCHAR8); 169 BufferDataTypeGetter(float, TFLOAT32); 170 BufferDataTypeGetter(double, TDOUBLE64); 171 BufferDataTypeGetter(long int, TINT32); 172 173 #undef BufferDataTypeGetter 174 175 // ------------------------- Ecriture binaire ------------------------------- 176 177 void CBuffer::printToBinaryFile (const std::string & _filename) 178 { 179 std::ofstream ofs(_filename.c_str()); 180 this->printToBinaryStream(ofs); 181 ofs.close(); 182 } 183 184 void CBuffer::printToBinaryStream (std::ostream & _ostr) 185 { 186 _ostr.write (this->getData(), this->getSize()); 187 } 188 189 // -------------------------------------------------------------------------- 190 191 #define CBufferGetter(type, Type) \ 192 type CBuffer::get##Type(std::size_t _position) const \ 193 { type retvalue; this->getData<type>(retvalue, _position); return (retvalue); } 194 195 196 CBufferGetter(char , Char) 197 CBufferGetter(bool , Bool) 198 CBufferGetter(float , Float) 199 CBufferGetter(double , Double) 200 CBufferGetter(long int , Int) 201 202 #undef CBufferGetter 203 204 // -------------------------------------------------------------------------- 205 206 #define CBufferArrayGetter(type, Type) \ 207 boost::shared_ptr<boost::multi_array<type, 1> > \ 208 CBuffer::get##Type##Array(std::size_t _position) const \ 209 { boost::shared_ptr<boost::multi_array<type, 1> > retvalue \ 210 (new boost::multi_array<type, 1>(boost::extents[1])); \ 211 this->getDataArray<type>(*retvalue, _position); \ 212 return (retvalue); } 213 214 CBufferArrayGetter(char , Char) 215 CBufferArrayGetter(bool , Bool) 216 CBufferArrayGetter(float , Float) 217 CBufferArrayGetter(double , Double) 218 CBufferArrayGetter(long int , Int) 219 220 #undef CBufferArrayGetter 221 222 std::string CBuffer::getString(std::size_t position) const 223 { 224 boost::shared_ptr<boost::multi_array<char, 1> > array = this->getCharArray(position); 225 return (std::string(array->data(), array->num_elements())); 226 } 227 228 // -------------------------------------------------------------------------- 229 230 #define CBufferSetter(type, Type) \ 231 void CBuffer::set##Type(type _value, std::size_t _position) \ 232 { this->setData(_value, _position); } 233 234 CBufferSetter(char , Char) 235 CBufferSetter(bool , Bool) 236 CBufferSetter(float , Float) 237 CBufferSetter(double , Double) 238 CBufferSetter(long int , Int) 239 240 #undef CBufferSetter 241 242 // -------------------------------------------------------------------------- 243 244 #define CBufferArraySetter(type, Type) \ 245 void CBuffer::set##Type##Array \ 246 (boost::shared_ptr<boost::multi_array<type, 1> > _value, std::size_t _position) \ 247 { this->setDataArray(*_value, _position); } 248 249 CBufferArraySetter(char , Char) 250 CBufferArraySetter(bool , Bool) 251 CBufferArraySetter(float , Float) 252 CBufferArraySetter(double , Double) 253 CBufferArraySetter(long int , Int) 254 255 #undef CBufferArraySetter 256 257 void CBuffer::setString(const std::string & value, std::size_t position) 258 { 259 boost::shared_ptr<boost::multi_array<char, 1> > arr 260 (new boost::multi_array<char, 1>(boost::extents[value.size()])); 261 std::copy(value.data(), &(value.data()[value.size()]), arr->data()); 262 this->setCharArray(arr, position); 263 } 264 265 // -------------------------------------------------------------------------- 266 14 267 } // namespace comm 15 268 } // namespace xmlioserver -
XMLIO_V2/dev/dev_rv/src4/xmlio/buffer/buffer.hpp
r258 r259 62 62 63 63 template <class T> static CBufferDataType getBufferDataType(void); 64 65 std::size_t getNextDataPosition(std::size_t _position); 64 66 65 67 public : // Accesseurs … … 68 70 char * getData(std::size_t _position = 0) const; 69 71 70 public : // Accesseurs 72 public : // Accesseurs de données 71 73 72 74 template <class T> … … 74 76 75 77 template <class T> 76 inline void getDataArray(boost::multi_array<T, 1> & _data, std::size_t _position) const; 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 //-------------------------------------------------------------- 77 103 78 104 public : // Mutateurs de données … … 82 108 83 109 template <class T> 84 inline CBufferData setDataArray(const boost::multi_array<T, 1> & _data, std::size_t _position); 110 inline CBufferData setDataArray 111 (const boost::multi_array<T, 1> & _data, std::size_t _position); 112 113 //-------------------------------------------------------------- 114 115 /// Mutateurs /// 116 void setChar (char value, std::size_t position) ; 117 void setBool (bool value, std::size_t position) ; 118 void setFloat (float value, std::size_t position) ; 119 void setDouble(double value, std::size_t position) ; 120 void setInt (long int value, std::size_t position) ; 121 122 void setString(const std::string & value, std::size_t position) ; 123 124 void setCharArray 125 (boost::shared_ptr<boost::multi_array<char, 1> > _value, std::size_t _position) ; 126 void setBoolArray 127 (boost::shared_ptr<boost::multi_array<bool, 1> > _value, std::size_t _position) ; 128 void setFloatArray 129 (boost::shared_ptr<boost::multi_array<float, 1> > _value, std::size_t _position) ; 130 void setDoubleArray 131 (boost::shared_ptr<boost::multi_array<double, 1> > _value, std::size_t _position) ; 132 void setIntArray 133 (boost::shared_ptr<boost::multi_array<long int, 1> > _value, std::size_t _position) ; 134 135 //-------------------------------------------------------------- 136 137 virtual void clear(void) = 0; 138 void updateBufferData(std::size_t _position); 85 139 86 140 public : // Sortie fichier binaire … … 112 166 private: // Propriétés privées 113 167 114 bool delIdata;115 168 std::size_t size; 116 const char * idata; 169 bool delIdata; 170 char * idata; 117 171 118 172 }; // class CBuffer
Note: See TracChangeset
for help on using the changeset viewer.