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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (hide annotations)
Tue Oct 26 06:53:54 2004 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataBlocks2D.cpp
File size: 3584 byte(s)
Initial revision

1 jgs 82 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14     #include "escript/Data/DataException.h"
15     #include "escript/Data/DataBlocks2D.h"
16     #include "esysUtils/EsysAssert.h"
17    
18     #include <sstream>
19     #include <iostream>
20    
21     using namespace std;
22    
23     namespace escript {
24    
25     DataBlocks2D::DataBlocks2D():
26     m_numRows(0),
27     m_numCols(0),
28     m_blockSize(0)
29     {
30     //cout << "Calling DataBlocks2D default constructor." << endl;
31     }
32    
33     DataBlocks2D::DataBlocks2D(const DataBlocks2D& other):
34     m_numRows(other.m_numRows),
35     m_numCols(other.m_numCols),
36     m_blockSize(other.m_blockSize)
37     {
38     //cout << "Calling DataBlocks2D copy constructor." << endl;
39     //
40     // Copy the vector values, this may throw an exception
41     m_data=other.m_data;
42     }
43    
44     DataBlocks2D::DataBlocks2D(int numRows, int numCols, int blockSize):
45     m_numRows(numRows),
46     m_numCols(numCols),
47     m_blockSize(blockSize)
48     {
49     //cout << "Calling DataBlocks2D constructor." << endl;
50     //
51     // allocate the data and initialise to 0
52     resize(m_numRows,numCols,blockSize);
53     }
54    
55     DataBlocks2D::~DataBlocks2D()
56     {
57     //cout << "Calling DataBlocks2D default destructor." << endl;
58     }
59    
60     DataBlocks2D::ValueType::size_type
61     DataBlocks2D::index(ValueType::size_type i, ValueType::size_type j) const
62     {
63     ValueType::size_type temp=(j+i*m_numCols)*m_blockSize;
64     // EsysAssert((temp >= 0),"(DataBlocks2D) Index value: " << temp << " out of range.");
65     EsysAssert((temp <= (m_data.size()-m_blockSize) &&
66     (m_data.size() > 0) ),
67     "(DataBlocks2D) Index value: " << temp << " out of range."
68     << " nRows=" << m_numRows << " nCols=" << m_numCols
69     << " blockSize=" << m_blockSize
70     << " dataSize=" << m_data.size());
71     return (temp);
72     }
73    
74     DataBlocks2D::ValueType&
75     DataBlocks2D::getData()
76     {
77     return m_data;
78     }
79    
80     const DataBlocks2D::ValueType&
81     DataBlocks2D::getData() const
82     {
83     return m_data;
84     }
85    
86     void
87     DataBlocks2D::resize(int numRows, int numCols, int blockSize)
88     {
89    
90     if (numRows < 0 || numCols < 0 || blockSize < 0) {
91     stringstream mess;
92     mess << "Error - Invalid resize parameter. numRows: " << numRows
93     << " numCols: " << numCols << " blockSize: " << blockSize;
94     throw DataException(mess.str());
95     }
96     ValueType::size_type size=numRows*numCols*blockSize;
97     m_data.resize(size,0.0);
98     m_numRows=numRows;
99     m_numCols=numCols;
100     m_blockSize=blockSize;
101     }
102    
103     void
104     DataBlocks2D::Swap(DataBlocks2D& other)
105     {
106     swap(m_data,other.m_data);
107     swap(m_blockSize,other.m_blockSize);
108     swap(m_numRows,other.m_numRows);
109     swap(m_numCols,other.m_numCols);
110     }
111    
112     DataBlocks2D&
113     DataBlocks2D::operator=(const DataBlocks2D& other)
114     {
115     DataBlocks2D temp(other);
116     Swap(temp);
117     return *this;
118     }
119    
120     } // end of namespace
121    
122    
123    
124    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26