/[escript]/branches/arrexp_2137_win_merge/escript/src/DataVector.cpp
ViewVC logotype

Diff of /branches/arrexp_2137_win_merge/escript/src/DataVector.cpp

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

trunk/esys2/escript/src/Data/DataVector.cpp revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC trunk/escript/src/DataVector.cpp revision 477 by jgs, Mon Jan 30 07:20:20 2006 UTC
# Line 12  Line 12 
12   ******************************************************************************   ******************************************************************************
13  */  */
14    
15  #include <iostream>  #include "DataVector.h"
16  #include <cassert>  
17    #include "Taipan.h"
18    #include "DataException.h"
19    
20  #include "escript/Data/DataVector.h"  #include <cassert>
 #include "escript/Data/Taipan.h"  
 #include "escript/Data/DataException.h"  
21    
22  using namespace std;  using namespace std;
23  using namespace escript;  using namespace escript;
# Line 61  DataVector::DataVector(const DataVector: Line 61  DataVector::DataVector(const DataVector:
61  DataVector::~DataVector()  DataVector::~DataVector()
62  {  {
63    // dispose of data array    // dispose of data array
64    arrayManager.delete_array(m_array_data);    if (m_array_data!=0) {
65        arrayManager.delete_array(m_array_data);
66      }
67    
68    // clear data members    // clear data members
69    m_size = -1;    m_size = -1;
# Line 77  DataVector::resize(const DataVector::siz Line 79  DataVector::resize(const DataVector::siz
79  {  {
80    assert(m_size >= 0);    assert(m_size >= 0);
81    
82      if ( newBlockSize == 0) {
83        throw DataException("DataVector: invalid blockSize specified");
84      }
85    
86    if ( (newSize % newBlockSize) != 0) {    if ( (newSize % newBlockSize) != 0) {
87      throw DataException("DataVector: invalid blockSize specified");      throw DataException("DataVector: invalid blockSize specified");
88    }    }
89    
90    arrayManager.delete_array(m_array_data);    if (m_array_data!=0) {
91        arrayManager.delete_array(m_array_data);
92      }
93    
94    m_size = newSize;    m_size = newSize;
95    m_dim = newBlockSize;    m_dim = newBlockSize;
# Line 100  DataVector::operator=(const DataVector& Line 108  DataVector::operator=(const DataVector&
108  {  {
109    assert(m_size >= 0);    assert(m_size >= 0);
110    
111    arrayManager.delete_array(m_array_data);    if (m_array_data!=0) {
112        arrayManager.delete_array(m_array_data);
113      }
114    
115    m_size = other.m_size;    m_size = other.m_size;
116    m_dim = other.m_dim;    m_dim = other.m_dim;
# Line 144  DataVector::operator!=(const DataVector& Line 154  DataVector::operator!=(const DataVector&
154    return !(*this==other);    return !(*this==other);
155  }  }
156    
157    int
158    DataVector::archiveData(ofstream& archiveFile,
159                            const size_type noValues) const
160    {
161      //
162      // Check number of values expected to be written matches number in this object
163      if (noValues != size()) {
164        return 2;
165      }
166    
167      //
168      // Write all values in this object out to archiveFile
169      for (int i=0; i<size(); i++) {
170        archiveFile.write(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
171      }
172    
173      //
174      // Check no errors were encountered before returning
175      if (!archiveFile.good()) {
176        return 1;
177      }
178    
179      return 0;
180    }
181    
182    int
183    DataVector::extractData(ifstream& archiveFile,
184                            const size_type noValues)
185    {
186      //
187      // Check number of values expected to be read matches number in this object
188      if (noValues != size()) {
189        return 2;
190      }
191    
192      //
193      // Read all values in archiveFile back to this object
194      for (int i=0; i<size(); i++) {
195        archiveFile.read(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
196      }
197    
198      //
199      // Check no errors were encountered before returning
200      if (!archiveFile.good()) {
201        return 1;
202      }
203    
204      return 0;
205    }
206    
207  } // end of namespace  } // end of namespace

Legend:
Removed from v.122  
changed lines
  Added in v.477

  ViewVC Help
Powered by ViewVC 1.1.26