ug4
fixed_array_specialization.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Martin Rupp
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 
34 #ifndef __H__UG__COMMON__FIXED_ARRAY_SPECIALIZATION_H__
35 #define __H__UG__COMMON__FIXED_ARRAY_SPECIALIZATION_H__
36 
37 namespace ug{
38 
39 template<typename T>
40 class FixedArray1<T, 1>
41 {
42 public:
43  typedef T value_type;
44  typedef size_t size_type;
45  enum {Size = 1 };
46 
47 public:
48  FixedArray1() { values[0] = 0; }
49  FixedArray1(const FixedArray1<T, 1> &other) { values[0] = other.values[0]; }
50 
51  // capacity
52  inline size_type
53  size() const { return Size; }
54 
55  inline bool
56  resize(size_type newN) { assert(newN == Size); return true; }
57 
58  // Element access
59  inline const T &
61  {
62  return at(i);
63  }
64 
65  inline T &
67  {
68  return at(i);
69  }
70 
71  inline const T &
72  at(size_type i) const { assert(i<Size); return values[i]; }
73 
74  inline T &
75  at(size_type i) { assert(i<Size); return values[i]; }
76 
77 
78  union
79  {
80  struct
81  {
83  };
84 
86  };
87 };
88 
89 
90 
91 template<typename T>
92 class FixedArray1<T, 2>
93 {
94 public:
95  typedef T value_type;
96  typedef size_t size_type;
97  enum {Size = 2 };
98 
99 public:
100  FixedArray1() { values[0] = 0.0; values[1] = 0.0; }
101  FixedArray1(const FixedArray1<T, 2> &other) { values[0] = other.values[0]; values[1] = other.values[1]; }
102 
103  // capacity
104  inline size_type
105  size() const { return Size; }
106 
107  inline bool
108  resize(size_type newN) { assert(newN == Size); return true; }
109 
110  // Element access
111  inline const T &
113  {
114  return at(i);
115  }
116 
117  inline T &
119  {
120  return at(i);
121  }
122 
123  inline const T &
124  at(size_type i) const { assert(i<Size); return values[i]; }
125 
126  inline T &
127  at(size_type i) { assert(i<Size); return values[i]; }
128 
129  union
130  {
131  struct
132  {
135  };
136 
138  };
139 };
140 
141 
142 template<typename T>
143 class FixedArray1<T, 3>
144 {
145 public:
146  typedef T value_type;
147  typedef size_t size_type;
148  enum {Size = 3 };
149 
150 public:
151  FixedArray1() { for(int i=0; i<Size; i++) values[i]=0.0; }
152  FixedArray1(const FixedArray1<T, 3> &other) { values[0] = other.values[0]; values[1] = other.values[1]; values[2] = other.values[2]; }
153 
154  // capacity
155  inline size_type
156  size() const { return Size; }
157 
158  inline bool
159  resize(size_type newN) { assert(newN == Size); return true; }
160 
161  // Element access
162  inline const T &
164  {
165  return at(i);
166  }
167 
168  inline T &
170  {
171  return at(i);
172  }
173 
174  inline const T &
175  at(size_type i) const { assert(i<Size); return values[i]; }
176 
177  inline T &
178  at(size_type i) { assert(i<Size); return values[i]; }
179 
180 
181  union
182  {
183  struct
184  {
188  };
189 
191  };
192 };
193 
194 template<typename T>
195 class FixedArray1<T, 4>
196 {
197 public:
198  typedef T value_type;
199  typedef size_t size_type;
200  enum {Size = 4 };
201 
202 public:
203  FixedArray1() { for(int i=0; i<Size; i++) values[i]=0.0; }
204  FixedArray1(const FixedArray1<T, 4> &other) { for(int i=0; i<Size; i++) values[i]=other.values[i]; }
205 
206  // capacity
207  inline size_type
208  size() const { return Size; }
209 
210  inline bool
211  resize(size_type newN) { assert(newN == Size); return true; }
212 
213  // Element access
214  inline const T &
216  {
217  return at(i);
218  }
219 
220  inline T &
222  {
223  return at(i);
224  }
225 
226  inline const T &
227  at(size_type i) const { assert(i<Size); return values[i]; }
228 
229  inline T &
230  at(size_type i) { assert(i<Size); return values[i]; }
231 
232  union
233  {
234  struct
235  {
240  };
241 
243  };
244 };
245 }
246 #endif // __H__UG__COMMON__FIXED_ARRAY_SPECIALIZATION_H__
Definition: fixed_array_specialization.h:41
const T & at(size_type i) const
Definition: fixed_array_specialization.h:72
FixedArray1()
Definition: fixed_array_specialization.h:48
FixedArray1(const FixedArray1< T, 1 > &other)
Definition: fixed_array_specialization.h:49
size_type size() const
Definition: fixed_array_specialization.h:53
size_t size_type
Definition: fixed_array_specialization.h:44
value_type values[1]
Definition: fixed_array_specialization.h:85
bool resize(size_type newN)
Definition: fixed_array_specialization.h:56
T value_type
Definition: fixed_array_specialization.h:43
value_type x
Definition: fixed_array_specialization.h:82
T & at(size_type i)
Definition: fixed_array_specialization.h:75
Definition: fixed_array_specialization.h:93
FixedArray1(const FixedArray1< T, 2 > &other)
Definition: fixed_array_specialization.h:101
T & at(size_type i)
Definition: fixed_array_specialization.h:127
bool resize(size_type newN)
Definition: fixed_array_specialization.h:108
FixedArray1()
Definition: fixed_array_specialization.h:100
size_t size_type
Definition: fixed_array_specialization.h:96
value_type values[2]
Definition: fixed_array_specialization.h:137
size_type size() const
Definition: fixed_array_specialization.h:105
value_type y
Definition: fixed_array_specialization.h:134
T value_type
Definition: fixed_array_specialization.h:95
const T & at(size_type i) const
Definition: fixed_array_specialization.h:124
value_type x
Definition: fixed_array_specialization.h:133
Definition: fixed_array_specialization.h:144
value_type x
Definition: fixed_array_specialization.h:185
value_type values[3]
Definition: fixed_array_specialization.h:190
FixedArray1()
Definition: fixed_array_specialization.h:151
value_type z
Definition: fixed_array_specialization.h:187
T & at(size_type i)
Definition: fixed_array_specialization.h:178
FixedArray1(const FixedArray1< T, 3 > &other)
Definition: fixed_array_specialization.h:152
size_t size_type
Definition: fixed_array_specialization.h:147
bool resize(size_type newN)
Definition: fixed_array_specialization.h:159
value_type y
Definition: fixed_array_specialization.h:186
T value_type
Definition: fixed_array_specialization.h:146
size_type size() const
Definition: fixed_array_specialization.h:156
const T & at(size_type i) const
Definition: fixed_array_specialization.h:175
Definition: fixed_array_specialization.h:196
value_type z
Definition: fixed_array_specialization.h:238
value_type y
Definition: fixed_array_specialization.h:237
FixedArray1()
Definition: fixed_array_specialization.h:203
value_type x
Definition: fixed_array_specialization.h:236
value_type values[4]
Definition: fixed_array_specialization.h:242
FixedArray1(const FixedArray1< T, 4 > &other)
Definition: fixed_array_specialization.h:204
value_type w
Definition: fixed_array_specialization.h:239
T & at(size_type i)
Definition: fixed_array_specialization.h:230
bool resize(size_type newN)
Definition: fixed_array_specialization.h:211
T value_type
Definition: fixed_array_specialization.h:198
const T & at(size_type i) const
Definition: fixed_array_specialization.h:227
size_t size_type
Definition: fixed_array_specialization.h:199
size_type size() const
Definition: fixed_array_specialization.h:208
Definition: fixed_array.h:56
T values[n]
Definition: fixed_array.h:111
const T & operator[](size_type i) const
Definition: fixed_array_impl.h:106
const T & at(size_type i) const
Definition: fixed_array.h:87
size_t size_type
Definition: fixed_array.h:59
the ug namespace