/[escript]/trunk/escript/src/DataVector.h
ViewVC logotype

Diff of /trunk/escript/src/DataVector.h

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

revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC revision 121 by jgs, Fri May 6 04:26:16 2005 UTC
# Line 11  Line 11 
11   *                                                                            *   *                                                                            *
12   ******************************************************************************   ******************************************************************************
13  */  */
14                                                                              
15  #if !defined escript_DataVector_20050324_H  #if !defined escript_DataVector_20050324_H
16  #define escript_DataVector_20050324_H  #define escript_DataVector_20050324_H
17    
# Line 24  namespace escript { Line 24  namespace escript {
24  /**  /**
25     \brief     \brief
26     DataVector implements an arbitrarily long vector of data values.     DataVector implements an arbitrarily long vector of data values.
27       DataVector is the underlying data container for Data objects.
28    
29     Description:     Description:
30     DataVector provides an implementation of a vector of data values for use     DataVector provides an implementation of a vector of data values for use
31     by DataBlocks2D and DataArrayView. Hiding the vector in this container     by DataBlocks2D and DataArrayView. Hiding the vector in this container
32     allows different implementations to be swapped in without disrupting the     allows different implementations to be swapped in without disrupting the
33     client classes. This is the underlying data container for Data objects.     client classes.
34  */  */
35    
36  class DataVector {  class DataVector {
# Line 42  class DataVector { Line 43  class DataVector {
43    
44    //    //
45    // The underlying type used to implement the vector.    // The underlying type used to implement the vector.
46    typedef std::vector<ElementType> ValueType;    typedef ElementType *  ValueType;
47    
48    //    //
49    // Various types needed by clients of this class.    // Various types exported to clients of this class.
50    typedef ValueType::value_type       value_type;    typedef ElementType          value_type;
51    typedef ValueType::size_type        size_type;    typedef long                 size_type;
52    typedef ValueType::reference        reference;    typedef ElementType &        reference;
53    typedef ValueType::const_reference  const_reference;    typedef const ElementType &  const_reference;
   typedef ValueType::iterator         iterator;  
54    
55    /**    /**
56       \brief       \brief
# Line 77  class DataVector { Line 77  class DataVector {
77    
78       Description:       Description:
79       Constructs a DataVector object of length "size" with all elements       Constructs a DataVector object of length "size" with all elements
80       initilised to "val". Default for "val" is zero.       initilised to "val".
81    
82       \param size - Input - Number of elements in the vector.       \param size - Input - Number of elements in the vector.
83    */       \param val - Input - Initial value for all elements in the vector. Default is 0.0.
84    DataVector(ValueType::size_type size, ValueType::value_type val=0.0);       \param blockSize - Input - size of blocks within the vector, overall vector
85                    size must be a precise multiple of the block size. Default is 1.
86      */
87      DataVector(const size_type size,
88                 const value_type val=0.0,
89                 const size_type blockSize=1);
90    
91    /**    /**
92       \brief       \brief
# Line 96  class DataVector { Line 101  class DataVector {
101       \brief       \brief
102       Resize the DataVector to the given length "newSize".       Resize the DataVector to the given length "newSize".
103       All current data is lost. All elements in the new DataVector are       All current data is lost. All elements in the new DataVector are
104       initialised to "newVal", which defaults to zero.       initialised to "newVal".
105    
106       \param newSize - Input - New size for the vector.       \param newSize - Input - New size for the vector.
107         \param newVal - Input - New initial value for all elements in the vector.
108         \param newBlockSize - Input - New block size for the vector.
109    */    */
   inline  
110    void    void
111    resize(ValueType::size_type newSize, ValueType::value_type newVal=0.0);    resize(const size_type newSize,
112             const value_type newVal=0.0,
113             const size_type newBlockSize=1);
114    
115    /**    /**
116       \brief       \brief
117       Return the number of elements in this DataVector.       Return the number of elements in this DataVector.
118    */    */
119    inline    inline
120    ValueType::size_type    size_type
121    size() const;    size() const;
122    
123    /**    /**
# Line 117  class DataVector { Line 125  class DataVector {
125       DataVector assignment operator "=".       DataVector assignment operator "=".
126       Assign the given DataVector object to this.       Assign the given DataVector object to this.
127    */    */
   inline  
128    DataVector&    DataVector&
129    operator=(const DataVector& other);    operator=(const DataVector& other);
130    
# Line 126  class DataVector { Line 133  class DataVector {
133       DataVector equality comparison operator "==".       DataVector equality comparison operator "==".
134       Return true if the given DataVector is equal to this.       Return true if the given DataVector is equal to this.
135    */    */
   inline  
136    bool    bool
137    operator==(const DataVector& other);    operator==(const DataVector& other) const;
138    
139    /**    /**
140       \brief       \brief
141       DataVector inequality comparison operator "!=".       DataVector inequality comparison operator "!=".
142       Return true if the given DataVector is not equal to this.       Return true if the given DataVector is not equal to this.
143    */    */
   inline  
144    bool    bool
145    operator!=(const DataVector& other);    operator!=(const DataVector& other) const;
146    
147    /**    /**
148      \brief      \brief
# Line 148  class DataVector { Line 153  class DataVector {
153      in order to provide a facility equivalent to an end() pointer.      in order to provide a facility equivalent to an end() pointer.
154    */    */
155    inline    inline
156    ValueType::reference    reference
157    operator[](ValueType::size_type i);    operator[](const size_type i);
   
   inline  
   ValueType::const_reference  
   operator[](ValueType::size_type i) const;  
158    
   /**  
     \brief  
     Add the element x at the end of the vector.  
   */  
159    inline    inline
160    void    const_reference
161    push_back(const ValueType::value_type& x);    operator[](const size_type i) const;
   
   /**  
     \brief  
     Insert.  
   */  
   inline  
   void  
   insert(iterator pos, const ValueType::value_type* first, const ValueType::value_type* last);  
   
   /**  
     \brief  
     End.  
   */  
   inline  
   iterator  
   end();  
162    
163   protected:   protected:
164    
165   private:   private:
166    
167      size_type m_size;
168      size_type m_dim;
169      size_type m_N;
170    
171    //    //
172    // The container for the elements contained in this DataVector.    // The container for the elements contained in this DataVector.
173    ValueType m_data;    ValueType m_array_data;
   
174  };  };
175    
176  inline  inline
177  DataVector::ValueType::size_type  DataVector::size_type
178  DataVector::size() const  DataVector::size() const
179  {  {
180    return m_data.size();    return m_size;
 }  
   
 inline  
 DataVector::ValueType::reference  
 DataVector::operator[](DataVector::ValueType::size_type i)  
 {  
   // Allow access to element one beyond end of vector to simulate end().  
   EsysAssert(i<=size(),"DataVector: invalid index specified.");  
   return m_data[i];  
 }  
   
 inline  
 DataVector::ValueType::const_reference  
 DataVector::operator[](DataVector::ValueType::size_type i) const  
 {  
   // Allow access to element one beyond end of vector to simulate end().  
   EsysAssert(i<=size(),"DataVector: invalid index specified.");  
   return m_data[i];  
 }  
   
 inline  
 DataVector&  
 DataVector::operator=(const DataVector& other)  
 {  
   DataVector temp(other);  
   swap(m_data,temp.m_data);  
   return *this;  
 }  
   
 inline  
 bool  
 DataVector::operator==(const DataVector& other)  
 {  
   return m_data==other.m_data;  
 }  
   
 inline  
 bool  
 DataVector::operator!=(const DataVector& other)  
 {  
   return m_data!=other.m_data;  
 }  
   
 inline  
 void  
 DataVector::resize(DataVector::ValueType::size_type newSize, DataVector::ValueType::value_type newValue)  
 {  
   m_data.resize(newSize,newValue);  
 }  
   
 inline  
 void  
 DataVector::push_back(const ValueType::value_type& x)  
 {  
   m_data.push_back(x);  
181  }  }
182    
183  inline  inline
184  void  DataVector::reference
185  DataVector::insert(DataVector::iterator pos, const ValueType::value_type* first, const ValueType::value_type* last)  DataVector::operator[](const DataVector::size_type i)
186  {  {
187    m_data.insert(pos, first, last);    EsysAssert(i<size(),"DataVector: invalid index specified.");
188      return m_array_data[i];
189  }  }
190    
191  inline  inline
192  DataVector::iterator  DataVector::const_reference
193  DataVector::end()  DataVector::operator[](const DataVector::size_type i) const
194  {  {
195    return m_data.end();    EsysAssert(i<size(),"DataVector: invalid index specified.");
196      return m_array_data[i];
197  }  }
198    
199  } // end of namespace  } // end of namespace

Legend:
Removed from v.117  
changed lines
  Added in v.121

  ViewVC Help
Powered by ViewVC 1.1.26