#ifndef __XMLIO_CArray_impl__ #define __XMLIO_CArray_impl__ #include "array_mac.hpp" namespace xmlioserver { /// ////////////////////// Définitions ////////////////////// /// template template CArray::CArray(const ExtentList & sizes) : boost::multi_array (sizes, 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 << (array.data()[0]) << "(" << array.shape()[0]; for (StdSize i = 1; i < array.num_dimensions(); i++) os << ", " << array.shape()[i]; os << ")" << (array.data()[array.num_elements()-1]); 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)); } ///--------------------------------------------------------------- } // namespace xmlioserver #endif // __XMLIO_CArray_impl__