/[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 116 by jgs, Tue Oct 26 06:53:54 2004 UTC revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC
# Line 11  Line 11 
11   *                                                                            *   *                                                                            *
12   ******************************************************************************   ******************************************************************************
13  */  */
14    
15  #include "escript/Data/DataException.h"  #include "escript/Data/DataException.h"
16  #include "escript/Data/DataBlocks2D.h"  #include "escript/Data/DataBlocks2D.h"
17  #include "esysUtils/EsysAssert.h"  #include "esysUtils/EsysAssert.h"
# Line 26  DataBlocks2D::DataBlocks2D(): Line 27  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      //cout << "Calling DataBlocks2D default constructor." << endl;  }
   }  
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    {  {
     //cout << "Calling DataBlocks2D copy constructor." << endl;  
     //  
     // Copy the vector values, this may throw an exception  
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    {  {
     //cout << "Calling DataBlocks2D constructor." << endl;  
     //  
     // allocate the data and initialise to 0  
46      resize(m_numRows,numCols,blockSize);      resize(m_numRows,numCols,blockSize);
47    }  }
48    
49  DataBlocks2D::~DataBlocks2D()  DataBlocks2D::~DataBlocks2D()
50    {      {    
51      //cout << "Calling DataBlocks2D default destructor." << endl;  }
   }  
   
 DataBlocks2D::ValueType::size_type  
 DataBlocks2D::index(ValueType::size_type i, ValueType::size_type j) const  
   {  
     ValueType::size_type temp=(j+i*m_numCols)*m_blockSize;  
     // EsysAssert((temp >= 0),"(DataBlocks2D) Index value: " << temp << " out of range.");  
     EsysAssert((temp <= (m_data.size()-m_blockSize) &&  
         (m_data.size() > 0) ),  
            "(DataBlocks2D) Index value: " << temp << " out of range."  
            << " nRows=" << m_numRows << " nCols=" << m_numCols  
            << " blockSize=" << m_blockSize  
            << " dataSize=" << m_data.size());  
     return (temp);  
   }  
   
 DataBlocks2D::ValueType&  
 DataBlocks2D::getData()  
   {  
     return m_data;  
   }  
   
 const DataBlocks2D::ValueType&  
 DataBlocks2D::getData() const  
   {  
     return m_data;  
   }  
52    
53  void  void
54  DataBlocks2D::resize(int numRows, int numCols, int blockSize)  DataBlocks2D::resize(int numRows, int numCols, int blockSize)
55    {  {
   
56      if (numRows < 0 || numCols < 0 || blockSize < 0) {      if (numRows < 0 || numCols < 0 || blockSize < 0) {
57        stringstream mess;        stringstream mess;
58        mess << "Error - Invalid resize parameter. numRows: " << numRows        mess << "Error - Invalid resize parameter. numRows: " << numRows
# Line 98  DataBlocks2D::resize(int numRows, int nu Line 64  DataBlocks2D::resize(int numRows, int nu
64      m_numRows=numRows;      m_numRows=numRows;
65      m_numCols=numCols;      m_numCols=numCols;
66      m_blockSize=blockSize;      m_blockSize=blockSize;
67    }  }
68    
69  void  void
70  DataBlocks2D::Swap(DataBlocks2D& other)  DataBlocks2D::Swap(DataBlocks2D& other)
71    {  {
72      swap(m_data,other.m_data);      swap(m_data,other.m_data);
73      swap(m_blockSize,other.m_blockSize);      swap(m_blockSize,other.m_blockSize);
74      swap(m_numRows,other.m_numRows);      swap(m_numRows,other.m_numRows);
75      swap(m_numCols,other.m_numCols);      swap(m_numCols,other.m_numCols);
76    }  }
77    
78  DataBlocks2D&  DataBlocks2D&
79  DataBlocks2D::operator=(const DataBlocks2D& other)  DataBlocks2D::operator=(const DataBlocks2D& other)
80    {  {
81      DataBlocks2D temp(other);      DataBlocks2D temp(other);
82      Swap(temp);      Swap(temp);
83      return *this;      return *this;
84    }  }
85      
86  }  // end of namespace  }  // end of namespace
   
   
   
   

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

  ViewVC Help
Powered by ViewVC 1.1.26