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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (hide annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 5 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataVector.cpp
File size: 3312 byte(s)
Merge of development branch back to main trunk on 2005-05-06

1 jgs 117 /*
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    
15     #include <iostream>
16    
17 jgs 121 #include "escript/Data/DataVector.h"
18     #include "escript/Data/Taipan.h"
19     #include "escript/Data/DataException.h"
20 jgs 117
21     using namespace std;
22 jgs 121 using namespace escript;
23 jgs 117
24     namespace escript {
25    
26 jgs 121 Taipan arrayManager;
27    
28     DataVector::DataVector() :
29     m_array_data(0),
30     m_size(0),
31     m_dim(0),
32     m_N(0)
33     {
34 jgs 117 }
35    
36 jgs 121 DataVector::DataVector(const DataVector& other) :
37     m_array_data(0),
38     m_size(other.m_size),
39     m_dim(other.m_dim),
40     m_N(other.m_N)
41     {
42     m_array_data = arrayManager.new_array(m_dim,m_N);
43     for (int i=0; i<m_size; i++) {
44     m_array_data[i] = other.m_array_data[i];
45     }
46 jgs 117 }
47    
48 jgs 121 DataVector::DataVector(const DataVector::size_type size,
49     const DataVector::value_type val,
50     const DataVector::size_type blockSize) :
51     m_array_data(0),
52     m_size(size),
53     m_dim(blockSize)
54     {
55     resize(size, val, blockSize);
56 jgs 117 }
57    
58 jgs 121 DataVector::~DataVector()
59     {
60     // dispose of data array
61     arrayManager.delete_array(m_array_data);
62    
63     // clear data members
64     m_size = -1;
65     m_dim = -1;
66     m_N = -1;
67     m_array_data = 0;
68 jgs 117 }
69    
70 jgs 121 void
71     DataVector::resize(const DataVector::size_type newSize,
72     const DataVector::value_type newValue,
73     const DataVector::size_type newBlockSize)
74     {
75     assert(m_size >= 0);
76    
77     if ( (newSize % newBlockSize) != 0) {
78     throw DataException("DataVector: invalid blockSize specified");
79     }
80    
81     arrayManager.delete_array(m_array_data);
82    
83     m_size = newSize;
84     m_dim = newBlockSize;
85     m_N = newSize / newBlockSize;
86     m_array_data = arrayManager.new_array(m_dim,m_N);
87    
88     for (int i=0; i<m_size; i++) {
89     m_array_data[i]=newValue;
90     }
91     }
92    
93     DataVector&
94     DataVector::operator=(const DataVector& other)
95     {
96     assert(m_size >= 0);
97    
98     arrayManager.delete_array(m_array_data);
99    
100     m_size = other.m_size;
101     m_dim = other.m_dim;
102     m_N = other.m_N;
103    
104     m_array_data = arrayManager.new_array(m_dim,m_N);
105     for (int i=0; i<m_size; i++) {
106     m_array_data[i] = other.m_array_data[i];
107     }
108    
109     return *this;
110     }
111    
112     bool
113     DataVector::operator==(const DataVector& other) const
114     {
115     assert(m_size >= 0);
116    
117     if (m_size!=other.m_size) {
118     return false;
119     }
120     if (m_dim!=other.m_dim) {
121     return false;
122     }
123     if (m_N!=other.m_N) {
124     return false;
125     }
126     for (int i=0; i<m_size; i++) {
127     if (m_array_data[i] != other.m_array_data[i]) {
128     return false;
129     }
130     }
131     return true;
132     }
133    
134     bool
135     DataVector::operator!=(const DataVector& other) const
136     {
137     return !(*this==other);
138     }
139    
140 jgs 117 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26