[152] | 1 | #ifndef __XMLIO_CArray_impl__ |
---|
| 2 | #define __XMLIO_CArray_impl__ |
---|
| 3 | |
---|
| 4 | namespace xmlioserver |
---|
| 5 | { |
---|
| 6 | |
---|
| 7 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 8 | |
---|
| 9 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 10 | template <typename ExtentList> |
---|
| 11 | CArray<ValueType, NumDims, Allocator>::CArray(const ExtentList & sizes) |
---|
| 12 | : boost::multi_array<ValueType, NumDims, Allocator> |
---|
| 13 | (sizes, boost::fortran_storage_order()) |
---|
| 14 | { /* Ne rien faire de plus */ } |
---|
| 15 | |
---|
| 16 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 17 | template <typename ExtentList> |
---|
| 18 | CArray<ValueType, NumDims, Allocator>::CArray |
---|
| 19 | (const ExtentList & sizes, const boost::general_storage_order<NumDims> & store) |
---|
| 20 | : boost::multi_array<ValueType, NumDims, Allocator> (sizes, store) |
---|
| 21 | { /* Ne rien faire de plus */ } |
---|
| 22 | |
---|
| 23 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 24 | CArray<ValueType, NumDims, Allocator>::~CArray(void) |
---|
| 25 | { /* Ne rien faire de plus */ } |
---|
| 26 | |
---|
| 27 | //---------------------------------------------------------------- |
---|
| 28 | |
---|
| 29 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 30 | StdOStream & operator << (StdOStream & os, |
---|
| 31 | const CArray<ValueType, NumDims, Allocator> & array) |
---|
| 32 | { |
---|
| 33 | os << (array.data()[0]) << "(" << array.shape()[0]; |
---|
| 34 | for (StdSize i = 1; i < array.num_dimensions(); i++) |
---|
| 35 | os << ", " << array.shape()[i]; |
---|
| 36 | os << ")" << (array.data()[array.num_elements()-1]); |
---|
| 37 | return (os); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | //---------------------------------------------------------------- |
---|
| 41 | |
---|
| 42 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 43 | StdOStream & operator << (StdOStream & os, |
---|
| 44 | const boost::shared_ptr<CArray<ValueType, NumDims, Allocator> > & array) |
---|
| 45 | { os << *array; return (os); } |
---|
| 46 | |
---|
| 47 | //---------------------------------------------------------------- |
---|
| 48 | |
---|
| 49 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 50 | void CArray<ValueType, NumDims, Allocator>::toBinary (StdOStream & os) const |
---|
| 51 | { |
---|
| 52 | typedef boost::multi_array_types::size_type LSize; |
---|
| 53 | LSize nelem = this->num_elements(); |
---|
| 54 | LSize ndim = this->num_dimensions(); |
---|
| 55 | const LSize * shape = this->shape(); |
---|
| 56 | const ValueType * data = this->data(); |
---|
| 57 | |
---|
| 58 | os.write (reinterpret_cast<const char*>(&ndim) , sizeof(LSize)); |
---|
| 59 | for (LSize i = 0; i < ndim; i++ ) |
---|
| 60 | os.write (reinterpret_cast<const char*>(&(shape[i])), sizeof(LSize)); |
---|
| 61 | os.write (reinterpret_cast<const char*>(&nelem), sizeof(LSize)); |
---|
| 62 | os.write (reinterpret_cast<const char*>(data), nelem * sizeof(ValueType)); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //---------------------------------------------------------------- |
---|
| 66 | |
---|
| 67 | template <typename ValueType, StdSize NumDims, typename Allocator> |
---|
| 68 | void CArray<ValueType, NumDims, Allocator>::fromBinary(StdIStream & is) |
---|
| 69 | { |
---|
| 70 | typedef boost::multi_array_types::size_type LSize; |
---|
| 71 | LSize ndim = 0, nelem = 0, temp = 0; |
---|
| 72 | std::vector<LSize> shape; |
---|
| 73 | is.read (reinterpret_cast<char*>(&ndim) , sizeof(LSize)); |
---|
| 74 | for (LSize i = 0; i < ndim; i++ ) |
---|
| 75 | { |
---|
| 76 | is.read (reinterpret_cast<char*>(&temp) , sizeof(LSize)); |
---|
| 77 | shape.push_back(temp); |
---|
| 78 | } |
---|
| 79 | this->reshape(shape); |
---|
| 80 | is.read (reinterpret_cast<char*>(&nelem), sizeof(LSize)); |
---|
| 81 | is.read (reinterpret_cast<char*>(this->data()), nelem * sizeof(ValueType)); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | ///--------------------------------------------------------------- |
---|
| 85 | |
---|
| 86 | } // namespace xmlioserver |
---|
| 87 | |
---|
| 88 | #endif // __XMLIO_CArray_impl__ |
---|