ug4
variable_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__VARIABLE_ARRAY_H__
35 #define __H__UG__COMMON__VARIABLE_ARRAY_H__
36 
37 #include "storage.h"
38 #include <iostream>
39 #include <cassert>
40 
41 namespace ug{
42 
44 // VariableArray1
57 template<typename T>
59 {
60 public:
61  typedef T value_type;
62  typedef size_t size_type;
64 
65 public:
66  // 'tors
69  VariableArray1(const VariableArray1<T> &other);
70 
71 //protected:
72  // see Alexandrescu: non-virtual destructors should be protected
74 
75 public:
76  // capacity
77  inline size_type
78  size() const;
79 
80  inline size_type
81  capacity() const;
82 
83  inline bool
84  resize(size_type n, bool bCopyValues=true);
85 
86  inline bool
87  reserve(size_type n) const;
88 
89  // Element access
90 
91  inline const T &
92  at (size_type i) const
93  {
94  // todo: throw if(i >= n)
95  return operator[](i);
96  }
97 
98  inline T &
100  {
101  // todo: throw if(i >= n)
102  return operator[](i);
103  }
104 
105  inline const T &
106  operator[](size_type i) const ;
107 
108  inline T &
109  operator[](size_type i) ;
110 
111  // output
112 
113  template<typename _T>
114  friend std::ostream &operator << (std::ostream &out, const VariableArray1<_T> &arr);
115 
116 protected:
117  T *values;
119 };
120 
121 template<typename T>
123 {
124  enum {is_static = false};
125  enum {static_size = 0};
126 };
127 
129 // VariableArray2
137 template<typename T, eMatrixOrdering T_ordering=ColMajor>
139 {
140 public:
141  typedef T value_type;
142  typedef size_t size_type;
143  static const eMatrixOrdering ordering = T_ordering;
144  enum { is_static=false };
145  enum { static_num_rows=0};
146  enum { static_num_cols=0};
148 
149 public:
150  VariableArray2();
151  VariableArray2(size_type rows_, size_type cols_);
153 
154 //protected:
155  // see Alexandrescu: non-virtual destructors should be protected
156  ~VariableArray2();
157 
158 public:
159  // Capacity
160  inline size_type
161  num_rows() const;
162 
163  inline size_type
164  num_cols() const;
165 
166  inline bool
167  resize(size_type newRows, size_type newCols, bool bCopyValues=true);
168 
169  inline size_type
170  capacity_num_rows() const { return rows; }
171 
172  inline size_type
173  capacity_num_cols() const { return cols; };
174 
175  inline void
176  reserve(size_type nrRows, size_type nrCols) const { return; }
177 
178  // Element Access
179 
180  inline const T &
181  at(size_type r, size_type c) const
182  {
183  // todo: if(r >= rows || c >= cols) throw
184  return operator()(r, c);
185  }
186 
187  inline T &
189  {
190  // todo: if(r >= rows || c >= cols) throw
191  return operator()(r, c);
192  }
193 
194  inline const T &
195  operator()(size_type r, size_type c) const ;
196 
197  inline T &
199 
200  // output
201 
202  template<typename _T, eMatrixOrdering _T_Ordering>
203  friend std::ostream &operator << (std::ostream &out, const VariableArray2<_T, _T_Ordering> &arr);
204 
205 protected:
206  T *values;
209 };
210 
211 }
212 
213 #include "variable_array_impl.h"
214 
215 #endif // #define __H__UG__COMMON__VARIABLE_ARRAY_H__
Definition: variable_array.h:59
T * values
Definition: variable_array.h:117
size_type n
Definition: variable_array.h:118
~VariableArray1()
Definition: variable_array_impl.h:74
bool reserve(size_type n) const
Definition: variable_array_impl.h:141
size_t size_type
Definition: variable_array.h:62
friend std::ostream & operator<<(std::ostream &out, const VariableArray1< _T > &arr)
T & at(size_type i)
Definition: variable_array.h:99
size_type size() const
Definition: variable_array_impl.h:85
const T & at(size_type i) const
Definition: variable_array.h:92
T value_type
Definition: variable_array.h:61
VariableArray1()
Definition: variable_array_impl.h:47
const T & operator[](size_type i) const
Definition: variable_array_impl.h:160
variable_type storage_type
Definition: variable_array.h:63
bool resize(size_type n, bool bCopyValues=true)
Definition: variable_array_impl.h:92
size_type capacity() const
Definition: variable_array_impl.h:132
Definition: variable_array.h:139
static const eMatrixOrdering ordering
Definition: variable_array.h:143
T value_type
Definition: variable_array.h:141
T * values
Definition: variable_array.h:206
size_type capacity_num_rows() const
Definition: variable_array.h:170
variable_type storage_type
Definition: variable_array.h:147
void reserve(size_type nrRows, size_type nrCols) const
Definition: variable_array.h:176
VariableArray2()
Definition: variable_array_impl.h:182
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: variable_array_impl.h:237
size_type num_rows() const
Definition: variable_array_impl.h:222
@ is_static
Definition: variable_array.h:144
const T & at(size_type r, size_type c) const
Definition: variable_array.h:181
friend std::ostream & operator<<(std::ostream &out, const VariableArray2< _T, _T_Ordering > &arr)
size_type cols
Definition: variable_array.h:208
size_type rows
Definition: variable_array.h:207
size_type num_cols() const
Definition: variable_array_impl.h:229
const T & operator()(size_type r, size_type c) const
Definition: variable_array_impl.h:299
size_t size_type
Definition: variable_array.h:142
T & at(size_type r, size_type c)
Definition: variable_array.h:188
~VariableArray2()
Definition: variable_array_impl.h:212
@ static_num_rows
Definition: variable_array.h:145
@ static_num_cols
Definition: variable_array.h:146
size_type capacity_num_cols() const
Definition: variable_array.h:173
the ug namespace
eMatrixOrdering
Definition: storage.h:47
Definition: storage.h:58
@ is_static
Definition: storage.h:59
@ static_size
Definition: storage.h:60
Definition: storage.h:64