#ifndef __XMLIO_CArray_impl__ #define __XMLIO_CArray_impl__ #include "array_mac.hpp" #include "buffer_in.hpp" #include "buffer_out.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// template template CArray::CArray(const ExtentList & sizes) : boost::multi_array (sizes, boost::fortran_storage_order()) { /* Ne rien faire de plus */ } template CArray::CArray() : boost::multi_array (getExtentNull(), boost::fortran_storage_order()) { /* Ne rien faire de plus */ } template template CArray::CArray (const ExtentList & sizes, const boost::general_storage_order & store) : boost::multi_array (sizes, store) { /* Ne rien faire de plus */ } template CArray::~CArray(void) { /* Ne rien faire de plus */ } //---------------------------------------------------------------- template StdOStream & operator << (StdOStream & os, const CArray & array) { os << "CArray (" ; for (StdSize i = 1; i < array.num_dimensions(); i++) os << ", " << array.shape()[i]; os << ") = " ; for (StdSize i = 0; i < array.num_elements(); i++) os << (array.data()[i])<<" "; return (os); } //---------------------------------------------------------------- template StdOStream & operator << (StdOStream & os, const boost::shared_ptr > & array) { os << *array; return (os); } //---------------------------------------------------------------- template void FromBinary (StdIStream & is, ARRAY(ValueType, 1) & array) { ARRAY_ASSIGN(array, ValueType, 1, [1]); array->fromBinary(is); } template void FromBinary (StdIStream & is, ARRAY(ValueType, 2) & array) { ARRAY_ASSIGN(array, ValueType, 2, [1][1]); array->fromBinary(is); } template void FromBinary (StdIStream & is, ARRAY(ValueType, 3) & array) { ARRAY_ASSIGN(array, ValueType, 3, [1][1][1]); array->fromBinary(is); } //---------------------------------------------------------------- template void CArray::toBinary (StdOStream & os) const { typedef boost::multi_array_types::size_type LSize; LSize nelem = this->num_elements(); LSize ndim = this->num_dimensions(); const LSize * shape = this->shape(); const ValueType * data = this->data(); os.write (reinterpret_cast(&ndim) , sizeof(LSize)); for (LSize i = 0; i < ndim; i++ ) os.write (reinterpret_cast(&(shape[i])), sizeof(LSize)); os.write (reinterpret_cast(&nelem), sizeof(LSize)); os.write (reinterpret_cast(data), nelem * sizeof(ValueType)); } //---------------------------------------------------------------- template void CArray::fromBinary(StdIStream & is) { typedef boost::multi_array_types::size_type LSize; LSize ndim = 0, nelem = 0, temp = 0; std::vector shape; is.read (reinterpret_cast(&ndim) , sizeof(LSize)); for (LSize i = 0; i < ndim; i++ ) { is.read (reinterpret_cast(&temp) , sizeof(LSize)); shape.push_back(temp); } this->resize(shape); is.read (reinterpret_cast(&nelem), sizeof(LSize)); is.read (reinterpret_cast(this->data()), nelem * sizeof(ValueType)); } template size_t CArray::getSize(void) const { typedef boost::multi_array_types::size_type LSize; LSize nelem = this->num_elements(); LSize ndim = this->num_dimensions(); const LSize * shape = this->shape(); const ValueType * data = this->data(); size_t ret ; ret=sizeof(ndim) ; for (LSize i = 0; i < ndim; i++ ) ret+=sizeof(shape[i]) ; ret+=sizeof(nelem) ; ret+=sizeof(ValueType)*nelem ; return ret ; } template bool CArray::toBuffer(CBufferOut& buffer) const { typedef boost::multi_array_types::size_type LSize; LSize nelem = this->num_elements(); LSize ndim = this->num_dimensions(); const LSize* shape = this->shape(); const ValueType* data = this->data(); bool ret ; ret=buffer.put(ndim) ; for (LSize i = 0; i < ndim; i++ ) ret&=buffer.put(shape[i]) ; ret&=buffer.put(nelem) ; ret&=buffer.put(data,nelem) ; return ret ; } template bool CArray::fromBuffer(CBufferIn& buffer) { typedef boost::multi_array_types::size_type LSize; LSize ndim = 0, nelem = 0, temp = 0; std::vector shape; bool ret ; ret=buffer.get(ndim) ; for (LSize i = 0; i < ndim; i++ ) { ret&=buffer.get(temp) ; shape.push_back(temp); } this->resize(shape); ret&=buffer.get(nelem) ; ret&=buffer.get(this->data(),nelem) ; return ret ; } ///--------------------------------------------------------------- } // namespace xios #endif // __XMLIO_CArray_impl__