#ifndef __XMLIO_CBuffer_impl__ #define __XMLIO_CBuffer_impl__ namespace xmlioserver { namespace comm { /// ////////////////// Définitions (inline) /////////////////// /// #define DATA_HEADER_SIZE sizeof(CBuffer::CBufferDataType) + 2 * sizeof(StdSize) + sizeof(bool) template StdSize CBuffer::getRequestedSize(T data) const { return (DATA_HEADER_SIZE + sizeof (T)); } template StdSize CBuffer::getRequestedSize(ARRAY(T, 1) data) const { return (DATA_HEADER_SIZE + data->num_elements() * sizeof (T)); } template <> StdSize CBuffer::getRequestedSize(StdString data) const; //--------------------------------------------------------------- template void CBuffer::getData(T & data, StdSize position) const { if (this->size < (position + this->getRequestedSize(data))) ERROR("CBuffer::getData(data, position)", << " Buffer size < size + position !"); CBufferData bufdata; this->getBufferData(bufdata, position); if (bufdata.type != this->getBufferDataType()) ERROR("CBuffer::getData(data, position)", << "[ BufferDataType Read : " << bufdata.type << ", " << ", BufferDataType T : " << this->getBufferDataType() << "] " << " invalid type !"); if (bufdata.isArray != false) ERROR("CBuffer::getData(data, position)", << " type should be an array !"); this->getData(reinterpret_cast(&data), bufdata.size , bufdata.position); } template void CBuffer::getDataArray(ARRAY(T, 1) data, StdSize position) const { CBufferData bufdata; this->getBufferData(bufdata, position); if (bufdata.type != this->getBufferDataType()) ERROR("CBuffer::getDataArray(data, position)", << " invalid type !"); if (bufdata.isArray != true) ERROR("CBuffer::getDataArray(data, position)", << " type should not be an array !"); if (this->size < (position + (DATA_HEADER_SIZE + bufdata.size))) ERROR("CBuffer::getData(data, size, position)", << " Buffer size < size + position !"); data->resize(boost::extents[bufdata.size/sizeof(T)]); this->getData(reinterpret_cast(data->data()), bufdata.size , bufdata.position); } //--------------------------------------------------------------- template void CBuffer::setData(const T & data, StdSize position) { if (this->size < (position + this->getRequestedSize(data))) ERROR("CBuffer::setData(data, size, position)", << " Buffer size < size + position !"); CBufferData bufdata; bufdata.type = this->getBufferDataType(); bufdata.isArray = false; bufdata.size = sizeof(T); bufdata.position = position + DATA_HEADER_SIZE; this->setBufferData(bufdata, position); this->setData(reinterpret_cast(&data), bufdata.size , bufdata.position); } template void CBuffer::setDataArray(const ARRAY(T, 1) data, StdSize position) { if (this->size < (position + this->getRequestedSize(data))) ERROR("CBuffer::setDataArray(data, size, position)", << " Buffer size < size + position ! : "<size<<" < "<getRequestedSize(data)<<" + "<getBufferDataType(); bufdata.isArray = true; bufdata.size = data->num_elements() * sizeof (T); bufdata.position = position + DATA_HEADER_SIZE; this->setBufferData(bufdata, position); this->setData(reinterpret_cast(data->data()), bufdata.size , bufdata.position); } ///---------------------------------------------------------------- } // namespace comm } // namespace xmlioserver #endif // __XMLIO_CBuffer_impl__