Array4D_Inline.cxx
1 // Copyright (C) 2010 Lin Wu
2 // Copyright (C) 2001-2009 Vivien Mallet
3 // Copyright (C) 2003-2009 Marc DuruflĂ©
4 //
5 // This file is part of the linear-algebra library Seldon,
6 // http://seldon.sourceforge.net/.
7 //
8 // Seldon is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License as published by the Free
10 // Software Foundation; either version 2.1 of the License, or (at your option)
11 // any later version.
12 //
13 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
14 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with Seldon. If not, see http://www.gnu.org/licenses/.
20 
21 
22 #ifndef SELDON_FILE_ARRAY4D_INLINE_CXX
23 
24 #include "Array4D.hxx"
25 
26 namespace Seldon
27 {
28 
29  /**************
30  * DESTRUCTOR *
31  **************/
32 
33 
35  template <class T, class Allocator>
37  {
38  Clear();
39  }
40 
41 
42  /*****************
43  * BASIC METHODS *
44  *****************/
45 
46 
48 
51  template <class T, class Allocator>
53  {
54  return length1_;
55  }
56 
57 
59 
62  template <class T, class Allocator>
64  {
65  return length2_;
66  }
67 
68 
70 
73  template <class T, class Allocator>
75  {
76  return length3_;
77  }
78 
79 
81 
84  template <class T, class Allocator>
86  {
87  return length4_;
88  }
89 
90 
92 
97  template <class T, class Allocator>
98  inline long Array4D<T, Allocator>::GetSize() const
99  {
100  return length1_ * length234_;
101  }
102 
103 
105 
111  template <class T, class Allocator>
113  {
114  return length1_ * length234_;
115  }
116 
117 
119 
124  template <class T, class Allocator>
125  inline typename Array4D<T, Allocator>::pointer Array4D<T, Allocator>
126  ::GetData() const
127  {
128  return data_;
129  }
130 
131 
133 
141  template <class T, class Allocator>
142  inline typename Array4D<T, Allocator>::pointer Array4D<T, Allocator>
143  ::GetDataPointer(int i, int j, int k, int l) const
144  {
145  return data_ + i * length234_ + j * length34_ + k * length4_ + l;
146  }
147 
148 
149  /**********************************
150  * ELEMENT ACCESS AND AFFECTATION *
151  **********************************/
152 
153 
155 
163  template <class T, class Allocator>
164  inline typename Array4D<T, Allocator>::reference
165  Array4D<T, Allocator>::operator() (int i, int j, int k, int l)
166  {
167 
168 #ifdef SELDON_CHECK_BOUNDS
169  CheckBounds(i, j, k, l, length1_,
170  length2_, length3_, length4_, "Array4D");
171 #endif
172 
173  return data_[i * length234_ + j * length34_ + k * length4_ + l];
174  }
175 
176 
178 
186  template <class T, class Allocator>
187  inline typename Array4D<T, Allocator>::const_reference
188  Array4D<T, Allocator>::operator() (int i, int j, int k, int l) const
189  {
190 
191 #ifdef SELDON_CHECK_BOUNDS
192  CheckBounds(i, j, k, l, length1_,
193  length2_, length3_, length4_, "Array4D");
194 #endif
195 
196  return data_[i*length234_ + j*length34_ + k*length4_ + l];
197  }
198 
200 
205  template <class T, class Allocator>
208  {
209  Copy(A);
210 
211  return *this;
212  }
213 
215 
220  template <class T, class Allocator>
222  {
223  Reallocate(A.GetLength1(), A.GetLength2(),
224  A.GetLength3(), A.GetLength4());
225 
226  Allocator::memorycpy(data_, A.GetData(), GetDataSize());
227  }
228 
229 } // namespace Seldon.
230 
231 #define SELDON_FILE_ARRAY4D_INLINE_CXX
232 #endif
Seldon::Array4D::Copy
void Copy(const Array4D< T, Allocator > &A)
Duplicates a 4D array.
Definition: Array4D_Inline.cxx:221
Seldon::Array4D::operator()
reference operator()(int i, int j, int k, int l)
Access operator.
Definition: Array4D_Inline.cxx:165
Seldon::Array4D::GetLength3
int GetLength3() const
Returns the length in dimension #3.
Definition: Array4D_Inline.cxx:74
Seldon::Array4D::GetLength1
int GetLength1() const
Returns the length in dimension #1.
Definition: Array4D_Inline.cxx:52
Seldon::Array4D::~Array4D
~Array4D()
Destructor.
Definition: Array4D_Inline.cxx:36
Seldon::Array4D::GetDataPointer
pointer GetDataPointer(int i, int j, int k, int l) const
Returns a pointer to an element of data array.
Definition: Array4D_Inline.cxx:143
Seldon::Array4D::GetLength4
int GetLength4() const
Returns the length in dimension #4.
Definition: Array4D_Inline.cxx:85
Seldon::Array4D::GetData
pointer GetData() const
Returns a pointer to the data array.
Definition: Array4D_Inline.cxx:126
Seldon::Array4D::GetLength2
int GetLength2() const
Returns the length in dimension #2.
Definition: Array4D_Inline.cxx:63
Seldon::Array4D
4D array.
Definition: Array4D.hxx:39
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Array4D::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Array4D_Inline.cxx:112
Seldon::Array4D::GetSize
long GetSize() const
Returns the number of elements in the 4D array.
Definition: Array4D_Inline.cxx:98