/[escript]/branches/complex/escriptcore/src/DataVector.h
ViewVC logotype

Diff of /branches/complex/escriptcore/src/DataVector.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5867 by jfenwick, Wed Jan 13 03:13:08 2016 UTC revision 5868 by jfenwick, Wed Jan 13 07:23:44 2016 UTC
# Line 15  Line 15 
15  *****************************************************************************/  *****************************************************************************/
16    
17    
18  #if !defined escript_DataVector_20050324_H  #if !defined escript_DataVectorTaipan_20050324_H
19  #define escript_DataVector_20050324_H  #define escript_DataVectorTaipan_20050324_H
20  #include "system_dep.h"  #include "system_dep.h"
21    
22  #include "esysUtils/EsysAssert.h"  #include "esysUtils/EsysAssert.h"
# Line 31  class WrappedArray; Line 31  class WrappedArray;
31    
32  /**  /**
33     \brief     \brief
34     DataVector implements an arbitrarily long vector of data values.     DataVectorTaipan implements an arbitrarily long vector of data values.
35     DataVector is the underlying data container for Data objects.     DataVectorTaipan is the underlying data container for Data objects.
36    
37     Description:     Description:
38     DataVector provides an implementation of a vector of data values for use     DataVectorTaipan provides an implementation of a vector of data values for use
39     by DataBlocks2D and DataArrayView. Hiding the vector in this container     by DataBlocks2D and DataArrayView. Hiding the vector in this container
40     allows different implementations to be swapped in without disrupting the     allows different implementations to be swapped in without disrupting the
41     client classes.     client classes.
42  */  */
43    
44  class ESCRIPT_DLL_API DataVector {  class ESCRIPT_DLL_API DataVectorTaipan {
45    
46   public:   public:
47    
# Line 51  class ESCRIPT_DLL_API DataVector { Line 51  class ESCRIPT_DLL_API DataVector {
51    
52    //    //
53    // The underlying type used to implement the vector.    // The underlying type used to implement the vector.
54    typedef ElementType *  ValueType;    typedef ElementType *  VectorStorageType;
55    typedef const ElementType * ConstValueType;    typedef const ElementType * ConstValueType;
56    
57    //    //
# Line 63  class ESCRIPT_DLL_API DataVector { Line 63  class ESCRIPT_DLL_API DataVector {
63    
64    /**    /**
65       \brief       \brief
66       Default constructor for DataVector.       Default constructor for DataVectorTaipan.
67    
68       Description:       Description:
69       Constructs an empty DataVector object.       Constructs an empty DataVectorTaipan object.
70    */    */
71    DataVector();    DataVectorTaipan();
72    
73    /**    /**
74       \brief       \brief
75       Copy constructor for DataVector.       Copy constructor for DataVectorTaipan.
76    
77       Description:       Description:
78       Constructs a DataVector object which is a copy of the       Constructs a DataVectorTaipan object which is a copy of the
79       given DataVector object.       given DataVectorTaipan object.
80    */    */
81    DataVector(const DataVector& other);    DataVectorTaipan(const DataVectorTaipan& other);
82    
83    /**    /**
84       \brief       \brief
85       Constructor for DataVector.       Constructor for DataVectorTaipan.
86    
87       Description:       Description:
88       Constructs a DataVector object of length "size" with all elements       Constructs a DataVectorTaipan object of length "size" with all elements
89       initilised to "val".       initilised to "val".
90    
91       \param size - Input - Number of elements in the vector.       \param size - Input - Number of elements in the vector.
# Line 98  class ESCRIPT_DLL_API DataVector { Line 98  class ESCRIPT_DLL_API DataVector {
98       number of data-points per sample. Size is the total number of elements required to hold       number of data-points per sample. Size is the total number of elements required to hold
99       all elements for all data-points in the given object, ie: number of samples * blocksize.       all elements for all data-points in the given object, ie: number of samples * blocksize.
100    */    */
101    DataVector(const size_type size,    DataVectorTaipan(const size_type size,
102               const value_type val=0.0,               const value_type val=0.0,
103               const size_type blockSize=1);               const size_type blockSize=1);
104    
105    /**    /**
106       \brief       \brief
107       Default destructor for DataVector.       Default destructor for DataVectorTaipan.
108    
109       Description:       Description:
110       Destroys the current DataVector object.       Destroys the current DataVectorTaipan object.
111    */    */
112    ~DataVector();    ~DataVectorTaipan();
113    
114    /**    /**
115       \brief       \brief
116       Resize the DataVector to the given length "newSize".       Resize the DataVectorTaipan to the given length "newSize".
117       All current data is lost. All elements in the new DataVector are       All current data is lost. All elements in the new DataVectorTaipan are
118       initialised to "newVal".       initialised to "newVal".
119    
120       \param newSize - Input - New size for the vector.       \param newSize - Input - New size for the vector.
# Line 141  class ESCRIPT_DLL_API DataVector { Line 141  class ESCRIPT_DLL_API DataVector {
141    
142    /**    /**
143       \brief       \brief
144       Return the number of elements in this DataVector.       Return the number of elements in this DataVectorTaipan.
145    */    */
146    inline    inline
147    size_type    size_type
# Line 149  class ESCRIPT_DLL_API DataVector { Line 149  class ESCRIPT_DLL_API DataVector {
149    
150    /**    /**
151       \brief       \brief
152       DataVector assignment operator "=".       DataVectorTaipan assignment operator "=".
153       Assign the given DataVector object to this.       Assign the given DataVectorTaipan object to this.
154    */    */
155    DataVector&    DataVectorTaipan&
156    operator=(const DataVector& other);    operator=(const DataVectorTaipan& other);
157    
158    /**    /**
159       \brief       \brief
160       DataVector equality comparison operator "==".       DataVectorTaipan equality comparison operator "==".
161       Return true if the given DataVector is equal to this.       Return true if the given DataVectorTaipan is equal to this.
162    */    */
163    bool    bool
164    operator==(const DataVector& other) const;    operator==(const DataVectorTaipan& other) const;
165    
166    /**    /**
167       \brief       \brief
168       DataVector inequality comparison operator "!=".       DataVectorTaipan inequality comparison operator "!=".
169       Return true if the given DataVector is not equal to this.       Return true if the given DataVectorTaipan is not equal to this.
170    */    */
171    bool    bool
172    operator!=(const DataVector& other) const;    operator!=(const DataVectorTaipan& other) const;
173    
174    /**    /**
175      \brief      \brief
176      Return a reference to the element at position i in this DataVector.      Return a reference to the element at position i in this DataVectorTaipan.
177      Will throw an exception if an invalid index "i" is given.      Will throw an exception if an invalid index "i" is given.
178    
179      NB: access to the element one past the end of the vector is permitted      NB: access to the element one past the end of the vector is permitted
# Line 197  class ESCRIPT_DLL_API DataVector { Line 197  class ESCRIPT_DLL_API DataVector {
197    size_type m_N;    size_type m_N;
198    
199    //    //
200    // The container for the elements contained in this DataVector.    // The container for the elements contained in this DataVectorTaipan.
201    ValueType m_array_data;    VectorStorageType m_array_data;
202  };  };
203    
204    
205    
206    class ESCRIPT_DLL_API DataVectorAlt {
207    
208     public:
209    
210      //
211      // The type of the elements stored in the vector.
212      typedef double ElementType;
213    
214      //
215      // Various types exported to clients of this class.
216      
217      typedef const ElementType * ConstValueType;
218      typedef ElementType          value_type;
219      typedef long                 size_type;
220      typedef ElementType &        reference;
221      typedef const ElementType &  const_reference;
222    
223      /**
224         \brief
225         Default constructor for DataVectorAlt.
226    
227         Description:
228         Constructs an empty DataVectorAlt object.
229      */
230      DataVectorAlt();
231    
232      /**
233         \brief
234         Copy constructor for DataVectorAlt.
235    
236         Description:
237         Constructs a DataVectorAlt object which is a copy of the
238         given DataVectorAlt object.
239      */
240      DataVectorAlt(const DataVectorAlt& other);
241    
242      /**
243         \brief
244         Constructor for DataVectorAlt.
245    
246         Description:
247         Constructs a DataVectorAlt object of length "size" with all elements
248         initilised to "val".
249    
250         \param size - Input - Number of elements in the vector.
251         \param val - Input - Initial value for all elements in the vector. Default is 0.0.
252         \param blockSize - Input - size of blocks within the vector, overall vector
253                    size must be a precise multiple of the block size. Default is 1.
254    
255         In escript::Data, blocksize corresponds to the number of elements required to hold all
256         the data-points for a sample, ie: the product of the dimensions of a data-point and the
257         number of data-points per sample. Size is the total number of elements required to hold
258         all elements for all data-points in the given object, ie: number of samples * blocksize.
259      */
260      DataVectorAlt(const size_type size,
261                 const value_type val=0.0,
262                 const size_type blockSize=1);
263    
264      /**
265         \brief
266         Default destructor for DataVectorAlt.
267    
268         Description:
269         Destroys the current DataVectorAlt object.
270      */
271      ~DataVectorAlt();
272    
273      /**
274         \brief
275         Resize the DataVectorAlt to the given length "newSize".
276         All current data is lost. All elements in the new DataVectorAlt are
277         initialised to "newVal".
278    
279         \param newSize - Input - New size for the vector.
280         \param newVal - Input - New initial value for all elements in the vector.
281         \param newBlockSize - Input - New block size for the vector.
282      */
283      void
284      resize(const size_type newSize,
285             const value_type newVal=0.0,
286             const size_type newBlockSize=1);
287    
288      /**
289        \brief
290        Populates the vector with the data from value.
291        This method currently throws an exception if the specified number of copies won't fit.
292        \warning This function does not attempt to perform shape checking.
293      */
294      void
295      copyFromArray(const escript::WrappedArray& value, size_type copies);
296    
297      void
298      copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
299    
300    
301      /**
302         \brief
303         Return the number of elements in this DataVectorAlt.
304      */
305      inline
306      size_type
307      size() const;
308    
309      /**
310         \brief
311         DataVectorAlt assignment operator "=".
312         Assign the given DataVectorAlt object to this.
313      */
314      DataVectorAlt&
315      operator=(const DataVectorAlt& other);
316    
317      /**
318         \brief
319         DataVectorAlt equality comparison operator "==".
320         Return true if the given DataVectorAlt is equal to this.
321      */
322      bool
323      operator==(const DataVectorAlt& other) const;
324    
325      /**
326         \brief
327         DataVectorAlt inequality comparison operator "!=".
328         Return true if the given DataVectorAlt is not equal to this.
329      */
330      bool
331      operator!=(const DataVectorAlt& other) const;
332    
333      /**
334        \brief
335        Return a reference to the element at position i in this DataVectorAlt.
336        Will throw an exception if an invalid index "i" is given.
337    
338        NB: access to the element one past the end of the vector is permitted
339        in order to provide a facility equivalent to an end() pointer.
340      */
341      inline
342      reference
343      operator[](const size_type i);
344    
345      inline
346      const_reference
347      operator[](const size_type i) const;
348    
349    
350     protected:
351    
352     private:
353    
354      size_type m_size;
355      size_type m_dim;
356      size_type m_N;
357    
358      //
359      // The container for the elements contained in this DataVectorTaipan.
360      std::vector<ElementType> m_array_data;
361    };
362    
363    
364    
365    // This is the main version we had
366    //typedef DataVectorTaipan DataVector;
367    
368    typedef DataVectorAlt DataVector;
369    
370    
371  /**  /**
372    \brief    \brief
373    releases unused memory in the memory manager.    releases unused memory in the memory manager.
# Line 211  ESCRIPT_DLL_API void releaseUnusedMemory Line 378  ESCRIPT_DLL_API void releaseUnusedMemory
378    
379    
380  inline  inline
381  DataVector::size_type  DataVectorTaipan::size_type
382  DataVector::size() const  DataVectorTaipan::size() const
383  {  {
384    return m_size;    return m_size;
385  }  }
386    
387  inline  inline
388  DataVector::reference  DataVectorTaipan::reference
389  DataVector::operator[](const DataVector::size_type i)  DataVectorTaipan::operator[](const DataVectorTaipan::size_type i)
390  {  {
391    EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());    EsysAssert(i<size(),"DataVectorTaipan: invalid index specified. " << i << " of " << size());
392    return m_array_data[i];    return m_array_data[i];
393  }  }
394    
395  inline  inline
396  DataVector::const_reference  DataVectorTaipan::const_reference
397  DataVector::operator[](const DataVector::size_type i) const  DataVectorTaipan::operator[](const DataVectorTaipan::size_type i) const
398  {  {
399    EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());    EsysAssert(i<size(),"DataVectorTaipan: invalid index specified. " << i << " of " << size());
400    return m_array_data[i];    return m_array_data[i];
401  }  }
402    
403    
404    
405    
406    inline
407    DataVectorAlt::size_type
408    DataVectorAlt::size() const
409    {
410      return m_size;
411    }
412    
413    inline
414    DataVectorAlt::reference
415    DataVectorAlt::operator[](const DataVectorAlt::size_type i)
416    {
417      EsysAssert(i<size(),"DataVectorAlt: invalid index specified. " << i << " of " << size());
418      return m_array_data[i];
419    }
420    
421    inline
422    DataVectorAlt::const_reference
423    DataVectorAlt::operator[](const DataVectorAlt::size_type i) const
424    {
425      EsysAssert(i<size(),"DataVectorAlt: invalid index specified. " << i << " of " << size());
426      return m_array_data[i];
427    }
428    
429    
430  } // end of namespace  } // end of namespace
431    
432  #endif  #endif

Legend:
Removed from v.5867  
changed lines
  Added in v.5868

  ViewVC Help
Powered by ViewVC 1.1.26