ug4
pointer_const_array.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
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 #ifndef __H__UG__pointer_const_array__
34 #define __H__UG__pointer_const_array__
35 
36 #include <vector>
37 #include <common/assert.h>
38 #include <common/types.h>
39 
40 namespace ug
41 {
42 
45 
47 
83 template <class TPtr>
85  typedef TPtr const* ConstPtrArray;
86  typedef TPtr* PtrArray;
87 
88  public:
92 
94 
96  inline size_t size() const;
97 
99  inline bool empty() const;
100 
102 
104  inline TPtr const operator[](size_t i) const;
105 
107 
113  void set_external_array(TPtr const* array, size_t size, bool bCopy = false);
114 
116 
118  void reserve(size_t capacity);
119 
121 
124  void clear();
125 
127 
128  void push_back(TPtr p);
129 
130  private:
132 
135 
137  void reserve(size_t capacity, bool copyOldData);
138 
139  private:
142  size_t m_size;
143  size_t m_capacity;
144 };
145 
146 // end group ugbase_common_util
148 
149 }// end of namespace
150 
152 // include implementation
154 
155 #endif
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
void set_external_array(TPtr const *array, size_t size, bool bCopy=false)
set the array on which the container operates.
Definition: pointer_const_array_impl.hpp:128
void clear()
clears the container
Definition: pointer_const_array_impl.hpp:182
PointerConstArray & operator=(const PointerConstArray &pa)
Definition: pointer_const_array_impl.hpp:67
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
void reserve(size_t capacity)
reserves memory but does not alter the size
Definition: pointer_const_array_impl.hpp:152
void push_back(TPtr p)
appends the given pointer at the end of the array.
Definition: pointer_const_array_impl.hpp:189
PtrArray m_data
Definition: pointer_const_array.h:141
TPtr const * ConstPtrArray
Definition: pointer_const_array.h:85
TPtr * PtrArray
Definition: pointer_const_array.h:86
TPtr const operator[](size_t i) const
returns the i-th entry of the array. Make sure that i < size().
Definition: pointer_const_array_impl.hpp:120
PointerConstArray()
Definition: pointer_const_array_impl.hpp:44
bool empty() const
returns true if the associated array is empty
Definition: pointer_const_array_impl.hpp:113
void assign_pointer_const_array(const PointerConstArray &pa)
copies contents from the given PointerConstArray
Definition: pointer_const_array_impl.hpp:82
ConstPtrArray m_array
Definition: pointer_const_array.h:140
size_t m_size
Definition: pointer_const_array.h:142
~PointerConstArray()
Definition: pointer_const_array_impl.hpp:58
size_t m_capacity
Definition: pointer_const_array.h:143
the ug namespace