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 
32 #include "../config.hpp"
33 #include "../macros.hpp"
34 
35 #include <initializer_list>
36 
37 namespace schnek {
38 
39 template<class Operator, size_t Length>
41 
42 
50 template<
51  class T,
52  size_t Length,
53  template<size_t> class CheckingPolicy = ArrayNoArgCheck
54 >
55 class Array :
56  public CheckingPolicy<Length>
57 {
58  private:
60  T data[Length];
61 
64  public:
65  typedef T value_type;
66  static constexpr size_t length = Length;
67 
69  SCHNEK_INLINE Array();
71  template<template<size_t> class CheckingPolicy2>
72  SCHNEK_INLINE Array(const Array<T, Length, CheckingPolicy2> &);
73 
75  template<class Operator>
76  SCHNEK_INLINE Array(const ArrayExpression<Operator, Length> &);
77 
79  // Array(std::initializer_list<T> l);
80 
82  SCHNEK_INLINE Array(const T&);
84  SCHNEK_INLINE Array(const T&, const T&);
86  SCHNEK_INLINE Array(const T&, const T&, const T&);
88  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&);
90  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&);
92  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&,
93  const T&);
95  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&,
96  const T&, const T&);
98  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&,
99  const T&, const T&, const T&);
101  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&,
102  const T&, const T&, const T&, const T&);
104  SCHNEK_INLINE Array(const T&, const T&, const T&, const T&, const T&,
105  const T&, const T&, const T&, const T&, const T&);
106 
107  SCHNEK_INLINE ~Array() {}
108 
110  SCHNEK_INLINE T& operator[](size_t);
112  SCHNEK_INLINE T operator[](size_t) const;
113 
115  SCHNEK_INLINE T& at(size_t);
117  SCHNEK_INLINE T at(size_t) const;
118 
119  public:
126  template<class T2, template <size_t> class CheckingPolicy2>
128 
130  template<class Operator>
132 
139  template<class T2, template <size_t> class CheckingPolicy2>
141 
148  template<class T2, template <size_t> class CheckingPolicy2>
150 
157  template<class T2, template <size_t> class CheckingPolicy2>
159 
166  template<class T2, template <size_t> class CheckingPolicy2>
168 
175  template<typename T2>
176  SCHNEK_INLINE Array<T,Length,CheckingPolicy> &operator+=(const T2);
177 
184  template<typename T2>
185  SCHNEK_INLINE Array<T,Length,CheckingPolicy> &operator-=(const T2);
186 
193  template<typename T2>
194  SCHNEK_INLINE Array<T,Length,CheckingPolicy> &operator*=(const T2);
195 
202  template<typename T2>
203  SCHNEK_INLINE Array<T,Length,CheckingPolicy> &operator/=(const T2);
204 
205 
207  template<class Operator>
209 
211  template<class Operator>
213 
215  template<class Operator>
217 
219  template<class Operator>
221 
222  public:
227 
229  template<size_t destLength>
231 
232  Array<T,Length-1,CheckingPolicy> projectDim(size_t dim) const;
233 
234 
239 
244 
246  T product() const;
247 
249  T sum() const;
250 
252  T sqr() const;
253 };
254 
255 
256 
257 } // namespace
258 
259 template<
260  class T1, class T2,
261  size_t Length,
262  template<size_t> class CheckingPolicy1, template<size_t> class CheckingPolicy2
263 >
264 SCHNEK_INLINE bool operator==(
267 );
268 
269 template<
270  class T1, class T2,
271  size_t Length,
272  template<size_t> class CheckingPolicy1, template<size_t> class CheckingPolicy2
273 >
274 SCHNEK_INLINE bool operator!=(
277 );
278 
279 template<
280  class T1, class T2,
281  size_t Length,
282  template<size_t> class CheckingPolicy1, template<size_t> class CheckingPolicy2
283 >
284 SCHNEK_INLINE bool operator<(
287 );
288 
289 template<
290  class T1, class T2,
291  size_t Length,
292  template<size_t> class CheckingPolicy1, template<size_t> class CheckingPolicy2
293 >
294 SCHNEK_INLINE bool operator<=(
297 );
298 
299 
300 #include "array.t"
301 
302 #endif // SCHNEK_ARRAY_HPP_
Array< T, Length, CheckingPolicy > & clear()
Sets all fields to zero.
SCHNEK_INLINE Array< T, Length, CheckingPolicy > & operator+=(const Array< T2, Length, CheckingPolicy2 > &)
Array< T, Length, CheckingPolicy > & fill(const T &)
Fills all fields with a given value.
Definition: array.hpp:55
SCHNEK_INLINE T & at(size_t)
Accessor operator.
SCHNEK_INLINE Array()
The default constructor.
Definition: array.hpp:40
T product() const
Returns the product of all elements.
Definition: algo.hpp:30
Definition: arraycheck.hpp:44
T sum() const
Returns the sum of all elements.
SCHNEK_INLINE T & operator[](size_t)
Accessor operator.
T sqr() const
Returns the sum of squares of all elements.
static Array< T, Length, CheckingPolicy > Ones()
Array< T, destLength, CheckingPolicy > project() const
projects the Array onto an Array of shorter length
SCHNEK_INLINE Array< T, Length, CheckingPolicy > & operator*=(const Array< T2, Length, CheckingPolicy2 > &)
SCHNEK_INLINE Array< T, Length, CheckingPolicy > & operator=(const Array< T2, Length, CheckingPolicy2 > &)
static Array< T, Length, CheckingPolicy > Zero()
SCHNEK_INLINE Array< T, Length, CheckingPolicy > & operator/=(const Array< T2, Length, CheckingPolicy2 > &)
SCHNEK_INLINE Array< T, Length, CheckingPolicy > & operator-=(const Array< T2, Length, CheckingPolicy2 > &)