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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 615 - (show annotations)
Wed Mar 22 02:12:00 2006 UTC (13 years, 6 months ago) by elspeth
Original Path: trunk/escript/src/DataBlocks2D.cpp
File size: 2910 byte(s)
More copyright information.

1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 #include "DataBlocks2D.h"
14
15 #include "DataException.h"
16 #include "EsysAssert.h"
17
18 using namespace std;
19
20 namespace escript {
21
22 DataBlocks2D::DataBlocks2D():
23 m_numRows(0),
24 m_numCols(0),
25 m_blockSize(0)
26 {
27 }
28
29 DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):
30 m_numRows(other.m_numRows),
31 m_numCols(other.m_numCols),
32 m_blockSize(other.m_blockSize)
33 {
34 m_data=other.m_data;
35 }
36
37 DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):
38 m_numRows(numRows),
39 m_numCols(numCols),
40 m_blockSize(blockSize)
41 {
42 resize(m_numRows,numCols,blockSize);
43 }
44
45 DataBlocks2D::~DataBlocks2D()
46 {
47 m_numRows=-1;
48 m_numCols=-1;
49 m_blockSize=-1;
50 }
51
52 void
53 DataBlocks2D::resize(int numRows, int numCols, int blockSize)
54 {
55 if (numRows < 1 || numCols < 1 || blockSize < 1) {
56 stringstream temp;
57 temp << "DataBlocks2D: Error - Invalid resize parameter. numRows: " << numRows
58 << " numCols: " << numCols << " blockSize: " << blockSize;
59 throw DataException(temp.str());
60 }
61 ValueType::size_type size=numRows*numCols*blockSize;
62 m_data.resize(size, 0.0, numCols*blockSize);
63 m_numRows=numRows;
64 m_numCols=numCols;
65 m_blockSize=blockSize;
66 }
67
68 void
69 DataBlocks2D::Swap(DataBlocks2D& other)
70 {
71 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
72 swap(m_data,other.m_data);
73 swap(m_blockSize,other.m_blockSize);
74 swap(m_numRows,other.m_numRows);
75 swap(m_numCols,other.m_numCols);
76 }
77
78 DataBlocks2D&
79 DataBlocks2D::operator=(const DataBlocks2D& other)
80 {
81 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
82 DataBlocks2D temp(other);
83 Swap(temp);
84 return *this;
85 }
86
87 int
88 DataBlocks2D::archiveData(ofstream& archiveFile,
89 const ValueType::size_type noValues) const
90 {
91 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
92 return (m_data.archiveData(archiveFile, noValues));
93 }
94
95 int
96 DataBlocks2D::extractData(ifstream& archiveFile,
97 const ValueType::size_type noValues)
98 {
99 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
100 return (m_data.extractData(archiveFile, noValues));
101 }
102
103 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26