C++ mpi module for stochmagnet_main Package
CORE_Collection.h
1 #ifndef CORE_Collection_H
2 #define CORE_Collection_H
3 
4 //inherited class header
5 #include "CORE_Object.h"
6 
7 //smart pointer
8 #include "shared_pointer.h"
9 
10 //vector header
11 #include <vector>
12 
13 //map header
14 #include <map>
15 
16 //val array header
17 #include <valarray>
18 
19 
20 //array header
21 #include <array>
22 
48 template<typename T, class I>
49 class CORE_Collection : public CORE_Object {
50 
51 
52 private:
53  //attributes
54  //=========
55 
56  //associations
57  //============
58 
59 
60  // CONSTRUCTORS
61  //=============
62 protected:
66 
67  }
68 
69 
70 
71  // DESTRUCTORS
74  virtual ~CORE_Collection() {
75  }
76 
77 
78  //memory method
79  //=============
80 public:
88  virtual tMemSize getMemorySize() const override {
89  return sizeof(*this)+getContentsMemorySize();
90  }
91 
92 
93  //allocation methods
94  //===================
95 public:
96 
97 
98 
104  inline void setSize(const tIndex& n) {
105  static_cast<I*>(this)->setSize(n);
106  };
107 
111  inline tIndex getSize() const {
112  return static_cast<const I*>(this)->getSize();
113  }
114 
117  inline void resize(const tIndex& n) {
118  return static_cast<I*>(this)->resize(n);
119  }
120  //accessor operators
121  //====================
122 public:
126  inline const T& operator[](const tIndex& i) const {
127  return (*static_cast<const I*>(this))[i];
128  };
132  inline T& operator[](const tIndex& i) {
133  return (*static_cast<I*>(this))[i];
134  };
135 
136 
137  //accessor iterator
138  //==================
139 public:
143  inline constexpr auto cbegin() const {
144  return static_cast<const I*>(this)->cbegin();
145  }
149  inline constexpr auto cend() const {
150  return static_cast<const I*>(this)->cend();
151  }
155  inline auto begin() {
156  return static_cast<I*>(this)->begin();
157  }
161  inline auto end() {
162  return static_cast<I*>(this)->end();
163  }
164 
168  inline auto rbegin() {
169  return static_cast<I*>(this)->rbegin();
170  }
174  inline auto rend() {
175  return static_cast<I*>(this)->rend();
176  }
177 
181  inline constexpr auto crbegin() const {
182  return static_cast<const I*>(this)->crbegin();
183  }
187  inline constexpr auto crend() const {
188  return static_cast<const I*>(this)->crend();
189  }
190 
191 
192 
193  //accessor methods
194  //================
195 
196 
197 
198 
199  //assignment operators
200  //====================
201 
202 
203 public:
204 
205 
206 
207  //copy methods
208  //============
209 
210 
211  //Initializers methods
212  //=====================
213 
214 public:
215  //assignement operators (+=,-=,*=,/=,^=...)
216  //=========================================
217 
218 
219  //transformation methods
220  //=======================
221 
225  template<typename LambdaFct>
226  inline void transform(LambdaFct&& F) {
227  static_cast<I*>(this)->transform(F);
228  }
229 
230 
231 
232 
233 
234  //Data consistency methods
235  //========================
236 
240  inline tString getDataTypeName() const {
241  return functions_type::getTypeName<T>();
242  }
243 
244 
245  //algebric methods
246  //================
247 
248  //ordonal methods
249  //===============
250 
251 
252  //string representation
253  //=====================
257  virtual tString toString() const override {
258  std::stringstream cstr;
259  cstr<<CORE_Object::toString()<<":{ ";
260  std::for_each(this->cbegin(),this->cend(),
261  [&cstr](const auto& Vi) {
262  cstr << Vi << ',';
263  });
264  cstr.seekp(-1, std::ios_base::end);
265  cstr<<"}\n";
266  return cstr.str();
267  }
268 
269 };
270 
271 
272 #endif
this class describes a general container of values of type T where implemented class is I
Definition: CORE_Collection.h:49
auto rend()
return reverse end iterator for writing
Definition: CORE_Collection.h:174
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_Collection.h:143
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: CORE_Collection.h:88
auto begin()
return begin iterator for writing
Definition: CORE_Collection.h:155
void transform(LambdaFct &&F)
transform the transform element with the lambda function Ti = F(Ti)
Definition: CORE_Collection.h:226
auto end()
return end iterator for writing
Definition: CORE_Collection.h:161
T & operator[](const tIndex &i)
get the i-th element for writting. Do not verify the bounds
Definition: CORE_Collection.h:132
tString getDataTypeName() const
get the type of data
Definition: CORE_Collection.h:240
CORE_Collection()
build an array of T*
Definition: CORE_Collection.h:65
constexpr auto crend() const
return reverse end iterator for reading
Definition: CORE_Collection.h:187
constexpr auto crbegin() const
return reverse begin iterator for reading
Definition: CORE_Collection.h:181
tIndex getSize() const
return the size of the container
Definition: CORE_Collection.h:111
auto rbegin()
return reverse begin iterator for writing
Definition: CORE_Collection.h:168
virtual tString toString() const override
return the string representation of the object node
Definition: CORE_Collection.h:257
void setSize(const tIndex &n)
set the size of the container
Definition: CORE_Collection.h:104
virtual ~CORE_Collection()
destroy an array of T*
Definition: CORE_Collection.h:74
constexpr auto cend() const
return end iterator for reading
Definition: CORE_Collection.h:149
void resize(const tIndex &n)
modify the size of the array and keep its old values
Definition: CORE_Collection.h:117
const T & operator[](const tIndex &i) const
get the i-th element for reading. Do not verify the bounds
Definition: CORE_Collection.h:126
abstract base class for most classes.
Definition: CORE_Object.h:65
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:333