AFF --- A container for numbers (array) by Friederich and Forbriger.
sharedheap.h
Go to the documentation of this file.
1 
65 // include guard
66 #ifndef AFF_SHAREDHEAP_H_VERSION
67 
68 #define AFF_SHAREDHEAP_H_VERSION \
69  "AFF_SHAREDHEAP_H V1.8"
70 
71 #include<new>
72 #include<aff/lib/error.h>
73 #include<aff/lib/types.h>
74 
75 namespace aff {
76 
77 #ifdef AFF_PREBUILT
78 namespace prebuilt {
79 #endif
80 
81  /*----------------------------------------------------------------------*/
82 
83 namespace util {
84 
101  template<typename T>
102  struct SHeap
103  {
105  SHeap(const Tsize& size);
107  SHeap(T* pointer, const Tsize& size);
108 
110  ~SHeap();
111 
112  T* Mheap;
115  bool Mextern;
116  }; // struct SHeap
117 
118 } // namespace util
119 
120  /*======================================================================*/
121 
138  template <class T>
140  {
141  public:
143  typedef const T Tvalue;
145  typedef const T* Tpointer;
147  typedef const T& Treference;
154 
155  private:
158 
159  public:
161  ConstSharedHeap();
162 
164  ConstSharedHeap(T* pointer, const Tsize& size);
165 
167  ConstSharedHeap(const Tcontainer& sharedheap);
168 
170  ~ConstSharedHeap();
171 
173  ConstSharedHeap<T>& operator=(const Tcontainer& sharedheap);
174 
178  inline
179  const Tsize& size() const
180  { return(Mheapstruct->Msize); }
181 
185  const T* array() const
186  { return(Mheapstruct->Mheap); }
187 
189  inline
190  const T& operator[](const Tsubscript& i) const
191  {
192 #ifdef AFF_INDEXCHECK
193  AFF_assert(((i<Tsubscript(Mheapstruct->Msize)) && (i>=0)),
194  "SharedHeap: illegal index position!");
195 #endif
196  return(Mheapstruct->Mheap[i]);
197  }
198 
199  /*-----------------------------------------------------------------*/
200  /* here starts the PROTECTED section!
201  * ----------------------------------
202  *
203  * These functions are needed by the derived aff::SharedHeap class to
204  * access its base class and the data elements contained therein in a
205  * defined way.
206  */
207  protected:
209  ConstSharedHeap(const Tsize& size);
210 
212  inline
213  T& write_access(const Tsubscript& i) const
214  {
215 #ifdef AFF_INDEXCHECK
216  AFF_assert(((i<Tsubscript(Mheapstruct->Msize)) && (i>=0)),
217  "SharedHeap: illegal index position!");
218 #endif
219  return(Mheapstruct->Mheap[i]);
220  }
221 
226  { return(Mheapstruct->Mheap); }
227 
228  private:
230 
231  }; // class ConstSharedHeap<T>
232 
233  /*======================================================================*/
234 
251  template <class T>
253  {
254  public:
256  typedef T Tvalue;
258  typedef T* Tpointer;
260  typedef T& Treference;
268  typedef Tbase Tcoc;
269 
270  public:
272  SharedHeap(): Tbase() { }
273 
275  SharedHeap(const Tsize& size): Tbase(size) { }
276 
278  SharedHeap(T* pointer, const Tsize& size):
279  Tbase(pointer, size) { }
280 
282  SharedHeap(const Tcontainer& sharedheap):
283  Tbase(sharedheap) { }
284 
287 
289 
290  using Tbase::size;
292  using Tbase::operator[];
293  using Tbase::array;
295 
297  T& operator[](const Tsubscript& i) const
298  { return(this->Tbase::write_access(i)); }
299 
303  T* array() const
304  { return(this->Tbase::writable_array()); }
305 
306  }; // class SharedHeap
307 
308 #ifdef AFF_PREBUILT
309 } // namespace prebuilt
310 #endif
311 
312 } // namespace aff
313 
314 #ifndef AFF_NO_DEFINITIONS
315 #include <aff/lib/sharedheap_def.h>
316 #endif
317 
318 #endif // AFF_SHAREDHEAP_H_VERSION (includeguard)
319 
320 /* ----- END OF sharedheap.h ----- */
Root namespace of library.
Definition: array.h:148
aff::util::SHeap< T > Theapstruct
Type of SHeap struct to be used in any case.
Definition: sharedheap.h:157
some typedefs we refer to
SharedHeap(const Tsize &size)
Allocate new heap memory.
Definition: sharedheap.h:275
bool Mextern
true if memory allocation is handled elsewhere
Definition: sharedheap.h:115
T * Tpointer
Type of pointer to element.
Definition: sharedheap.h:258
SharedHeap(const Tcontainer &sharedheap)
Copy representation to share heap.
Definition: sharedheap.h:282
Tbase Tcontainer_of_const
Type of const version of SharedHeap.
Definition: sharedheap.h:266
const Tsize & size() const
Definition: sharedheap.h:179
aff::ConstSharedHeap< T > Tcontainer
this class
Definition: sharedheap.h:149
Theapstruct * Mheapstruct
shared heap structure
Definition: sharedheap.h:229
T * array() const
Definition: sharedheap.h:303
const T & operator[](const Tsubscript &i) const
Index operator (always inline).
Definition: sharedheap.h:190
A template class to share heap memory for different array projections.
Definition: sharedheap.h:252
Tsize Msize
size (number of elements) of array
Definition: sharedheap.h:113
aff::ConstSharedHeap< T > Tcontainer_of_const
Type of const version of SharedHeap.
Definition: sharedheap.h:151
exceptions and error handling macros (prototypes)
shared heap definitions (prototypes)
T * Mheap
shared raw array on heap
Definition: sharedheap.h:112
const T & Treference
Type of reference to element.
Definition: sharedheap.h:147
#define AFF_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:162
T & Treference
Type of reference to element.
Definition: sharedheap.h:260
aff::ConstSharedHeap< T > Tcoc
short for container of const
Definition: sharedheap.h:153
const T * Tpointer
Type of pointer to element.
Definition: sharedheap.h:145
This is the base class for const elements.
Definition: sharedheap.h:139
const T * array() const
Definition: sharedheap.h:185
T & write_access(const Tsubscript &i) const
write access to data
Definition: sharedheap.h:213
aff::ConstSharedHeap< T > Tbase
base class
Definition: sharedheap.h:264
T & operator[](const Tsubscript &i) const
delegate to base
Definition: sharedheap.h:297
A structure to be shared between different SharedHeap instances.
Definition: sharedheap.h:102
aff::SharedHeap< T > Tcontainer
this class
Definition: sharedheap.h:262
~SharedHeap()
Deallocate heap memory if this is the last referencing instance.
Definition: sharedheap.h:286
SharedHeap(T *pointer, const Tsize &size)
Create representation for externally managed memory.
Definition: sharedheap.h:278
ptrdiff_t Tsubscript
Type to hold an array&#39;s subscript value.
Definition: types.h:53
const T Tvalue
Element type.
Definition: sharedheap.h:143
T Tvalue
Element type.
Definition: sharedheap.h:256
SharedHeap()
Create from nothing.
Definition: sharedheap.h:272
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51
Tsize Mnref
number of referencing instances
Definition: sharedheap.h:114
Tbase Tcoc
short for container of const
Definition: sharedheap.h:268