Schnek
array.hpp
1 /*
2  * array.hpp
3  *
4  * Created on: 23 Jan 2007
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_ARRAY_HPP_
28 #define SCHNEK_ARRAY_HPP_
29 
30 #include "arraycheck.hpp"
31 namespace schnek {
32 
33 template<class Operator, int Length>
35 
36 
44 template<
45  class T,
46  int length,
47  template<int> class CheckingPolicy = ArrayNoArgCheck
48 >
49 class Array :
50  public CheckingPolicy<length>
51 {
52  private:
54  T data[length];
55 
58  public:
59  typedef T value_type;
60  enum {Length = length};
61 
63  Array();
65  template<template<int> class CheckingPolicy2>
67 
69  template<class Operator>
71 
73  Array(const T&);
75  Array(const T&, const T&);
77  Array(const T&, const T&, const T&);
79  Array(const T&, const T&, const T&, const T&);
81  Array(const T&, const T&, const T&, const T&, const T&);
83  Array(const T&, const T&, const T&, const T&, const T&,
84  const T&);
86  Array(const T&, const T&, const T&, const T&, const T&,
87  const T&, const T&);
89  Array(const T&, const T&, const T&, const T&, const T&,
90  const T&, const T&, const T&);
92  Array(const T&, const T&, const T&, const T&, const T&,
93  const T&, const T&, const T&, const T&);
95  Array(const T&, const T&, const T&, const T&, const T&,
96  const T&, const T&, const T&, const T&, const T&);
97 
98  ~Array() {}
99 
101  T& operator[](int);
103  T operator[](int) const;
104 
106  T& at(int);
108  T at(int) const;
109 
110  public:
117  template<class T2, template <int> class CheckingPolicy2>
119 
121  template<class Operator>
123 
130  template<class T2, template <int> class CheckingPolicy2>
132 
139  template<class T2, template <int> class CheckingPolicy2>
141 
148  template<class T2, template <int> class CheckingPolicy2>
150 
157  template<class T2, template <int> class CheckingPolicy2>
159 
166  template<typename T2>
168 
175  template<typename T2>
177 
184  template<typename T2>
186 
193  template<typename T2>
195 
196 
198  template<class Operator>
200 
202  template<class Operator>
204 
206  template<class Operator>
208 
210  template<class Operator>
212 
213  public:
218 
220  template<int destLength>
222 
223  Array<T,length-1,CheckingPolicy> projectDim(int dim) const;
224 
225 
230 
235 
237  T product() const;
238 
240  T sum() const;
241 
243  T sqr() const;
244 };
245 
246 
247 
248 } // namespace
249 
250 template<
251  class T1, class T2,
252  int length,
253  template<int> class CheckingPolicy1, template<int> class CheckingPolicy2
254 >
255 bool operator==(
258 );
259 
260 template<
261  class T1, class T2,
262  int length,
263  template<int> class CheckingPolicy1, template<int> class CheckingPolicy2
264 >
265 bool operator!=(
268 );
269 
270 template<
271  class T1, class T2,
272  int length,
273  template<int> class CheckingPolicy1, template<int> class CheckingPolicy2
274 >
275 bool operator<(
278 );
279 
280 template<
281  class T1, class T2,
282  int length,
283  template<int> class CheckingPolicy1, template<int> class CheckingPolicy2
284 >
285 bool operator<=(
288 );
289 
290 
291 #include "array.t"
292 
293 #endif // SCHNEK_ARRAY_HPP_
Array< T, length, CheckingPolicy > & operator-=(const Array< T2, length, CheckingPolicy2 > &)
Array< T, destLength, CheckingPolicy > project() const
projects the Array onto an Array of shorter length
Array< T, length, CheckingPolicy > & clear()
Sets all fields to zero.
Definition: array.hpp:49
static Array< T, length, CheckingPolicy > Ones()
Array()
The default constructor.
Array< T, length, CheckingPolicy > & operator*=(const Array< T2, length, CheckingPolicy2 > &)
Definition: array.hpp:34
static Array< T, length, CheckingPolicy > Zero()
Definition: algo.hpp:30
Array< T, length, CheckingPolicy > & fill(const T &)
Fills all fields with a given value.
T sum() const
Returns the sum of all elements.
T & at(int)
Accessor operator.
Definition: arraycheck.hpp:38
Array< T, length, CheckingPolicy > & operator+=(const Array< T2, length, CheckingPolicy2 > &)
Array< T, length, CheckingPolicy > & operator=(const Array< T2, length, CheckingPolicy2 > &)
T sqr() const
Returns the sum of squares of all elements.
T product() const
Returns the product of all elements.
T & operator[](int)
Accessor operator.
Array< T, length, CheckingPolicy > & operator/=(const Array< T2, length, CheckingPolicy2 > &)