/[escript]/trunk/escript/src/DataBlocks2D.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataBlocks2D.cpp

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

revision 150 by jgs, Fri Jul 8 04:08:13 2005 UTC revision 151 by jgs, Thu Sep 22 01:55:00 2005 UTC
# Line 24  using namespace std; Line 24  using namespace std;
24  namespace escript {  namespace escript {
25    
26  DataBlocks2D::DataBlocks2D():  DataBlocks2D::DataBlocks2D():
27     m_numRows(0),    m_numRows(0),
28     m_numCols(0),    m_numCols(0),
29     m_blockSize(0)    m_blockSize(0)
30  {      {
31  }  }
32    
33  DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):  DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):
34     m_numRows(other.m_numRows),    m_numRows(other.m_numRows),
35     m_numCols(other.m_numCols),    m_numCols(other.m_numCols),
36     m_blockSize(other.m_blockSize)    m_blockSize(other.m_blockSize)
37  {  {
38      m_data=other.m_data;      m_data=other.m_data;
39  }  }
40    
41  DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):  DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):
42      m_numRows(numRows),    m_numRows(numRows),
43      m_numCols(numCols),    m_numCols(numCols),
44      m_blockSize(blockSize)    m_blockSize(blockSize)
45  {  {
46      resize(m_numRows,numCols,blockSize);      resize(m_numRows,numCols,blockSize);
47  }  }
48    
49  DataBlocks2D::~DataBlocks2D()  DataBlocks2D::~DataBlocks2D()
50  {      {
51        m_numRows=-1;
52        m_numCols=-1;
53        m_blockSize=-1;
54  }  }
55    
56  void  void
57  DataBlocks2D::resize(int numRows, int numCols, int blockSize)  DataBlocks2D::resize(int numRows, int numCols, int blockSize)
58  {  {
59      if (numRows < 0 || numCols < 0 || blockSize < 0) {      if (numRows < 1 || numCols < 1 || blockSize < 1) {
60        stringstream mess;        stringstream temp;
61        mess << "Error - Invalid resize parameter. numRows: " << numRows        temp << "DataBlocks2D: Error - Invalid resize parameter. numRows: " << numRows
62         << " numCols: " << numCols << " blockSize: " << blockSize;         << " numCols: " << numCols << " blockSize: " << blockSize;
63        throw DataException(mess.str());        throw DataException(temp.str());
64      }      }
65      ValueType::size_type size=numRows*numCols*blockSize;      ValueType::size_type size=numRows*numCols*blockSize;
66      m_data.resize(size);      m_data.resize(size, 0.0, numCols*blockSize);
67      m_numRows=numRows;      m_numRows=numRows;
68      m_numCols=numCols;      m_numCols=numCols;
69      m_blockSize=blockSize;      m_blockSize=blockSize;
# Line 69  DataBlocks2D::resize(int numRows, int nu Line 72  DataBlocks2D::resize(int numRows, int nu
72  void  void
73  DataBlocks2D::Swap(DataBlocks2D& other)  DataBlocks2D::Swap(DataBlocks2D& other)
74  {  {
75        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
76      swap(m_data,other.m_data);      swap(m_data,other.m_data);
77      swap(m_blockSize,other.m_blockSize);      swap(m_blockSize,other.m_blockSize);
78      swap(m_numRows,other.m_numRows);      swap(m_numRows,other.m_numRows);
# Line 78  DataBlocks2D::Swap(DataBlocks2D& other) Line 82  DataBlocks2D::Swap(DataBlocks2D& other)
82  DataBlocks2D&  DataBlocks2D&
83  DataBlocks2D::operator=(const DataBlocks2D& other)  DataBlocks2D::operator=(const DataBlocks2D& other)
84  {  {
85        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
86      DataBlocks2D temp(other);      DataBlocks2D temp(other);
87      Swap(temp);      Swap(temp);
88      return *this;      return *this;
# Line 87  int Line 92  int
92  DataBlocks2D::archiveData(ofstream& archiveFile,  DataBlocks2D::archiveData(ofstream& archiveFile,
93                            const ValueType::size_type noValues) const                            const ValueType::size_type noValues) const
94  {  {
95    return(m_data.archiveData(archiveFile, noValues));      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
96        return (m_data.archiveData(archiveFile, noValues));
97  }  }
98    
99  int  int
100  DataBlocks2D::extractData(ifstream& archiveFile,  DataBlocks2D::extractData(ifstream& archiveFile,
101                            const ValueType::size_type noValues)                            const ValueType::size_type noValues)
102  {  {
103    return(m_data.extractData(archiveFile, noValues));      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
104        return (m_data.extractData(archiveFile, noValues));
105  }  }
106    
107  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.150  
changed lines
  Added in v.151

  ViewVC Help
Powered by ViewVC 1.1.26