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

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

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

trunk/esys2/escript/src/Data/DataBlocks2D.cpp revision 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/src/DataBlocks2D.cpp revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
1    
2  #include "escript/Data/DataException.h"  /* $Id$ */
3  #include "escript/Data/DataBlocks2D.h"  
4  #include "esysUtils/EsysAssert.h"  /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16    #include "DataBlocks2D.h"
17    
18  #include <sstream>  #include "DataException.h"
19  #include <iostream>  #include "esysUtils/EsysAssert.h"
20    
21  using namespace std;  using namespace std;
22    
23  namespace escript {  namespace escript {
24    
25  DataBlocks2D::DataBlocks2D():  DataBlocks2D::DataBlocks2D():
26     m_numRows(0),    m_numRows(0),
27     m_numCols(0),    m_numCols(0),
28     m_blockSize(0)    m_blockSize(0)
29  {      {
30  }  }
31    
32  DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):  DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):
33     m_numRows(other.m_numRows),    m_numRows(other.m_numRows),
34     m_numCols(other.m_numCols),    m_numCols(other.m_numCols),
35     m_blockSize(other.m_blockSize)    m_blockSize(other.m_blockSize)
36  {  {
37      m_data=other.m_data;      m_data=other.m_data;
38  }  }
39    
40  DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):  DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):
41      m_numRows(numRows),    m_numRows(numRows),
42      m_numCols(numCols),    m_numCols(numCols),
43      m_blockSize(blockSize)    m_blockSize(blockSize)
44  {  {
45      resize(m_numRows,numCols,blockSize);      resize(m_numRows,numCols,blockSize);
46  }  }
47    
48  DataBlocks2D::~DataBlocks2D()  DataBlocks2D::~DataBlocks2D()
49  {      {
50        m_numRows=-1;
51        m_numCols=-1;
52        m_blockSize=-1;
53  }  }
54    
55  void  void
56  DataBlocks2D::resize(int numRows, int numCols, int blockSize)  DataBlocks2D::resize(int numRows, int numCols, int blockSize)
57  {  {
58      if (numRows < 0 || numCols < 0 || blockSize < 0) {      if (numRows < 1 || numCols < 1 || blockSize < 1) {
59        stringstream mess;        stringstream temp;
60        mess << "Error - Invalid resize parameter. numRows: " << numRows        temp << "DataBlocks2D: Error - Invalid resize parameter. numRows: " << numRows
61         << " numCols: " << numCols << " blockSize: " << blockSize;         << " numCols: " << numCols << " blockSize: " << blockSize;
62        throw DataException(mess.str());        throw DataException(temp.str());
63      }      }
64      ValueType::size_type size=numRows*numCols*blockSize;      ValueType::size_type size=numRows*numCols*blockSize;
65      m_data.resize(size);      m_data.resize(size, 0.0, numCols*blockSize);
66      m_numRows=numRows;      m_numRows=numRows;
67      m_numCols=numCols;      m_numCols=numCols;
68      m_blockSize=blockSize;      m_blockSize=blockSize;
# Line 69  DataBlocks2D::resize(int numRows, int nu Line 71  DataBlocks2D::resize(int numRows, int nu
71  void  void
72  DataBlocks2D::Swap(DataBlocks2D& other)  DataBlocks2D::Swap(DataBlocks2D& other)
73  {  {
74        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
75      swap(m_data,other.m_data);      swap(m_data,other.m_data);
76      swap(m_blockSize,other.m_blockSize);      swap(m_blockSize,other.m_blockSize);
77      swap(m_numRows,other.m_numRows);      swap(m_numRows,other.m_numRows);
# Line 78  DataBlocks2D::Swap(DataBlocks2D& other) Line 81  DataBlocks2D::Swap(DataBlocks2D& other)
81  DataBlocks2D&  DataBlocks2D&
82  DataBlocks2D::operator=(const DataBlocks2D& other)  DataBlocks2D::operator=(const DataBlocks2D& other)
83  {  {
84        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
85      DataBlocks2D temp(other);      DataBlocks2D temp(other);
86      Swap(temp);      Swap(temp);
87      return *this;      return *this;
# Line 87  int Line 91  int
91  DataBlocks2D::archiveData(ofstream& archiveFile,  DataBlocks2D::archiveData(ofstream& archiveFile,
92                            const ValueType::size_type noValues) const                            const ValueType::size_type noValues) const
93  {  {
94    return(m_data.archiveData(archiveFile, noValues));      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
95        return (m_data.archiveData(archiveFile, noValues));
96  }  }
97    
98  int  int
99  DataBlocks2D::extractData(ifstream& archiveFile,  DataBlocks2D::extractData(ifstream& archiveFile,
100                            const ValueType::size_type noValues)                            const ValueType::size_type noValues)
101  {  {
102    return(m_data.extractData(archiveFile, noValues));      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
103        return (m_data.extractData(archiveFile, noValues));
104  }  }
105    
106  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.123  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26