source: XMLIO_V2/dev/common/src/xmlio/array_impl.hpp @ 219

Last change on this file since 219 was 219, checked in by hozdoba, 13 years ago

Préparation nouvelle arborescence

File size: 4.2 KB
Line 
1#ifndef __XMLIO_CArray_impl__
2#define __XMLIO_CArray_impl__
3
4#include "array_mac.hpp"
5
6namespace xmlioserver
7{
8   
9   /// ////////////////////// Définitions ////////////////////// ///
10
11   template <typename ValueType, StdSize NumDims, typename Allocator>
12      template <typename ExtentList>
13         CArray<ValueType, NumDims, Allocator>::CArray(const ExtentList & sizes)
14            : boost::multi_array<ValueType, NumDims, Allocator>
15                  (sizes, boost::fortran_storage_order())
16   { /* Ne rien faire de plus */ }
17
18   template <typename ValueType, StdSize NumDims, typename Allocator>
19      template <typename ExtentList>
20         CArray<ValueType, NumDims, Allocator>::CArray
21            (const ExtentList & sizes, const boost::general_storage_order<NumDims> & store)
22               : boost::multi_array<ValueType, NumDims, Allocator> (sizes, store)
23   { /* Ne rien faire de plus */ }
24
25   template <typename ValueType, StdSize NumDims, typename Allocator>
26      CArray<ValueType, NumDims, Allocator>::~CArray(void)
27   { /* Ne rien faire de plus */ }
28
29   //----------------------------------------------------------------
30
31   template <typename ValueType, StdSize NumDims, typename Allocator>
32      StdOStream & operator << (StdOStream & os,
33                                const CArray<ValueType, NumDims, Allocator> & array)
34   {
35      os << (array.data()[0]) << "(" << array.shape()[0];
36      for (StdSize i = 1; i < array.num_dimensions(); i++)
37         os << ", " << array.shape()[i];
38      os << ")" << (array.data()[array.num_elements()-1]);
39      return (os);
40   }
41
42   //----------------------------------------------------------------
43
44   template <typename ValueType, StdSize NumDims, typename Allocator>
45      StdOStream & operator << 
46         (StdOStream & os, const boost::shared_ptr<CArray<ValueType, NumDims, Allocator> > & array)
47   { 
48      os << *array; 
49      return (os); 
50   }
51   
52   //----------------------------------------------------------------
53   
54   template <typename ValueType> void FromBinary
55         (StdIStream & is, ARRAY(ValueType, 1) & array)
56   {
57      ARRAY_ASSIGN(array, ValueType, 1, [1]);
58      array->fromBinary(is);
59   }
60   
61   template <typename ValueType> void FromBinary
62         (StdIStream & is, ARRAY(ValueType, 2) & array)
63   {
64      ARRAY_ASSIGN(array, ValueType, 2, [1][1]);
65      array->fromBinary(is);
66   }
67
68   template <typename ValueType> void FromBinary
69         (StdIStream & is, ARRAY(ValueType, 3) & array)
70   {
71      ARRAY_ASSIGN(array, ValueType, 3, [1][1][1]);
72      array->fromBinary(is);
73   }
74   //----------------------------------------------------------------
75
76   template <typename ValueType, StdSize NumDims, typename Allocator>
77      void CArray<ValueType, NumDims, Allocator>::toBinary  (StdOStream & os) const
78   {
79      typedef boost::multi_array_types::size_type LSize;
80      LSize nelem = this->num_elements();
81      LSize ndim  = this->num_dimensions();
82      const LSize * shape = this->shape();
83      const ValueType * data = this->data();
84
85      os.write (reinterpret_cast<const char*>(&ndim) , sizeof(LSize));
86      for (LSize i = 0; i < ndim; i++ )
87         os.write (reinterpret_cast<const char*>(&(shape[i])), sizeof(LSize));
88      os.write (reinterpret_cast<const char*>(&nelem), sizeof(LSize));
89      os.write (reinterpret_cast<const char*>(data), nelem * sizeof(ValueType));
90   }
91
92   //----------------------------------------------------------------
93
94   template <typename ValueType, StdSize NumDims, typename Allocator>
95      void CArray<ValueType, NumDims, Allocator>::fromBinary(StdIStream & is)
96   {
97      typedef boost::multi_array_types::size_type LSize;
98      LSize ndim = 0, nelem = 0, temp = 0;
99      std::vector<LSize> shape;
100      is.read (reinterpret_cast<char*>(&ndim) , sizeof(LSize));
101      for (LSize i = 0; i < ndim; i++ )
102      {
103         is.read (reinterpret_cast<char*>(&temp) , sizeof(LSize));
104         shape.push_back(temp);
105      }
106      this->resize(shape);
107      is.read (reinterpret_cast<char*>(&nelem), sizeof(LSize));
108      is.read (reinterpret_cast<char*>(this->data()), nelem * sizeof(ValueType));
109   }
110
111   ///---------------------------------------------------------------
112   
113} // namespace xmlioserver
114
115#endif // __XMLIO_CArray_impl__
Note: See TracBrowser for help on using the repository browser.