ug4
fixed_array.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_H__
35 #define __H__UG__COMMON__FIXED_ARRAY_H__
36 
37 #include "storage.h"
38 #include <iostream>
39 #include <cassert>
40 
42 // FixedArray1
43 namespace ug{
44 
54 template<typename T, size_t n>
56 {
57 public:
58  typedef T value_type;
59  typedef size_t size_type;
61 
62 public:
63  FixedArray1();
65  FixedArray1(const FixedArray1<T, n> &other);
66 
67 //protected:
68  // see Alexandrescu: non-virtual destructors should be protected
69  ~FixedArray1();
70 
71 public:
72  // capacity
73  inline size_type
74  size() const;
75 
76  inline size_type
77  capacity() const;
78 
79  inline bool
80  resize(size_type newN, bool bCopyValues=true);
81 
82  inline bool
83  reserve(size_type newN) const;
84 
85  // Element access
86  inline const T &
87  at(size_type i) const
88  {
89  return operator[](i);
90  }
91 
92  inline T &
94  {
95  return operator[](i);
96  }
97 
98  inline const T &
99  operator[](size_type i) const ;
100 
101  inline T &
102  operator[](size_type i) ;
103 
104  // output
105  template<typename _T, size_type _n>
106  friend
107  std::ostream &
108  operator << (std::ostream &out, const FixedArray1<_T, _n> &arr);
109 
110 protected:
111  T values[n];
112 };
113 
114 template<typename T, size_t N>
116 {
117  enum {is_static = true};
118  enum {static_size = N};
119 };
120 
121 
123 // FixedArray2
133 template<typename T, size_t rowsT, size_t colsT, eMatrixOrdering T_ordering=ColMajor>
135 {
136 public:
137  typedef T value_type;
138  typedef size_t size_type;
139  static const eMatrixOrdering ordering = T_ordering;
140  enum { is_static=true};
141  enum { static_num_rows=rowsT};
142  enum { static_num_cols=colsT};
144 
145 public:
146  FixedArray2();
147  FixedArray2(size_type rows, size_type cols);
149 
150 //protected:
151  // see Alexandrescu: non-virtual destructors should be protected
152  ~FixedArray2();
153 
154 public:
155  // capacity
156  inline size_type
157  num_rows() const;
158 
159  inline size_type
160  num_cols() const;
161 
162  inline bool
163  resize(size_type newRows, size_type newCols, bool bCopyValues=true);
164 
165  inline size_type
166  capacity_num_rows() const { return rowsT; }
167 
168  inline size_type
169  capacity_num_cols() const { return colsT; };
170 
171  inline bool
172  empty() const;
173 
174  inline bool
175  reserve(size_type nrRows, size_type nrCols) const
176  {
177  assert(nrRows == rowsT && nrCols == colsT);
178  return nrRows == rowsT && nrCols == colsT;
179  }
180 
181 
182  // Element access
183  inline const T &
184  at(size_type r, size_type c) const
185  {
186  // todo: if(r >= rowsT || c >= colsT) throw
187  return operator()(r, c);
188  }
189 
190  inline T &
192  {
193  // todo: if(r >= rowsT || c >= colsT) throw
194  return operator()(r, c);
195  }
196 
197  inline const T &
198  operator()(size_type r, size_type c) const ;
199 
200  inline T &
202 
203  // output
204  template<typename a, size_type b, size_type c, eMatrixOrdering d>
205  friend
206  std::ostream &
207  operator << (std::ostream &out, const FixedArray2<a, b, c, d> &arr);
208 
209 protected:
210  T values[rowsT*colsT];
211 };
212 
213 
214 }
215 #include "fixed_array_impl.h"
216 // #include "fixed_array_specialization.h"
217 
218 #endif // __H__UG__COMMON__FIXED_ARRAY_H__
Definition: fixed_array.h:56
T value_type
Definition: fixed_array.h:58
bool resize(size_type newN, bool bCopyValues=true)
Definition: fixed_array_impl.h:79
bool reserve(size_type newN) const
Definition: fixed_array_impl.h:88
T & at(size_type i)
Definition: fixed_array.h:93
T values[n]
Definition: fixed_array.h:111
size_type capacity() const
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
static_type storage_type
Definition: fixed_array.h:60
size_t size_type
Definition: fixed_array.h:59
size_type size() const
Definition: fixed_array_impl.h:71
friend std::ostream & operator<<(std::ostream &out, const FixedArray1< _T, _n > &arr)
FixedArray1()
Definition: fixed_array_impl.h:44
~FixedArray1()
Definition: fixed_array_impl.h:63
Definition: fixed_array.h:135
@ static_num_rows
Definition: fixed_array.h:141
FixedArray2()
Definition: fixed_array_impl.h:130
@ is_static
Definition: fixed_array.h:140
size_type num_rows() const
Definition: fixed_array_impl.h:157
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: fixed_array_impl.h:172
friend std::ostream & operator<<(std::ostream &out, const FixedArray2< a, b, c, d > &arr)
static const eMatrixOrdering ordering
Definition: fixed_array.h:139
bool empty() const
~FixedArray2()
Definition: fixed_array_impl.h:149
T value_type
Definition: fixed_array.h:137
const T & at(size_type r, size_type c) const
Definition: fixed_array.h:184
size_t size_type
Definition: fixed_array.h:138
const T & operator()(size_type r, size_type c) const
Definition: fixed_array_impl.h:196
@ static_num_cols
Definition: fixed_array.h:142
static_type storage_type
Definition: fixed_array.h:143
size_type num_cols() const
Definition: fixed_array_impl.h:164
T values[rowsT *colsT]
Definition: fixed_array.h:210
bool reserve(size_type nrRows, size_type nrCols) const
Definition: fixed_array.h:175
size_type capacity_num_cols() const
Definition: fixed_array.h:169
size_type capacity_num_rows() const
Definition: fixed_array.h:166
T & at(size_type r, size_type c)
Definition: fixed_array.h:191
the ug namespace
eMatrixOrdering
Definition: storage.h:47
Definition: storage.h:63
Definition: storage.h:58
@ is_static
Definition: storage.h:59
@ static_size
Definition: storage.h:60