Changeset 300 for XMLIO_V2/dev/common/src/array_impl.hpp
- Timestamp:
- 02/13/12 19:35:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/common/src/array_impl.hpp
r219 r300 3 3 4 4 #include "array_mac.hpp" 5 #include "buffer_in.hpp" 6 #include "buffer_out.hpp" 5 7 6 8 namespace xmlioserver … … 16 18 { /* Ne rien faire de plus */ } 17 19 20 template <typename ValueType, StdSize NumDims, typename Allocator> 21 CArray<ValueType, NumDims, Allocator>::CArray() 22 : boost::multi_array<ValueType, NumDims, Allocator> 23 (getExtentNull<NumDims>(), boost::fortran_storage_order()) 24 { /* Ne rien faire de plus */ } 25 18 26 template <typename ValueType, StdSize NumDims, typename Allocator> 19 27 template <typename ExtentList> … … 33 41 const CArray<ValueType, NumDims, Allocator> & array) 34 42 { 35 os << (array.data()[0]) << "(" << array.shape()[0];43 os << "CArray (" ; 36 44 for (StdSize i = 1; i < array.num_dimensions(); i++) 37 45 os << ", " << array.shape()[i]; 38 os << ")" << (array.data()[array.num_elements()-1]); 46 os << ") = " ; 47 for (StdSize i = 0; i < array.num_elements(); i++) os << (array.data()[i])<<" "; 39 48 return (os); 40 49 } … … 108 117 is.read (reinterpret_cast<char*>(this->data()), nelem * sizeof(ValueType)); 109 118 } 119 120 template <typename ValueType, StdSize NumDims, typename Allocator> 121 size_t CArray<ValueType, NumDims, Allocator>::getSize(void) const 122 { 123 typedef boost::multi_array_types::size_type LSize; 124 LSize nelem = this->num_elements(); 125 LSize ndim = this->num_dimensions(); 126 const LSize * shape = this->shape(); 127 const ValueType * data = this->data(); 128 size_t ret ; 129 ret=sizeof(ndim) ; 130 for (LSize i = 0; i < ndim; i++ ) ret+=sizeof(shape[i]) ; 131 ret+=sizeof(nelem) ; 132 ret+=sizeof(ValueType)*nelem ; 133 return ret ; 134 } 135 136 template <typename ValueType, StdSize NumDims, typename Allocator> 137 bool CArray<ValueType, NumDims, Allocator>::toBuffer(CBufferOut& buffer) const 138 { 139 typedef boost::multi_array_types::size_type LSize; 140 141 LSize nelem = this->num_elements(); 142 LSize ndim = this->num_dimensions(); 143 const LSize* shape = this->shape(); 144 const ValueType* data = this->data(); 145 bool ret ; 146 147 ret=buffer.put(ndim) ; 148 for (LSize i = 0; i < ndim; i++ ) ret&=buffer.put(shape[i]) ; 149 ret&=buffer.put(nelem) ; 150 ret&=buffer.put(data,nelem) ; 151 return ret ; 152 } 153 154 template <typename ValueType, StdSize NumDims, typename Allocator> 155 bool CArray<ValueType, NumDims, Allocator>::fromBuffer(CBufferIn& buffer) 156 { 157 typedef boost::multi_array_types::size_type LSize; 158 LSize ndim = 0, nelem = 0, temp = 0; 159 std::vector<LSize> shape; 160 bool ret ; 161 162 ret=buffer.get(ndim) ; 163 for (LSize i = 0; i < ndim; i++ ) 164 { 165 ret&=buffer.get(temp) ; 166 shape.push_back(temp); 167 } 168 this->resize(shape); 169 ret&=buffer.get(nelem) ; 170 ret&=buffer.get(this->data(),nelem) ; 171 return ret ; 172 } 173 110 174 111 175 ///---------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.