Ocean
Accessor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_ACCESSOR_H
9 #define META_OCEAN_BASE_ACCESSOR_H
10 
11 #include "ocean/base/Base.h"
12 #include "ocean/base/Callback.h"
13 
14 namespace Ocean
15 {
16 
17 /**
18  * This class implements a base class for all accessors.
19  * Accessors provide access to any kind of data elements which are stored in any kind of data structure by any kind of access method.<br>
20  * @ingroup base
21  */
22 class Accessor
23 {
24  public:
25 
26  /**
27  * Default destructor
28  */
29  virtual ~Accessor() = default;
30 
31  /**
32  * Returns the number of accessible elements of this accessor object.
33  * @return The number of elements
34  */
35  virtual size_t size() const = 0;
36 
37  /**
38  * Returns whether this accessor provides no elements.
39  * @return True, if so
40  */
41  inline bool isEmpty() const;
42 
43  /**
44  * Returns all elements of a given accessor (as a block).
45  * @param accessor The accessor from which all elements are extracted
46  * @return The elements as a block
47  */
48  template <typename TAccessor>
49  static std::vector<typename TAccessor::Type> accessor2elements(const TAccessor& accessor);
50 
51  /**
52  * Returns all elements of a given accessor as a map with key and elements.
53  * @param accessor The accessor from which all elements are extracted
54  * @return The elements as a map
55  */
56  template <typename TAccessor>
57  static std::unordered_map<typename TAccessor::KeyType, typename TAccessor::Type> accessor2map(const TAccessor& accessor);
58 
59  /**
60  * Returns a subset of all elements of a given accessor (as a block).
61  * @param accessor The accessor from which all sub elements are extracted.
62  * @param subset The individual indices of the subset's elements
63  * @return Subset elements as a block
64  */
65  template <typename TAccessor, typename TIndex>
66  static std::vector<typename TAccessor::Type> accessor2subsetElements(const TAccessor& accessor, const std::vector<TIndex>& subset);
67 
68  protected:
69 
70  /**
71  * Protected default constructor.
72  */
73  Accessor() = default;
74 
75  /**
76  * Protected copy constructor.
77  * @param accessor Accessor to copy
78  */
79  Accessor(const Accessor& accessor) = default;
80 
81  /**
82  * Deleted assign operator.
83  * @param accessor Accessor which would be assigned
84  * @return Reference to this object
85  */
86  Accessor& operator=(const Accessor& accessor) = delete;
87 };
88 
89 /**
90  * This class implements a base class for accessors allowing a constant reference access.
91  * @tparam T The data type of the elements of the accessor
92  * @tparam TKey The data type of the keys of the accessor
93  * @ingroup base
94  */
95 template <typename T, typename TKey>
96 class ConstAccessor : public Accessor
97 {
98  public:
99 
100  /**
101  * Definition of the element type of this accessor.
102  */
103  typedef T Type;
104 
105  /**
106  * Definition of the key (or e.g., index) type of this accessor.
107  */
108  typedef TKey KeyType;
109 
110  public:
111 
112  /**
113  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
114  * Beware: There is not guarantee that the data of an accessor is stored as one memory block, thus be prepared that the resulting pointer is nullptr.
115  * @return The pointer to the memory block of this accessor, if available
116  */
117  virtual const T* data() const;
118 
119  /**
120  * Returns whether this accessor has a specific element.
121  * @param key The key of the element to be checked
122  * @return True, if the element exists
123  */
124  virtual bool canAccess(const TKey& key) const = 0;
125 
126  /**
127  * Returns the first element of this accessor.
128  * @param element The resulting first element by copying the element (by using the assign operator)
129  * @param key The resulting key of the first element
130  * @return True, if at least one element exists
131  */
132  virtual bool firstElement(T& element, TKey& key) const = 0;
133 
134  /**
135  * Returns the next element which follows a given key of the previous element.
136  * @param previousKey The previous key for which the next following element is requested
137  * @param nextElement The resulting next element by copying the element (by using the assign operator)
138  * @param nextKey The resulting key of the next element
139  * @return True, if a next element exists
140  */
141  virtual bool nextElement(const TKey& previousKey, T& nextElement, TKey& nextKey) const = 0;
142 
143  /**
144  * Returns one element of this accessor object by a given key.
145  * @param key The key of element to be accessed, must be valid
146  * @return The requested element
147  */
148  virtual const T& operator[](const TKey& key) const = 0;
149 
150  protected:
151 
152  /**
153  * Protected default constructor.
154  */
155  ConstAccessor() = default;
156 };
157 
158 /**
159  * This class implements a base class for accessors allowing a non-constant reference access.
160  * @tparam T The data type of the elements of the accessor
161  * @tparam TKey The data type of the keys of the accessor
162  * @ingroup base
163  */
164 template <typename T, typename TKey>
165 class NonconstAccessor : public ConstAccessor<T, TKey>
166 {
167  // we want to keep the const data function from the base class
169 
170  public:
171 
172  /**
173  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
174  * Beware: There is not guarantee that the data of an accessor is stored as one memory block, thus be prepared that the resulting pointer is nullptr.
175  * @return The pointer to the memory block of this accessor, if available
176  */
177  virtual T* data();
178 
179  /**
180  * Returns one element of this accessor object by a given key.
181  * @param key The key of element to be accessed, must be valid
182  * @return The requested element
183  */
184  virtual T& operator[](const TKey& key) = 0;
185 
186  protected:
187 
188  /**
189  * Creates a new indexed-based accessor object.
190  */
191  NonconstAccessor() = default;
192 };
193 
194 /**
195  * This class implements a base class for all accessors allowing to access temporary elements.
196  * @tparam T The data type of the elements of the accessor
197  * @tparam TKey The data type of the keys of the accessor
198  * @ingroup base
199  */
200 template <typename T, typename TKey>
202 {
203  public:
204 
205  /**
206  * Definition of the element type of this accessor.
207  */
208  typedef T Type;
209 
210  public:
211 
212  /**
213  * Returns one element of this accessor object by a given index.
214  * @param key The key of element to be accessed, must be valid
215  * @return The requested element
216  */
217  virtual T operator[](const TKey& key) const = 0;
218 
219  /**
220  * Returns whether this accessor has a specific element.
221  * @param key The key of the element to be checked
222  * @return True, if the element exists
223  */
224  virtual bool canAccess(const TKey& key) const = 0;
225 
226  protected:
227 
228  /**
229  * Creates a new indexed-based accessor object.
230  */
231  TemporaryAccessor() = default;
232 };
233 
234 /**
235  * This class implements a base class for all indexed-based accessors allowing a constant reference access only.
236  * @tparam T The data type of the elements of the accessor
237  * @ingroup base
238  */
239 template <typename T>
240 class ConstIndexedAccessor : public ConstAccessor<T, size_t>
241 {
242  public:
243 
244  /**
245  * Returns whether this accessor has a specific element.
246  * @see ConstAccessor::canAccess().
247  */
248  virtual bool canAccess(const size_t& index) const;
249 
250  /**
251  * Returns the first element of this accessor.
252  * @see ConstAccessor:firstElement().
253  */
254  virtual bool firstElement(T& element, size_t& index) const;
255 
256  /**
257  * Returns the next element which follows a given key of the previous element.
258  * @see ConstAccessor::nextElement().
259  */
260  virtual bool nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const;
261 
262  /**
263  * Returns one element of this accessor object by a given index.
264  * @param index The index of element to be accessed, with range [0, size())
265  * @return The requested element
266  */
267  virtual const T& operator[](const size_t& index) const = 0;
268 
269  protected:
270 
271  /**
272  * Creates a new indexed-based accessor object.
273  */
274  ConstIndexedAccessor() = default;
275 };
276 
277 /**
278  * This class implements a base class for all indexed-based accessors allowing a non-constant reference access.
279  * @tparam T The data type of the elements of the accessor
280  * @ingroup base
281  */
282 template <typename T>
283 class NonconstIndexedAccessor : public NonconstAccessor<T, size_t>
284 {
285  public:
286 
287  /**
288  * Returns whether this accessor has a specific element.
289  * @see ConstAccessor::canAccess().
290  */
291  virtual bool canAccess(const size_t& index) const;
292 
293  /**
294  * Returns the first element of this accessor.
295  * @see ConstAccessor:firstElement().
296  */
297  virtual bool firstElement(T& element, size_t& index) const;
298 
299  /**
300  * Returns the next element which follows a given key of the previous element.
301  * @see ConstAccessor::nextElement().
302  */
303  virtual bool nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const;
304 
305  /**
306  * Returns the pointer to this object if this accessor holds at least one element (if this accessor is not empty).
307  * This function can be used to simplify code fragments in which an optional pointer to a non-const accessor is used depending on the factor whether the accessor holds elements or not.
308  * @return The accessor's pointer, otherwise nullptr
309  */
311 
312  /**
313  * Returns one element of this accessor object by a given key.
314  * @param index The index of element to be accessed, with range [0, size())
315  * @return The requested element
316  */
317  virtual const T& operator[](const size_t& index) const = 0;
318 
319  /**
320  * Returns one element of this accessor object by a given index.
321  * @param index The index of element to be accessed, with range [0, size())
322  * @return The requested element
323  */
324  virtual T& operator[](const size_t& index) = 0;
325 
326  protected:
327 
328  /**
329  * Creates a new accessor object.
330  */
332 };
333 
334 /**
335  * This class implements a base class for all indexed-based accessors allowing to access temporary elements.
336  * @tparam T The data type of the elements of the accessor
337  * @ingroup base
338  */
339 template <typename T>
341 {
342  public:
343 
344  /**
345  * Returns one element of this accessor object by a given index.
346  * @param index The index of element to be accessed, with range [0, size())
347  * @return The requested element
348  */
349  virtual T operator[](const size_t& index) const = 0;
350 
351  /**
352  * Returns whether this accessor has a specific element.
353  * @param index The index of the element to be checked
354  * @return True, if the element exists
355  */
356  virtual bool canAccess(const size_t& index) const;
357 
358  protected:
359 
360  /**
361  * Creates a new indexed-based accessor object.
362  */
364 };
365 
366 /**
367  * This class implements an accessor providing direct access to a constant array of elements.
368  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
369  *
370  * The application of the this class is demonstrated in the following code example (compare the code example for ConstTemplateArrayAccessor):
371  * @code
372  * // the parameter type is a base class of ConstArrayAccessor<Object> allowing a more flexible application of this function
373  * void iterate(const ConstIndexedAccessor<Object>& accessor)
374  * {
375  * for (size_t n = 0; n < accessor.size(); ++n)
376  * {
377  * // access the object by application of the !virtual! index operator
378  * const Object& object = accessor[n];
379  *
380  * // ... do something with the object ...
381  * }
382  * }
383  *
384  * void main()
385  * {
386  * std::vector<Object> objects;
387  *
388  * // ... add some objects ...
389  *
390  * // iterate over all objects
391  * iterate(ConstArrayAccessor<Object>(objects));
392  * }
393  * @endcode
394  * @tparam T The data type of the elements of the accessor
395  * @see ConstTemplateArrayAccessor, ConstElementAccessor.
396  * @ingroup base
397  */
398 template <typename T>
400 {
401  public:
402 
403  /**
404  * Creates a new empty accessor.
405  */
406  ConstArrayAccessor() = default;
407 
408  /**
409  * Move constructor.
410  * @param accessor Accessor to be moved
411  */
412  inline ConstArrayAccessor(ConstArrayAccessor<T>&& accessor) noexcept;
413 
414  /**
415  * Creates a new accessor object.
416  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
417  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
418  * @param size The number of elements that can be accessed, may be 0 if elements is nullptr
419  */
420  inline ConstArrayAccessor(const T* elements, const size_t size);
421 
422  /**
423  * Creates a new accessor object.
424  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
425  * @param elements A vector holding all elements
426  */
427  explicit inline ConstArrayAccessor(const std::vector<T>& elements);
428 
429  /**
430  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
431  * @see ConstAccessor::size().
432  */
433  virtual const T* data() const;
434 
435  /**
436  * Returns the number of accessible elements of this accessor object.
437  * @see ConstAccessor::size().
438  */
439  virtual size_t size() const;
440 
441  /**
442  * Returns one element of this accessor object.
443  * @see ConstAccessor::operator[].
444  */
445  virtual const T& operator[](const size_t& index) const;
446 
447  /**
448  * Move operator.
449  * @param accessor Accessor to be moved
450  * @return Reference to this accessor
451  */
452  inline ConstArrayAccessor<T>& operator=(ConstArrayAccessor<T>&& accessor) noexcept;
453 
454  protected:
455 
456  /// The elements of this accessor.
457  const T* elements_ = nullptr;
458 
459  /// The number of elements that can be accessed.
460  size_t size_ = 0;
461 };
462 
463 /**
464  * This class implements an accessor providing direct access to std::shared_ptr<T> elements returned as const T* pointers.
465  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
466  * This class is mainly a helper class to avoid extracting pointer from a shared_ptr objects and using a normal `ConstArrayAccessor`.
467  *
468  * The application of the this class is demonstrated in the following code example:
469  * @code
470  * void iterate(const ConstIndexedAccessor<const Object*>& accessor)
471  * {
472  * for (size_t n = 0; n < accessor.size(); ++n)
473  * {
474  * // access the object by application of the !virtual! index operator
475  * const Object* object = accessor[n];
476  *
477  * // ... do something with the object ...
478  * }
479  * }
480  *
481  * void main()
482  * {
483  * std::vector<std::shared_ptr<Object>> objects;
484  *
485  * // ... add some objects ...
486  *
487  * // iterate over all objects
488  * iterate(SharedPointerConstArrayAccessor<Object>(objects));
489  * }
490  * @endcode
491  * @tparam T The data type of the shared_ptr's element_type
492  * @see ConstArrayAccessor.
493  * @ingroup base
494  */
495 template <typename T>
497 {
498  public:
499 
500  /**
501  * Definition of the shared pointer object.
502  */
503  using SharedPointer = std::shared_ptr<T>;
504 
505  /**
506  * Definition of a vector holding the shared pointer objects.
507  */
508  using SharedPointers = std::vector<SharedPointer>;
509 
510  public:
511 
512  /**
513  * Creates a new empty accessor.
514  */
516 
517  /**
518  * Move constructor.
519  * @param accessor Accessor to be moved
520  */
522 
523  /**
524  * Creates a new accessor object.
525  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
526  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
527  * @param size The number of elements that can be accessed, may be 0 if elements is nullptr
528  */
529  inline SharedPointerConstArrayAccessor(const SharedPointer* elements, const size_t size);
530 
531  /**
532  * Creates a new accessor object.
533  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
534  * @param elements A vector holding all elements
535  */
536  explicit inline SharedPointerConstArrayAccessor(const SharedPointers& elements);
537 
538  /**
539  * Returns the number of accessible elements of this accessor object.
540  * @see ConstAccessor::size().
541  */
542  virtual size_t size() const;
543 
544  /**
545  * Returns one element of this accessor object.
546  * @see ConstAccessor::operator[].
547  */
548  virtual const T* const & operator[](const size_t& index) const;
549 
550  /**
551  * Move operator.
552  * @param accessor Accessor to be moved
553  * @return Reference to this accessor
554  */
556 
557  protected:
558 
559  /// The pointers to the actual elements wrapped in the shared pointers.
560  std::vector<const T*> elements_;
561 };
562 
563 /**
564  * This class implements an accessor providing direct access to a constant array of elements.
565  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
566  * This class is not derived from Accessor (or any other Accessor class) to avoid virtual functions ensuring higher element-access performances.<br>
567  * Thus, this class will mainly be applied in template functions where the type of the accessor is defined at compile time.
568  *
569  * The application of the this class is demonstrated in the following code example (compare the code example for ConstArrayAccessor):
570  * @code
571  * // the parameter type is a template type allowing for fast but not flexible application of this function
572  * template <typename TAccessor>
573  * void iterate(const TAccessor& accessor)
574  * {
575  * for (size_t n = 0; n < accessor.size(); ++n)
576  * {
577  * // access the object by application of the !inlined! index operator
578  * const Object& object = accessor[n];
579  *
580  * // ... do something with the object ...
581  * }
582  * }
583  *
584  * void main()
585  * {
586  * std::vector<Object> objects;
587  *
588  * // ... add some objects ...
589  *
590  * // iterate over all objects
591  * iterate(ConstTemplateArrayAccessor<Object>(objects));
592  * }
593  * @endcode
594  * @tparam T The data type of the elements of the accessor
595  * @see ConstArrayAccessor, NonconstTemplateArrayAccessor.
596  * @ingroup base
597  */
598 template <typename T>
600 {
601  public:
602 
603  /**
604  * Definition of the element type of this accessor.
605  */
606  typedef T Type;
607 
608  /**
609  * Definition of the key (or e.g., index) type of this accessor.
610  */
611  typedef size_t KeyType;
612 
613  public:
614 
615  /**
616  * Creates a new empty accessor.
617  */
619 
620  /**
621  * Move constructor.
622  * @param accessor Accessor to be moved
623  */
624  inline ConstTemplateArrayAccessor(ConstTemplateArrayAccessor<T>&& accessor) noexcept;
625 
626  /**
627  * Creates a new accessor object.
628  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
629  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
630  * @param size The number of elements that can be accessed, may be 0 if elements is nullptr
631  */
632  inline ConstTemplateArrayAccessor(const T* elements, const size_t size);
633 
634  /**
635  * Creates a new accessor object.
636  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
637  * @param elements A vector holding all elements
638  */
639  explicit inline ConstTemplateArrayAccessor(const std::vector<T>& elements);
640 
641  /**
642  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
643  * @see ConstAccessor::data().
644  */
645  inline const T* data() const;
646 
647  /**
648  * Returns the number of accessible elements of this accessor object.
649  * @see ConstAccessor::size().
650  */
651  inline size_t size() const;
652 
653  /**
654  * Returns whether this accessor provides no elements.
655  * @see Accessor::isEmpty().
656  */
657  inline bool isEmpty() const;
658 
659  /**
660  * Returns whether this accessor has a specific element.
661  * @see ConstAccessor::canAccess().
662  */
663  inline bool canAccess(const size_t& index) const;
664 
665  /**
666  * Returns the first element of this accessor.
667  * @see ConstAccessor:firstElement().
668  */
669  inline bool firstElement(T& element, size_t& index) const;
670 
671  /**
672  * Returns the next element which follows a given key of the previous element.
673  * @see ConstAccessor::nextElement().
674  */
675  inline bool nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const;
676 
677  /**
678  * Returns one element of this accessor object.
679  * @see ConstAccessor::operator[].
680  */
681  inline const T& operator[](const size_t& index) const;
682 
683  /**
684  * Move operator.
685  * @param accessor Accessor to be moved
686  * @return Reference to this accessor
687  */
689 
690  protected:
691 
692  /// The elements of this accessor.
693  const T* elements_ = nullptr;
694 
695  /// The number of elements that can be accessed.
696  size_t size_ = 0;
697 };
698 
699 /**
700  * This class implements an accessor providing direct access to an array of elements.
701  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
702  * @tparam T The data type of the elements of the accessor
703  * @ingroup base
704  */
705 template <typename T>
707 {
708  public:
709 
710  /**
711  * Creates a new empty accessor.
712  */
714 
715  /**
716  * Move constructor.
717  * @param accessor Accessor to be moved
718  */
719  inline NonconstArrayAccessor(NonconstArrayAccessor<T>&& accessor) noexcept;
720 
721  /**
722  * Creates a new accessor object.
723  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
724  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
725  * @param size The number of elements that can be accessed, may be 0 if elements is nullptr
726  */
727  inline NonconstArrayAccessor(T* elements, const size_t size);
728 
729  /**
730  * Creates a new accessor object.
731  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
732  * @param elements A vector holding all elements
733  */
734  explicit inline NonconstArrayAccessor(std::vector<T>& elements);
735 
736  /**
737  * Creates a new accessor object.
738  * This constructor simplifies the creation of an optional NonconstArrayAccessor object by allowing to provide an empty vector object while defining an explicit resize value.<br>
739  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
740  * @param elements A vector holding all elements
741  * @param resizeSize An explicit resize value that will invoke a resizing of the given vector before the vector is connected with the accessor, with range [1, infinity), 0 to avoid any resizing
742  */
743  inline NonconstArrayAccessor(std::vector<T>& elements, const size_t resizeSize);
744 
745  /**
746  * Creates a new accessor object.
747  * This constructor simplifies the creation of an optional NonconstArrayAccessor object.<br>
748  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
749  * @param elements An optional vector holding all elements, nullptr to create an empty invalid accessor
750  * @param resizeSize An optional possibility to resize the provided elements vector (if defined - otherwise nothing happens), with range [1, infinity), 0 to avoid any resizing
751  */
752  explicit inline NonconstArrayAccessor(std::vector<T>* elements, const size_t resizeSize = 0);
753 
754  /**
755  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
756  * @see NonconstAccessor::data().
757  */
758  virtual T* data();
759 
760  /**
761  * Returns the number of accessible elements of this accessor object.
762  * @see ConstAccessor::size().
763  */
764  virtual size_t size() const;
765 
766  /**
767  * Returns one element of this accessor object.
768  * @see ConstAccessor::operator[].
769  */
770  virtual const T& operator[](const size_t& index) const;
771 
772  /**
773  * Returns one element of this accessor object.
774  * @see ConstAccessor::operator[].
775  */
776  virtual T& operator[](const size_t& index);
777 
778  /**
779  * Move operator.
780  * @param accessor Accessor to be moved
781  * @return Reference to this accessor
782  */
783  inline NonconstArrayAccessor<T>& operator=(NonconstArrayAccessor<T>&& accessor) noexcept;
784 
785  protected:
786 
787  /// The elements of this accessor.
788  T* elements_ = nullptr;
789 
790  /// The number of elements that can be accessed.
791  size_t size_ = 0;
792 };
793 
794 /**
795  * This class implements an accessor providing direct access to an array of elements.
796  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
797  * This class is not derived from Accessor (or any other Accessor class) to avoid virtual functions ensuring higher element-access performances.<br>
798  * Thus, this class will mainly be applied in template functions where the type of the accessor is defined at compile time.
799  * @tparam T The data type of the elements of the accessor
800  * @see NonconstArrayAccessor, ConstTemplateArrayAccessor.
801  * @ingroup base
802  */
803 template <typename T>
805 {
806  public:
807 
808  /**
809  * Definition of the element type of this accessor.
810  */
811  typedef T Type;
812 
813  /**
814  * Definition of the key (or e.g., index) type of this accessor.
815  */
816  typedef size_t KeyType;
817 
818  public:
819 
820  /**
821  * Creates a new empty accessor.
822  */
824 
825  /**
826  * Move constructor.
827  * @param accessor Accessor to be moved
828  */
830 
831  /**
832  * Creates a new accessor object.
833  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
834  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
835  * @param size The number of elements that can be accessed, may be 0 if elements is nullptr
836  */
837  inline NonconstTemplateArrayAccessor(T* elements, const size_t size);
838 
839  /**
840  * Creates a new accessor object.
841  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
842  * @param elements A vector holding all elements
843  */
844  explicit inline NonconstTemplateArrayAccessor(std::vector<T>& elements);
845 
846  /**
847  * Creates a new accessor object.
848  * This constructor simplifies the creation of an optional NonconstTemplateArrayAccessor object by allowing to provide an empty vector object while defining an explicit resize value.<br>
849  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
850  * @param elements A vector holding all elements
851  * @param resizeSize An explicit resize value that will invoke a resizing of the given vector before the vector is connected with the accessor, with range [1, infinity), 0 to avoid any resizing
852  */
853  inline NonconstTemplateArrayAccessor(std::vector<T>& elements, const size_t resizeSize);
854 
855  /**
856  * Creates a new accessor object.
857  * This constructor simplifies the creation of an optional NonconstTemplateArrayAccessor object.<br>
858  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
859  * @param elements An optional vector holding all elements, nullptr to create an empty invalid accessor
860  * @param resizeSize An optional possibility to resize the provided elements vector (if defined - otherwise nothing happens), with range [1, infinity), 0 to avoid any resizing
861  */
862  explicit inline NonconstTemplateArrayAccessor(std::vector<T>* elements, const size_t resizeSize = 0);
863 
864  /**
865  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
866  * @see ConstAccessor::data().
867  */
868  inline const T* data() const;
869 
870  /**
871  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
872  * @see NonconstAccessor::data().
873  */
874  inline T* data();
875 
876  /**
877  * Returns the number of accessible elements of this accessor object.
878  * @see NonconstAccessor::size().
879  */
880  inline size_t size() const;
881 
882  /**
883  * Returns whether this accessor provides no elements.
884  * @see NonconstAccessor::isEmpty().
885  */
886  inline bool isEmpty() const;
887 
888  /**
889  * Returns whether this accessor has a specific element.
890  * @see NonconstAccessor::canAccess().
891  */
892  inline bool canAccess(const size_t& index) const;
893 
894  /**
895  * Returns the first element of this accessor.
896  * @see ConstAccessor:firstElement().
897  */
898  inline bool firstElement(T& element, size_t& index) const;
899 
900  /**
901  * Returns the next element which follows a given key of the previous element.
902  * @see ConstAccessor::nextElement().
903  */
904  inline bool nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const;
905 
906  /**
907  * Returns one element of this accessor object.
908  * @see ConstAccessor::operator[].
909  */
910  inline const T& operator[](const size_t& index) const;
911 
912  /**
913  * Returns one element of this accessor object.
914  * @see NonconstAccessor::operator[].
915  */
916  inline T& operator[](const size_t& index);
917 
918  /**
919  * Move operator.
920  * @param accessor Accessor to be moved
921  * @return Reference to this accessor
922  */
924 
925  protected:
926 
927  /// The elements of this accessor.
928  T* elements_ = nullptr;
929 
930  /// The number of elements that can be accessed.
931  size_t size_ = 0;
932 };
933 
934 /**
935  * This class implements an accessor providing direct access to a constant array of elements while all elements are identical (all elements point to one unique object).
936  * This accessor can be used to simulate a large array with several identical entries.
937  * @see ConstArrayAccessor.
938  * @ingroup base
939  */
940 template <typename T>
942 {
943  public:
944 
945  /**
946  * Creates a new empty accessor.
947  */
948  ConstElementAccessor() = default;
949 
950  /**
951  * Move constructor.
952  * @param accessor Accessor to be moved
953  */
954  inline ConstElementAccessor(ConstElementAccessor<T>&& accessor) noexcept;
955 
956  /**
957  * Creates a new accessor object.
958  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.
959  * @param size The number of elements that can be accessed, with range [1, infinity)
960  * @param element The element that can be accessed though any index
961  */
962  inline ConstElementAccessor(const size_t size, const T& element);
963 
964  /**
965  * Returns the number of accessible elements of this accessor object.
966  * @see ConstAccessor::size().
967  */
968  virtual size_t size() const;
969 
970  /**
971  * Returns one element of this accessor object.
972  * @see ConstAccessor::operator[].
973  */
974  virtual const T& operator[](const size_t& index) const;
975 
976  /**
977  * Move operator.
978  * @param accessor Accessor to be moved
979  * @return Reference to this accessor
980  */
981  inline ConstElementAccessor<T>& operator=(ConstElementAccessor<T>&& accessor) noexcept;
982 
983  protected:
984 
985  /// The element of this accessor.
986  const T* element_ = nullptr;
987 
988  /// The number of elements that can be accessed.
989  size_t size_ = 0;
990 };
991 
992 /**
993  * This class implements an accessor providing direct access to a constant (unordered) map of elements.
994  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
995  * @tparam T The data type of the elements of the accessor
996  * @tparam TKey The data type of the keys of the accessor
997  * @ingroup base
998  */
999 template <typename T, typename TKey>
1000 class ConstMapAccessor : public ConstAccessor<T, TKey>
1001 {
1002  public:
1003 
1004  /**
1005  * Creates a new empty accessor.
1006  */
1007  ConstMapAccessor() = default;
1008 
1009  /**
1010  * Move constructor.
1011  * @param accessor Accessor to be moved
1012  */
1013  inline ConstMapAccessor(ConstMapAccessor<T, TKey>&& accessor) noexcept;
1014 
1015  /**
1016  * Creates a new accessor object.
1017  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1018  * @param elements A map holding all elements
1019  */
1020  explicit inline ConstMapAccessor(const std::unordered_map<TKey, T>& elements);
1021 
1022  /**
1023  * Returns the number of accessible elements of this accessor object.
1024  * @see ConstAccessor::size().
1025  */
1026  virtual size_t size() const;
1027 
1028  /**
1029  * Returns whether this accessor has a specific element.
1030  * @see ConstAccessor::canAccess().
1031  */
1032  virtual bool canAccess(const TKey& key) const;
1033 
1034  /**
1035  * Returns the first element of this accessor.
1036  * @see ConstAccessor::firstElement().
1037  */
1038  virtual bool firstElement(T& element, TKey& key) const;
1039 
1040  /**
1041  * Returns the next element which follows a given key of the previous element.
1042  * @see ConstAccessor::nextElement().
1043  */
1044  virtual bool nextElement(const TKey& previousKey, T& nextElement, TKey& nextKey) const;
1045 
1046  /**
1047  * Returns one element of this accessor object.
1048  * @see ConstAccessor::operator[].
1049  */
1050  virtual const T& operator[](const TKey& key) const;
1051 
1052  /**
1053  * Move operator.
1054  * @param accessor Accessor to be moved
1055  * @return Reference to this accessor
1056  */
1057  inline ConstMapAccessor<T, TKey>& operator=(ConstMapAccessor<T, TKey>&& accessor) noexcept;
1058 
1059  protected:
1060 
1061  /// The elements of this accessor.
1062  const std::unordered_map<TKey, T>* elementMap_ = nullptr;
1063 };
1064 
1065 /**
1066  * This class implements an accessor providing direct access to an (unordered) map of elements.
1067  * An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
1068  * @tparam T The data type of the elements of the accessor
1069  * @tparam TKey The data type of the keys of the accessor
1070  * @ingroup base
1071  */
1072 template <typename T, typename TKey>
1073 class NonconstMapAccessor : public NonconstAccessor<T, TKey>
1074 {
1075  public:
1076 
1077  /**
1078  * Creates a new empty accessor.
1079  */
1080  NonconstMapAccessor() = default;
1081 
1082  /**
1083  * Creates a new accessor object.
1084  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1085  * @param elements A map holding all elements
1086  */
1087  explicit inline NonconstMapAccessor(std::unordered_map<TKey, T>& elements);
1088 
1089  /**
1090  * Returns the number of accessible elements of this accessor object.
1091  * @see ConstAccessor::size().
1092  */
1093  virtual size_t size() const;
1094 
1095  /**
1096  * Returns whether this accessor has a specific element.
1097  * @see ConstAccessor::canAccess().
1098  */
1099  virtual bool canAccess(const TKey& key) const;
1100 
1101  /**
1102  * Returns the first element of this accessor.
1103  * @see ConstAccessor::firstElement().
1104  */
1105  virtual bool firstElement(T& element, TKey& key) const;
1106 
1107  /**
1108  * Returns the next element which follows a given key of the previous element.
1109  * @see ConstAccessor::nextElement().
1110  */
1111  virtual bool nextElement(const TKey& previousKey, T& nextElement, TKey& nextKey) const;
1112 
1113  /**
1114  * Returns one element of this accessor object.
1115  * @see ConstAccessor::operator[].
1116  */
1117  virtual const T& operator[](const TKey& key) const;
1118 
1119  /**
1120  * Returns one element of this accessor object.
1121  * @see ConstAccessor::operator[].
1122  */
1123  virtual T& operator[](const TKey& key);
1124 
1125  protected:
1126 
1127  /// The elements of this accessor.
1128  std::unordered_map<TKey, T>* elementMap_ = nullptr;
1129 };
1130 
1131 /**
1132  * This class implements an indexed-based constant accessor providing access to a subset of elements stored in an array.
1133  * The subset is defined by a set of indices defining also the order of the accessible elements.<br>
1134  * An instance of this accessor does not copy the elements or the subset indices, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
1135  * @tparam T The data type of the elements of the accessor
1136  * @tparam TIndex The data type of the indices defining the subset of elements
1137  * @ingroup base
1138  */
1139 template <typename T, typename TIndex>
1141 {
1142  public:
1143 
1144  /**
1145  * Definition of the data type of the indices.
1146  */
1147  typedef TIndex IndexType;
1148 
1149  public:
1150 
1151  /**
1152  * Creates a new empty accessor.
1153  */
1155 
1156  /**
1157  * Move constructor.
1158  * @param accessor Accessor to be moved
1159  */
1161 
1162  /**
1163  * Creates a new accessor object.
1164  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1165  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1166  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1167  * @param subsetSize The number of indices (not the number of elements) that define the subset, may be 0 if indices is nullptr
1168  */
1169  inline ConstArraySubsetAccessor(const T* elements, const TIndex* subsetIndices, const size_t subsetSize);
1170 
1171  /**
1172  * Creates a new accessor object.
1173  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1174  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1175  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1176  */
1177  inline ConstArraySubsetAccessor(const T* elements, const std::vector<TIndex>& subsetIndices);
1178 
1179  /**
1180  * Creates a new accessor object.
1181  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1182  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1183  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1184  */
1185  inline ConstArraySubsetAccessor(const std::vector<T>& elements, const std::vector<TIndex>& subsetIndices);
1186 
1187  /**
1188  * Returns the number of accessible elements of this accessor object.
1189  * @see ConstAccessor::size().
1190  */
1191  virtual size_t size() const;
1192 
1193  /**
1194  * Returns one element of this accessor object.
1195  * @see ConstAccessor::operator[].
1196  */
1197  virtual const T& operator[](const size_t& index) const;
1198 
1199  /**
1200  * Move operator.
1201  * @param accessor Accessor to be moved
1202  * @return Reference to this object
1203  */
1205 
1206  protected:
1207 
1208  /// The elements of this accessor.
1209  const T* elements_ = nullptr;
1210 
1211  /// The subset indices of this accessor.
1212  const TIndex* subsetIndices_ = nullptr;
1213 
1214  /// The number of elements that can be accessed.
1215  size_t subsetSize_ = 0;
1216 };
1217 
1218 /**
1219  * This class implements an indexed-based constant accessor providing access to a subset of elements stored in an array.
1220  * The subset is defined by a set of indices defining also the order of the accessible elements.<br>
1221  * An instance of this accessor does not copy the elements or the subset indices, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.<br>
1222  * This class is not derived from Accessor (or any other Accessor class) to avoid virtual functions ensuring higher element-access performances.<br>
1223  * Thus, this class will mainly be applied in template functions where the type of the accessor is defined at compile time.
1224  * @tparam T The data type of the elements of the accessor
1225  * @tparam TIndex The data type of the indices defining the subset of elements
1226  * @see ConstTemplateArrayAccessor.
1227  * @ingroup base
1228  */
1229 template <typename T, typename TIndex>
1231 {
1232  public:
1233 
1234  /**
1235  * Definition of the element type of this accessor.
1236  */
1237  typedef T Type;
1238 
1239  /**
1240  * Definition of the key (or e.g., index) type of this accessor.
1241  */
1242  typedef size_t KeyType;
1243 
1244  /**
1245  * Definition of the data type of the indices.
1246  */
1247  typedef TIndex IndexType;
1248 
1249  public:
1250 
1251  /**
1252  * Creates a new empty accessor.
1253  */
1255 
1256  /**
1257  * Move constructor.
1258  * @param accessor Accessor to be moved
1259  */
1261 
1262  /**
1263  * Creates a new accessor object.
1264  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1265  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1266  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1267  * @param subsetSize The number of indices (not the number of elements) that define the subset, may be 0 if indices is nullptr
1268  */
1269  inline ConstTemplateArraySubsetAccessor(const T* elements, const TIndex* subsetIndices, const size_t subsetSize);
1270 
1271  /**
1272  * Creates a new accessor object.
1273  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1274  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1275  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1276  */
1277  inline ConstTemplateArraySubsetAccessor(const T* elements, const std::vector<TIndex>& subsetIndices);
1278 
1279  /**
1280  * Creates a new accessor object.
1281  * Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.<br>
1282  * @param elements The elements that can be accessed, may be nullptr if size is equal 0
1283  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
1284  */
1285  inline ConstTemplateArraySubsetAccessor(const std::vector<T>& elements, const std::vector<TIndex>& subsetIndices);
1286 
1287  /**
1288  * Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.
1289  * @see ConstAccessor::data().
1290  */
1291  inline const T* data() const;
1292 
1293  /**
1294  * Returns the number of accessible elements of this accessor object.
1295  * @see ConstAccessor::size().
1296  */
1297  inline size_t size() const;
1298 
1299  /**
1300  * Returns whether this accessor provides no elements.
1301  * @return True, if so
1302  */
1303  inline bool isEmpty() const;
1304 
1305  /**
1306  * Returns whether this accessor has a specific element.
1307  * @see ConstAccessor::canAccess().
1308  */
1309  inline bool canAccess(const size_t& index) const;
1310 
1311  /**
1312  * Returns the first element of this accessor.
1313  * @see ConstAccessor:firstElement().
1314  */
1315  inline bool firstElement(T& element, size_t& index) const;
1316 
1317  /**
1318  * Returns the next element which follows a given key of the previous element.
1319  * @see ConstAccessor::nextElement().
1320  */
1321  inline bool nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const;
1322 
1323  /**
1324  * Returns one element of this accessor object.
1325  * @see ConstAccessor::operator[].
1326  */
1327  inline const T& operator[](const size_t& index) const;
1328 
1329  /**
1330  * Move operator.
1331  * @param accessor Accessor to be moved
1332  * @return Reference to this object
1333  */
1335 
1336  protected:
1337 
1338  /// The elements of this accessor.
1339  const T* elements_ = nullptr;
1340 
1341  /// The subset indices of this accessor.
1342  const TIndex* subsetIndices_ = nullptr;
1343 
1344  /// The number of elements that can be accessed.
1345  size_t subsetSize_ = 0;
1346 };
1347 
1348 /**
1349  * This class implements an indexed-based constant accessor providing access to a subset of elements stored in a specified indexed-based child accessor.
1350  * @tparam T The data type of the elements of the accessor
1351  * @tparam TIndex The data type of the indices defining the subset of elements
1352  * @ingroup base
1353  */
1354 template <typename T, typename TIndex>
1356 {
1357  public:
1358 
1359  /**
1360  * Creates a new accessor which uses an accessor as base.
1361  * @param child The child accessor
1362  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of elements in the child accessor
1363  * @param subsetSize The number of indices (not the number of elements) that define the subset, may be 0 if indices is nullptr
1364  */
1365  inline ConstIndexedAccessorSubsetAccessor(const ConstIndexedAccessor<T>& child, const TIndex* subsetIndices, const size_t subsetSize);
1366 
1367  /**
1368  * Creates a new accessor which uses an accessor as base.
1369  * @param child The child accessor
1370  * @param subsetIndices The indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of elements in the child accessor
1371  */
1372  inline ConstIndexedAccessorSubsetAccessor(const ConstIndexedAccessor<T>& child, const std::vector<TIndex>& subsetIndices);
1373 
1374  /**
1375  * Returns the number of accessible elements of this accessor object.
1376  * @see Accessor::size().
1377  */
1378  virtual size_t size() const;
1379 
1380  /**
1381  * Returns one element of this accessor object.
1382  * @param index The index of element to be accessed, with range [0, size())
1383  * @return The requested element
1384  */
1385  virtual const T& operator[](const size_t& index) const;
1386 
1387  protected:
1388 
1389  // The child accessor of this accessor.
1391 
1392  /// The subset indices of this accessor.
1393  const TIndex* subsetIndices_ = nullptr;
1394 
1395  /// The number of elements that can be accessed.
1396  size_t subsetSize_ = 0;
1397 };
1398 
1399 /**
1400  * This class implements an accessor providing access to a elements by using a callback function.
1401  * @tparam T The data type of the elements of the accessor
1402  * @ingroup base
1403  */
1404 template <typename T>
1406 {
1407  public:
1408 
1409  /**
1410  * Definition of a callback function providing access to individual elements.
1411  * The first parameter is the index of the elements to be accessed
1412  * The return parameter is the constant reference to the requested element
1413  */
1415 
1416  public:
1417 
1418  /**
1419  * Creates a new empty accessor.
1420  */
1422 
1423  /**
1424  * Creates a new accessor object.
1425  * @param callback The callback function providing access to individual elements
1426  * @param size The number of elements of this accessor
1427  */
1428  inline ConstCallbackIndexedAccessor(const CallbackFunction& callback, const size_t size);
1429 
1430  /**
1431  * Returns one element of this accessor object.
1432  * @see ConstAccessor::operator[].
1433  */
1434  virtual const T& operator[](const size_t& index) const;
1435 
1436  /**
1437  * Returns the number of accessible elements of this accessor object.
1438  * @see ConstAccessor::size().
1439  */
1440  virtual size_t size() const;
1441 
1442  protected:
1443 
1444  /// The callback function of this accessor.
1446 
1447  /// The number of elements that can be accessed.
1448  size_t size_ = 0;
1449 };
1450 
1451 /**
1452  * This class implements an accessor that guarantees memory access to the elements of an indexed accessor object until the scope ends.
1453  * The memory access ensures that the entire data of the indexed accessor objects is provided as one memory block without any gaps.<br>
1454  * Beware: The data of the given indexed accessor may be copied (if necessary) to ensure the functionality.<br>
1455  * Thus, the accessible elements of this object may be clones/copies of the actual provided accessor object.
1456  */
1457 template <typename T>
1459 {
1460  public:
1461 
1462  /**
1463  * Creates a new scoped accessor object by a given indexed accessor object.
1464  * @param accessor The accessor object providing the data for this scoped object, ensure that the provided accessor exists at least until the scope ends
1465  * @tparam TAccessor The data type of the accessor providing the data, must be of type ConstIndexedAccessor<T>, or ConstTemplateArrayAccessor<T, size_t> or ConstTemplateArraySubsetAccessor<T, size_t>
1466  */
1467  template <typename TAccessor>
1468  inline explicit ScopedConstMemoryAccessor(const TAccessor& accessor);
1469 
1470  /**
1471  * Returns the pointer to the memory block providing the data of the accessor.
1472  * @return The memory block's pointer, nullptr if the accessor does not provide any data
1473  */
1474  inline const T* data() const;
1475 
1476  /**
1477  * Returns the number of elements the accessor provides.
1478  * @return The accessor's number of elements, with range [0, infinity)
1479  */
1480  inline size_t size() const;
1481 
1482  /**
1483  * Returns one element of this accessor.
1484  * @param index The index of the element, with range [0, size())
1485  * @return The requested element
1486  */
1487  inline const T& operator[](const size_t index) const;
1488 
1489  /**
1490  * Returns whether this object provides access to at least one element of the accessor.
1491  * @return True, if so
1492  */
1493  explicit inline operator bool() const;
1494 
1495  protected:
1496 
1497  /// The pointer to the memory block of the accessor.
1498  const T* data_ = nullptr;
1499 
1500  /// The number of elements the accessor provides.
1501  size_t size_ = 0;
1502 
1503  /// The individual elements of the accessor, if necessary.
1504  std::vector<T> intermediateValues_;
1505 };
1506 
1507 /**
1508  * This class implements an accessor that guarantees memory access to the elements of an indexed accessor object until the scope ends.
1509  * The memory access ensures that the entire data of the indexed accessor objects is provided as one memory block without any gaps.<br>
1510  * Beware: The data of the given indexed accessor may be copied (if necessary) to ensure the functionality.<br>
1511  * Thus, the accessible elements of this object may be clones/copies of the actual provided accessor object.
1512  * The connected indexed accessor object will hold the data of this accessor object after this object is disposed.
1513  */
1514 template <typename T>
1516 {
1517  public:
1518 
1519  /**
1520  * Creates a new scoped accessor object by a given indexed accessor object.
1521  * @param accessor The accessor object providing the data for this scoped object, the provided accessor needs to exist at least until the scope ends
1522  */
1523  explicit inline ScopedNonconstMemoryAccessor(NonconstIndexedAccessor<T>& accessor);
1524 
1525  /**
1526  * Creates a new scoped accessor object by an optional indexed accessor object or creates an internal temporary memory with specified size.
1527  * @param accessor The accessor object providing the data for this scoped object, the provided accessor needs to exist at least until the scope ends, nullptr to create an internal temporary memory without connected accessor
1528  * @param temporarySize The explicit size of the internal memory if no accessor is provided, does not have any meaning if an accessor is provided
1529  */
1530  explicit inline ScopedNonconstMemoryAccessor(NonconstIndexedAccessor<T>* accessor, const size_t temporarySize = 0);
1531 
1532  /**
1533  * Destructs the scoped accessor object.
1534  * Further, the intermediate values of this object may be copied back to the accessor object, if necessary.
1535  */
1537 
1538  /**
1539  * Returns the pointer to the memory block providing the data of the accessor.
1540  * @return The memory block's pointer, nullptr if the accessor does not provide any data
1541  */
1542  inline T* data();
1543 
1544  /**
1545  * Returns the number of elements the accessor provides.
1546  * @return The accessor's number of elements, with range [0, infinity)
1547  */
1548  inline size_t size() const;
1549 
1550  /**
1551  * Returns one element of this accessor.
1552  * @param index The index of the element, with range [0, size())
1553  * @return The requested element
1554  */
1555  inline T& operator[](const size_t index);
1556 
1557  /**
1558  * Returns whether this object provides access to at least one element of the accessor.
1559  * @return True, if so
1560  */
1561  explicit inline operator bool() const;
1562 
1563  protected:
1564 
1565  /// The given accessor object providing the data for this object, nullptr if no accessor object was provided during creation.
1567 
1568  /// The pointer to the memory block of the accessor.
1569  T* data_ = nullptr;
1570 
1571  /// The number of elements the accessor provides.
1572  size_t size_ = 0;
1573 
1574  /// The individual elements of the accessor, if necessary.
1575  std::vector<T> intermediateValues_;
1576 };
1577 
1578 inline bool Accessor::isEmpty() const
1579 {
1580  return size() == 0;
1581 }
1582 
1583 template <typename TAccessor>
1584 std::vector<typename TAccessor::Type> Accessor::accessor2elements(const TAccessor& accessor)
1585 {
1586  std::vector<typename TAccessor::Type> result;
1587  result.reserve(accessor.size());
1588 
1589  for (size_t n = 0; n < accessor.size(); ++n)
1590  {
1591  result.emplace_back(accessor[n]);
1592  }
1593 
1594  return result;
1595 }
1596 
1597 template <typename TAccessor>
1598 std::unordered_map<typename TAccessor::KeyType, typename TAccessor::Type> Accessor::accessor2map(const TAccessor& accessor)
1599 {
1600  std::unordered_map<typename TAccessor::KeyType, typename TAccessor::Type> result;
1601 
1602  typename TAccessor::Type element;
1603  typename TAccessor::KeyType key;
1604 
1605  if (accessor.firstElement(element, key))
1606  {
1607  do
1608  {
1609  result[key] = element;
1610  }
1611  while (accessor.nexteElement(key, element, key));
1612  }
1613 
1614  return result;
1615 }
1616 
1617 template <typename TAccessor, typename TIndex>
1618 std::vector<typename TAccessor::Type> Accessor::accessor2subsetElements(const TAccessor& accessor, const std::vector<TIndex>& subset)
1619 {
1620  std::vector<typename TAccessor::Type> result;
1621  result.reserve(subset.size());
1622 
1623  for (size_t n = 0; n < subset.size(); ++n)
1624  {
1625  result.emplace_back(accessor[subset[n]]);
1626  }
1627 
1628  return result;
1629 }
1630 
1631 template <typename T, typename TKey>
1633 {
1634  return nullptr;
1635 }
1636 
1637 template <typename T, typename TKey>
1639 {
1640  return nullptr;
1641 }
1642 
1643 template <typename T>
1644 bool ConstIndexedAccessor<T>::canAccess(const size_t& index) const
1645 {
1646  return index < this->size();
1647 }
1648 
1649 template <typename T>
1650 bool ConstIndexedAccessor<T>::firstElement(T& element, size_t& index) const
1651 {
1652  if (this->size() == 0)
1653  {
1654  return false;
1655  }
1656 
1657  element = (*this)[0];
1658  index = 0;
1659 
1660  return true;
1661 }
1662 
1663 template <typename T>
1664 bool ConstIndexedAccessor<T>::nextElement(const size_t& previousIndex, T& element, size_t& nextIndex) const
1665 {
1666  if (previousIndex + 1 < this->size())
1667  {
1668  nextIndex = previousIndex + 1;
1669  element = (*this)[nextIndex];
1670 
1671  return true;
1672  }
1673 
1674  return false;
1675 }
1676 
1677 template <typename T>
1678 bool NonconstIndexedAccessor<T>::canAccess(const size_t& index) const
1679 {
1680  return index < this->size();
1681 }
1682 
1683 template <typename T>
1684 bool NonconstIndexedAccessor<T>::firstElement(T& element, size_t& index) const
1685 {
1686  if (this->size() == 0)
1687  {
1688  return false;
1689  }
1690 
1691  element = (*this)[0];
1692  index = 0;
1693  return true;
1694 }
1695 
1696 template <typename T>
1697 bool NonconstIndexedAccessor<T>::nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const
1698 {
1699  if (previousIndex + 1 < this->size())
1700  {
1701  nextIndex = previousIndex + 1;
1702  nextElement = (*this)[nextIndex];
1703  return true;
1704  }
1705 
1706  return false;
1707 }
1708 
1709 template <typename T>
1711 {
1712  if (this->isEmpty())
1713  {
1714  return nullptr;
1715  }
1716  else
1717  {
1718  return this;
1719  }
1720 }
1721 
1722 template <typename T>
1723 bool TemporaryIndexedAccessor<T>::canAccess(const size_t& index) const
1724 {
1725  return index < this->size();
1726 }
1727 
1728 template <typename T, typename TIndex>
1729 inline ConstIndexedAccessorSubsetAccessor<T, TIndex>::ConstIndexedAccessorSubsetAccessor(const ConstIndexedAccessor<T>& child, const TIndex* subsetIndices, const size_t subsetSize) :
1730  child_(child),
1731  subsetIndices_(subsetIndices),
1732  subsetSize_(subsetSize)
1733 {
1734  // nothing to do here
1735 }
1736 
1737 template <typename T, typename TIndex>
1739  child_(child),
1740  subsetIndices_(subsetIndices.data()),
1741  subsetSize_(subsetIndices.size())
1742 {
1743  // nothing to do here
1744 }
1745 
1746 template <typename T, typename TIndex>
1748 {
1749  return subsetSize_;
1750 }
1751 
1752 template <typename T, typename TIndex>
1754 {
1755  ocean_assert(index < subsetSize_);
1756 
1757  return child_[subsetIndices_[index]];
1758 }
1759 
1760 template <typename T>
1762 {
1763  *this = std::move(accessor);
1764 }
1765 
1766 template <typename T>
1767 inline ConstArrayAccessor<T>::ConstArrayAccessor(const T* elements, const size_t size) :
1768  elements_(elements),
1769  size_(size)
1770 {
1771  // nothing to do here
1772 }
1773 
1774 template <typename T>
1775 inline ConstArrayAccessor<T>::ConstArrayAccessor(const std::vector<T>& elements) :
1776  elements_(elements.data()),
1777  size_(elements.size())
1778 {
1779  // nothing to do here
1780 }
1781 
1782 template <typename T>
1784 {
1785  return elements_;
1786 }
1787 
1788 template <typename T>
1790 {
1791  return size_;
1792 }
1793 
1794 template <typename T>
1795 const T& ConstArrayAccessor<T>::operator[](const size_t& index) const
1796 {
1797  ocean_assert(index < size_);
1798  ocean_assert(elements_ != nullptr);
1799 
1800  return elements_[index];
1801 }
1802 
1803 template <typename T>
1805 {
1806  if (this != &accessor)
1807  {
1808  elements_ = accessor.elements_;
1809  size_ = accessor.size_;
1810 
1811  accessor.elements_ = nullptr;
1812  accessor.size_ = 0;
1813  }
1814 
1815  return *this;
1816 }
1817 
1818 template <typename T>
1820  elements_(size)
1821 {
1822  for (size_t n = 0; n < size; ++n)
1823  {
1824  elements_[n] = elements[n]->get();
1825  }
1826 }
1827 
1828 template <typename T>
1830  elements_(elements.size())
1831 {
1832  for (size_t n = 0; n < elements.size(); ++n)
1833  {
1834  elements_[n] = elements[n].get();
1835  }
1836 }
1837 
1838 template <typename T>
1840 {
1841  return elements_.size();
1842 }
1843 
1844 template <typename T>
1845 const T* const & SharedPointerConstArrayAccessor<T>::operator[](const size_t& index) const
1846 {
1847  ocean_assert(index < elements_.size());
1848 
1849  return elements_[index];
1850 }
1851 
1852 template <typename T>
1854 {
1855  *this = std::move(accessor);
1856 }
1857 
1858 template <typename T>
1859 inline ConstTemplateArrayAccessor<T>::ConstTemplateArrayAccessor(const T* elements, const size_t size) :
1860  elements_(elements),
1861  size_(size)
1862 {
1863  // nothing to do here
1864 }
1865 
1866 template <typename T>
1867 inline ConstTemplateArrayAccessor<T>::ConstTemplateArrayAccessor(const std::vector<T>& elements) :
1868  elements_(elements.data()),
1869  size_(elements.size())
1870 {
1871  // nothing to do here
1872 }
1873 
1874 template <typename T>
1876 {
1877  return elements_;
1878 }
1879 
1880 template <typename T>
1882 {
1883  return size_;
1884 }
1885 
1886 template <typename T>
1888 {
1889  return size_ == 0;
1890 }
1891 
1892 template <typename T>
1893 inline bool ConstTemplateArrayAccessor<T>::canAccess(const size_t& index) const
1894 {
1895  return index < size_;
1896 }
1897 
1898 template <typename T>
1899 inline bool ConstTemplateArrayAccessor<T>::firstElement(T& element, size_t& index) const
1900 {
1901  if (size_ == 0)
1902  {
1903  return false;
1904  }
1905 
1906  element = elements_[0];
1907  index = 0;
1908  return true;
1909 }
1910 
1911 template <typename T>
1912 inline bool ConstTemplateArrayAccessor<T>::nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const
1913 {
1914  if (previousIndex + 1 >= size_)
1915  {
1916  return false;
1917  }
1918 
1919  nextIndex = previousIndex + 1;
1920  nextElement = elements_[nextIndex];
1921  return true;
1922 }
1923 
1924 template <typename T>
1925 inline const T& ConstTemplateArrayAccessor<T>::operator[](const size_t& index) const
1926 {
1927  ocean_assert(index < size_);
1928  return elements_[index];
1929 }
1930 
1931 template <typename T>
1933 {
1934  if (this != &accessor)
1935  {
1936  elements_ = accessor.elements_;
1937  size_ = accessor.size_;
1938 
1939  accessor.elements_ = nullptr;
1940  accessor.size_ = 0;
1941  }
1942 
1943  return *this;
1944 }
1945 
1946 template <typename T>
1948 {
1949  *this = std::move(accessor);
1950 }
1951 
1952 template <typename T>
1953 inline NonconstArrayAccessor<T>::NonconstArrayAccessor(T* elements, const size_t size) :
1954  elements_(elements),
1955  size_(size)
1956 {
1957  // nothing to do here
1958 }
1959 
1960 template <typename T>
1961 inline NonconstArrayAccessor<T>::NonconstArrayAccessor(std::vector<T>& elements) :
1962  elements_(elements.data()),
1963  size_(elements.size())
1964 {
1965  // nothing to do here
1966 }
1967 
1968 template <typename T>
1969 inline NonconstArrayAccessor<T>::NonconstArrayAccessor(std::vector<T>& elements, const size_t resizeSize) :
1970  elements_(nullptr),
1971  size_(0)
1972 {
1973  if (resizeSize != 0)
1974  {
1975  elements.resize(resizeSize);
1976  }
1977 
1978  elements_ = elements.data();
1979  size_ = elements.size();
1980 }
1981 
1982 template <typename T>
1983 inline NonconstArrayAccessor<T>::NonconstArrayAccessor(std::vector<T>* elements, const size_t resizeSize) :
1984  elements_(nullptr),
1985  size_(0)
1986 {
1987  if (elements)
1988  {
1989  if (resizeSize != 0)
1990  {
1991  elements->resize(resizeSize);
1992  }
1993 
1994  elements_ = elements->data();
1995  size_ = elements->size();
1996  }
1997 }
1998 
1999 template <typename T>
2000 const T& NonconstArrayAccessor<T>::operator[](const size_t& index) const
2001 {
2002  ocean_assert(index < size_);
2003  ocean_assert(elements_);
2004 
2005  return elements_[index];
2006 }
2007 
2008 template <typename T>
2010 {
2011  ocean_assert(index < size_);
2012  ocean_assert(elements_);
2013 
2014  return elements_[index];
2015 }
2016 
2017 template <typename T>
2019 {
2020  return elements_;
2021 }
2022 
2023 template <typename T>
2025 {
2026  return size_;
2027 }
2028 
2029 template <typename T>
2031 {
2032  if (this != &accessor)
2033  {
2034  elements_ = accessor.elements_;
2035  size_ = accessor.size_;
2036 
2037  accessor.elements_ = nullptr;
2038  accessor.size_ = 0;
2039  }
2040 
2041  return *this;
2042 }
2043 
2044 template <typename T>
2046 {
2047  *this = std::move(accessor);
2048 }
2049 
2050 template <typename T>
2052  elements_(elements),
2053  size_(size)
2054 {
2055  // nothing to do here
2056 }
2057 
2058 template <typename T>
2060  elements_(elements.data()),
2061  size_(elements.size())
2062 {
2063  // nothing to do here
2064 }
2065 
2066 template <typename T>
2067 inline NonconstTemplateArrayAccessor<T>::NonconstTemplateArrayAccessor(std::vector<T>& elements, const size_t resizeSize) :
2068  elements_(nullptr),
2069  size_(0)
2070 {
2071  if (resizeSize != 0)
2072  {
2073  elements.resize(resizeSize);
2074  }
2075 
2076  elements_ = elements.data();
2077  size_ = elements.size();
2078 }
2079 
2080 template <typename T>
2081 inline NonconstTemplateArrayAccessor<T>::NonconstTemplateArrayAccessor(std::vector<T>* elements, const size_t resizeSize) :
2082  elements_(nullptr),
2083  size_(0)
2084 {
2085  if (elements)
2086  {
2087  if (resizeSize != 0)
2088  {
2089  elements->resize(resizeSize);
2090  }
2091 
2092  elements_ = elements->data();
2093  size_ = elements->size();
2094  }
2095 }
2096 
2097 template <typename T>
2099 {
2100  return elements_;
2101 }
2102 
2103 template <typename T>
2105 {
2106  return elements_;
2107 }
2108 
2109 template <typename T>
2111 {
2112  return size_;
2113 }
2114 
2115 template <typename T>
2117 {
2118  return size_ == 0;
2119 }
2120 
2121 template <typename T>
2122 inline bool NonconstTemplateArrayAccessor<T>::canAccess(const size_t& index) const
2123 {
2124  return index < size_;
2125 }
2126 
2127 template <typename T>
2128 inline bool NonconstTemplateArrayAccessor<T>::firstElement(T& element, size_t& index) const
2129 {
2130  if (size_ == 0)
2131  {
2132  return false;
2133  }
2134 
2135  element = elements_[0];
2136  index = 0;
2137  return true;
2138 }
2139 
2140 template <typename T>
2141 inline bool NonconstTemplateArrayAccessor<T>::nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const
2142 {
2143  if (previousIndex + 1 >= size_)
2144  {
2145  return false;
2146  }
2147 
2148  nextIndex = previousIndex + 1;
2149  nextElement = elements_[nextIndex];
2150  return true;
2151 }
2152 
2153 template <typename T>
2154 inline const T& NonconstTemplateArrayAccessor<T>::operator[](const size_t& index) const
2155 {
2156  ocean_assert(index < size_);
2157  return elements_[index];
2158 }
2159 
2160 template <typename T>
2161 inline T& NonconstTemplateArrayAccessor<T>::operator[](const size_t& index)
2162 {
2163  ocean_assert(index < size_);
2164  return elements_[index];
2165 }
2166 
2167 template <typename T>
2169 {
2170  if (this != &accessor)
2171  {
2172  elements_ = accessor.elements_;
2173  size_ = accessor.size_;
2174 
2175  accessor.elements_ = nullptr;
2176  accessor.size_ = 0;
2177  }
2178 
2179  return *this;
2180 }
2181 
2182 template <typename T>
2184 {
2185  *this = std::move(accessor);
2186 }
2187 
2188 template <typename T>
2189 inline ConstElementAccessor<T>::ConstElementAccessor(const size_t size, const T& element) :
2190  element_(&element),
2191  size_(size)
2192 {
2193  ocean_assert(size_ != 0);
2194  ocean_assert(element_ != nullptr);
2195 }
2196 
2197 template <typename T>
2199 {
2200  return size_;
2201 }
2202 
2203 template <typename T>
2204 const T& ConstElementAccessor<T>::operator[](const size_t& index) const
2205 {
2206  ocean_assert_and_suppress_unused(index < size_, index);
2207  ocean_assert(element_ != nullptr);
2208 
2209  return *element_;
2210 }
2211 
2212 template <typename T>
2214 {
2215  if (this != &accessor)
2216  {
2217  element_ = accessor.element_;
2218  size_ = accessor.size_;
2219 
2220  accessor.element_ = nullptr;
2221  accessor.size_ = 0;
2222  }
2223 
2224  return *this;
2225 }
2226 
2227 template <typename T, typename TKey>
2229 {
2230  *this = std::move(accessor);
2231 }
2232 
2233 template <typename T, typename TKey>
2234 inline ConstMapAccessor<T, TKey>::ConstMapAccessor(const std::unordered_map<TKey, T>& elements) :
2235  elementMap_(&elements)
2236 {
2237  // nothing to do here
2238 }
2239 
2240 template <typename T, typename TKey>
2242 {
2243  return elementMap_ ? elementMap_->size() : 0;
2244 }
2245 
2246 template <typename T, typename TKey>
2247 bool ConstMapAccessor<T, TKey>::canAccess(const TKey& key) const
2248 {
2249  if (elementMap_ == nullptr)
2250  {
2251  return false;
2252  }
2253 
2254  return elementMap_->find(key) != elementMap_->end();
2255 }
2256 
2257 template <typename T, typename TKey>
2258 bool ConstMapAccessor<T, TKey>::firstElement(T& element, TKey& key) const
2259 {
2260  if (elementMap_ == nullptr || elementMap_->empty())
2261  {
2262  return false;
2263  }
2264 
2265  key = elementMap_->begin()->first;
2266  element = elementMap_->begin()->second;
2267 
2268  return true;
2269 }
2270 
2271 template <typename T, typename TKey>
2272 bool ConstMapAccessor<T, TKey>::nextElement(const TKey& previousKey, T& element, TKey& nextKey) const
2273 {
2274  if (elementMap_ == nullptr)
2275  {
2276  return false;
2277  }
2278 
2279  const typename std::unordered_map<TKey, T>::const_iterator i = elementMap_->find(previousKey);
2280  if (i == elementMap_->cend() || (++i) == elementMap_->cend())
2281  {
2282  return false;
2283  }
2284 
2285  nextKey = i->first;
2286  element = i->second;
2287 
2288  return true;
2289 }
2290 
2291 template <typename T, typename TKey>
2292 const T& ConstMapAccessor<T, TKey>::operator[](const TKey& key) const
2293 {
2294  ocean_assert(elementMap_);
2295  ocean_assert(elementMap_->find(key) != elementMap_->end());
2296 
2297  return elementMap_->find(key)->second;
2298 }
2299 
2300 template <typename T, typename TKey>
2302 {
2303  if (this != &accessor)
2304  {
2305  elementMap_ = accessor.elementMap_;
2306  accessor.elementMap_ = nullptr;
2307  }
2308 
2309  return *this;
2310 }
2311 
2312 template <typename T, typename TKey>
2313 inline NonconstMapAccessor<T, TKey>::NonconstMapAccessor(std::unordered_map<TKey, T>& elements) :
2314  elementMap_(&elements)
2315 {
2316  // nothing to do here
2317 }
2318 
2319 template <typename T, typename TKey>
2320 bool NonconstMapAccessor<T, TKey>::canAccess(const TKey& key) const
2321 {
2322  if (elementMap_ == nullptr)
2323  {
2324  return false;
2325  }
2326 
2327  return elementMap_->find(key) != elementMap_->end();
2328 }
2329 
2330 template <typename T, typename TKey>
2331 bool NonconstMapAccessor<T, TKey>::firstElement(T& element, TKey& key) const
2332 {
2333  if (elementMap_ == nullptr || elementMap_->empty())
2334  {
2335  return false;
2336  }
2337 
2338  key = elementMap_->begin()->first;
2339  element = elementMap_->begin()->second;
2340 
2341  return true;
2342 }
2343 
2344 template <typename T, typename TKey>
2345 bool NonconstMapAccessor<T, TKey>::nextElement(const TKey& previousKey, T& element, TKey& nextKey) const
2346 {
2347  if (elementMap_ == nullptr)
2348  {
2349  return false;
2350  }
2351 
2352  const typename std::unordered_map<TKey, T>::const_iterator i = elementMap_->find(previousKey);
2353  if (i == elementMap_->cend() || (++i) == elementMap_->cend())
2354  {
2355  return false;
2356  }
2357 
2358  nextKey = i->first;
2359  element = i->second;
2360 
2361  return true;
2362 }
2363 
2364 template <typename T, typename TKey>
2366 {
2367  return elementMap_ ? elementMap_->size() : 0;
2368 }
2369 
2370 template <typename T, typename TKey>
2371 const T& NonconstMapAccessor<T, TKey>::operator[](const TKey& key) const
2372 {
2373  ocean_assert(elementMap_);
2374  ocean_assert(elementMap_->find(key) != elementMap_->end());
2375 
2376  return elementMap_->find(key)->second;
2377 }
2378 
2379 template <typename T, typename TKey>
2381 {
2382  ocean_assert(elementMap_);
2383  ocean_assert(elementMap_->find(key) != elementMap_->end());
2384 
2385  return elementMap_->find(key)->second;
2386 }
2387 
2388 template <typename T, typename TIndex>
2390 {
2391  *this = std::move(accessor);
2392 }
2393 
2394 template <typename T, typename TIndex>
2395 inline ConstArraySubsetAccessor<T, TIndex>::ConstArraySubsetAccessor(const T* elements, const TIndex* subsetIndices, const size_t subsetSize) :
2396  elements_(elements),
2397  subsetIndices_(subsetIndices),
2398  subsetSize_(subsetSize)
2399 {
2400  // nothing to do here
2401 }
2402 
2403 template <typename T, typename TIndex>
2404 inline ConstArraySubsetAccessor<T, TIndex>::ConstArraySubsetAccessor(const T* elements, const std::vector<TIndex>& subsetIndices) :
2405  elements_(elements),
2406  subsetIndices_(subsetIndices.data()),
2407  subsetSize_(subsetIndices.size())
2408 {
2409  // nothing to do here
2410 }
2411 
2412 template <typename T, typename TIndex>
2413 inline ConstArraySubsetAccessor<T, TIndex>::ConstArraySubsetAccessor(const std::vector<T>& elements, const std::vector<TIndex>& subsetIndices) :
2414  elements_(elements.data()),
2415  subsetIndices_(subsetIndices.data()),
2416  subsetSize_(subsetIndices.size())
2417 {
2418 #ifdef OCEAN_DEBUG
2419  ocean_assert(subsetIndices.size() <= elements.size());
2420  for (size_t n = 0; n < subsetIndices.size(); ++n)
2421  {
2422  ocean_assert(subsetIndices[n] < elements.size());
2423  }
2424 #endif
2425 }
2426 
2427 template <typename T, typename TIndex>
2429 {
2430  return subsetSize_;
2431 }
2432 
2433 template <typename T, typename TIndex>
2434 const T& ConstArraySubsetAccessor<T, TIndex>::operator[](const size_t& index) const
2435 {
2436  ocean_assert(index < subsetSize_);
2437  ocean_assert(elements_ && subsetIndices_);
2438 
2439  return elements_[subsetIndices_[index]];
2440 }
2441 
2442 template <typename T, typename TIndex>
2444 {
2445  if (this != &accessor)
2446  {
2447  elements_ = accessor.elements_;
2448  subsetIndices_ = accessor.subsetIndices_;
2449  subsetSize_ = accessor.subsetSize_;
2450 
2451  accessor.elements_ = nullptr;
2452  accessor.subsetIndices_ = nullptr;
2453  accessor.subsetSize_ = 0;
2454  }
2455 
2456  return *this;
2457 }
2458 
2459 template <typename T, typename TIndex>
2461 {
2462  *this = std::move(accessor);
2463 }
2464 
2465 template <typename T, typename TIndex>
2466 inline ConstTemplateArraySubsetAccessor<T, TIndex>::ConstTemplateArraySubsetAccessor(const T* elements, const TIndex* subsetIndices, const size_t subsetSize) :
2467  elements_(elements),
2468  subsetIndices_(subsetIndices),
2469  subsetSize_(subsetSize)
2470 {
2471  ocean_assert(subsetSize_ == 0 || (elements_ != nullptr && subsetIndices_ != nullptr));
2472 }
2473 
2474 template <typename T, typename TIndex>
2475 inline ConstTemplateArraySubsetAccessor<T, TIndex>::ConstTemplateArraySubsetAccessor(const T* elements, const std::vector<TIndex>& subsetIndices) :
2476  elements_(elements),
2477  subsetIndices_(subsetIndices.data()),
2478  subsetSize_(subsetIndices.size())
2479 {
2480  ocean_assert(subsetSize_ == 0 || (elements_ != nullptr && subsetIndices_ != nullptr));
2481 }
2482 
2483 template <typename T, typename TIndex>
2484 inline ConstTemplateArraySubsetAccessor<T, TIndex>::ConstTemplateArraySubsetAccessor(const std::vector<T>& elements, const std::vector<TIndex>& subsetIndices) :
2485  elements_(elements.data()),
2486  subsetIndices_(subsetIndices.data()),
2487  subsetSize_(subsetIndices.size())
2488 {
2489 #ifdef OCEAN_DEBUG
2490  ocean_assert(subsetIndices.size() <= elements.size());
2491  for (size_t n = 0; n < subsetIndices.size(); ++n)
2492  {
2493  ocean_assert(subsetIndices[n] < elements.size());
2494  }
2495 #endif
2496 }
2497 
2498 template <typename T, typename TIndex>
2500 {
2501  return nullptr;
2502 }
2503 
2504 template <typename T, typename TIndex>
2506 {
2507  return subsetSize_;
2508 }
2509 
2510 template <typename T, typename TIndex>
2512 {
2513  return subsetSize_ == 0;
2514 }
2515 
2516 template <typename T, typename TIndex>
2517 inline bool ConstTemplateArraySubsetAccessor<T, TIndex>::canAccess(const size_t& index) const
2518 {
2519  return index < subsetSize_;
2520 }
2521 
2522 template <typename T, typename TIndex>
2523 inline bool ConstTemplateArraySubsetAccessor<T, TIndex>::firstElement(T& element, size_t& index) const
2524 {
2525  if (subsetSize_ == 0)
2526  {
2527  return false;
2528  }
2529 
2530  element = (*this)[0];
2531  index = 0;
2532 
2533  return true;
2534 }
2535 
2536 template <typename T, typename TIndex>
2537 inline bool ConstTemplateArraySubsetAccessor<T, TIndex>::nextElement(const size_t& previousIndex, T& nextElement, size_t& nextIndex) const
2538 {
2539  if (previousIndex + 1 >= subsetSize_)
2540  {
2541  return false;
2542  }
2543 
2544  nextIndex = previousIndex + 1;
2545  nextElement = (*this)[nextIndex];
2546 
2547  return true;
2548 }
2549 
2550 template <typename T, typename TIndex>
2551 inline const T& ConstTemplateArraySubsetAccessor<T, TIndex>::operator[](const size_t& index) const
2552 {
2553  ocean_assert(index < subsetSize_);
2554 
2555  return elements_[subsetIndices_[index]];
2556 }
2557 
2558 template <typename T, typename TIndex>
2560 {
2561  if (this != &accessor)
2562  {
2563  elements_ = accessor.elements_;
2564  subsetIndices_ = accessor.subsetIndices_;
2565  subsetSize_ = accessor.subsetSize_;
2566 
2567  accessor.elements_ = nullptr;
2568  accessor.subsetIndices_ = nullptr;
2569  accessor.subsetSize_ = 0;
2570  }
2571 
2572  return *this;
2573 }
2574 
2575 template <typename T>
2577  callback_(callback),
2578  size_(size)
2579 {
2580  // nothing to do here
2581 }
2582 
2583 template <typename T>
2584 const T& ConstCallbackIndexedAccessor<T>::operator[](const size_t& index) const
2585 {
2586  ocean_assert(index < size_);
2587  ocean_assert(callback_);
2588 
2589  return callback_(index);
2590 }
2591 
2592 template <typename T>
2594 {
2595  return size_;
2596 }
2597 
2598 template <typename T>
2599 template <typename TAccessor>
2601  data_(nullptr),
2602  size_(0)
2603 {
2604  data_ = accessor.data();
2605  size_ = accessor.size();
2606 
2607  if (data_ == nullptr && size_ != 0)
2608  {
2609  intermediateValues_.reserve(size_);
2610 
2611  for (size_t n = 0; n < size_; ++n)
2612  {
2613  intermediateValues_.emplace_back(accessor[n]);
2614  }
2615 
2616  data_ = intermediateValues_.data();
2617  }
2618 }
2619 
2620 template <typename T>
2621 inline const T* ScopedConstMemoryAccessor<T>::data() const
2622 {
2623  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2624 
2625  return data_;
2626 }
2627 
2628 template <typename T>
2630 {
2631  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2632 
2633  return size_;
2634 }
2635 
2636 template <typename T>
2637 inline const T& ScopedConstMemoryAccessor<T>::operator[](const size_t index) const
2638 {
2639  ocean_assert(data_ && index < size());
2640 
2641  return data_[index];
2642 }
2643 
2644 template <typename T>
2646 {
2647  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2648 
2649  return data_ != nullptr;
2650 }
2651 
2652 template <typename T>
2654  accessor_(&accessor),
2655  data_(nullptr),
2656  size_(0)
2657 {
2658  data_ = accessor.data();
2659  size_ = accessor.size();
2660 
2661  if (data_ == nullptr && size_ != 0)
2662  {
2663  // the provided accessor does not allow to access the elements as a joined memory block, so we create out own intermediate memory block
2664 
2665  intermediateValues_.reserve(size_);
2666 
2667  for (size_t n = 0; n < size_; ++n)
2668  {
2669  intermediateValues_.emplace_back(accessor[n]);
2670  }
2671 
2672  data_ = intermediateValues_.data();
2673  }
2674 }
2675 
2676 template <typename T>
2678  accessor_(accessor),
2679  data_(nullptr),
2680  size_(0)
2681 {
2682  if (accessor_)
2683  {
2684  data_ = accessor_->data();
2685  size_ = accessor_->size();
2686 
2687  if (data_ == nullptr && size_ != 0)
2688  {
2689  // the provided accessor does not allow to access the elements as a joined memory block, so we create out own intermediate memory block
2690 
2691  intermediateValues_.reserve(size_);
2692 
2693  for (size_t n = 0; n < size_; ++n)
2694  {
2695  intermediateValues_.emplace_back((*accessor_)[n]);
2696  }
2697 
2698  data_ = intermediateValues_.data();
2699  }
2700  }
2701  else
2702  {
2703  // no provided accessor so that we create our own intermediate memory block
2704 
2705  intermediateValues_.resize(temporarySize);
2706 
2707  data_ = intermediateValues_.data();
2708  size_ = intermediateValues_.size();
2709  }
2710 }
2711 
2712 template <typename T>
2714 {
2715  if (accessor_ && !intermediateValues_.empty())
2716  {
2717  ocean_assert(accessor_->data() == nullptr);
2718  ocean_assert(size_ == accessor_->size());
2719 
2720  for (size_t n = 0; n < size_; ++n)
2721  {
2722  (*accessor_)[n] = std::move(intermediateValues_[n]);
2723  }
2724  }
2725 }
2726 
2727 template <typename T>
2729 {
2730  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2731 
2732  return data_;
2733 }
2734 
2735 template <typename T>
2737 {
2738  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2739 
2740  return size_;
2741 }
2742 
2743 template <typename T>
2744 inline T& ScopedNonconstMemoryAccessor<T>::operator[](const size_t index)
2745 {
2746  ocean_assert(data_ && index < size());
2747 
2748  return data_[index];
2749 }
2750 
2751 template <typename T>
2753 {
2754  ocean_assert((data_ != nullptr && size_ != 0) || (data_ == nullptr && size_ == 0));
2755 
2756  return data_ != nullptr;
2757 }
2758 
2759 }
2760 
2761 #endif // META_OCEAN_BASE_ACCESSOR_H
This class implements a base class for all accessors.
Definition: Accessor.h:23
Accessor(const Accessor &accessor)=default
Protected copy constructor.
static std::unordered_map< typename TAccessor::KeyType, typename TAccessor::Type > accessor2map(const TAccessor &accessor)
Returns all elements of a given accessor as a map with key and elements.
Definition: Accessor.h:1598
virtual size_t size() const =0
Returns the number of accessible elements of this accessor object.
virtual ~Accessor()=default
Default destructor.
Accessor & operator=(const Accessor &accessor)=delete
Deleted assign operator.
static std::vector< typename TAccessor::Type > accessor2subsetElements(const TAccessor &accessor, const std::vector< TIndex > &subset)
Returns a subset of all elements of a given accessor (as a block).
Definition: Accessor.h:1618
Accessor()=default
Protected default constructor.
bool isEmpty() const
Returns whether this accessor provides no elements.
Definition: Accessor.h:1578
static std::vector< typename TAccessor::Type > accessor2elements(const TAccessor &accessor)
Returns all elements of a given accessor (as a block).
Definition: Accessor.h:1584
This class implements a base class for accessors allowing a constant reference access.
Definition: Accessor.h:97
TKey KeyType
Definition of the key (or e.g., index) type of this accessor.
Definition: Accessor.h:108
virtual bool nextElement(const TKey &previousKey, T &nextElement, TKey &nextKey) const =0
Returns the next element which follows a given key of the previous element.
virtual const T * data() const
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:1632
virtual const T & operator[](const TKey &key) const =0
Returns one element of this accessor object by a given key.
ConstAccessor()=default
Protected default constructor.
virtual bool canAccess(const TKey &key) const =0
Returns whether this accessor has a specific element.
virtual bool firstElement(T &element, TKey &key) const =0
Returns the first element of this accessor.
T Type
Definition of the element type of this accessor.
Definition: Accessor.h:103
This class implements an accessor providing direct access to a constant array of elements.
Definition: Accessor.h:400
ConstArrayAccessor()=default
Creates a new empty accessor.
ConstArrayAccessor< T > & operator=(ConstArrayAccessor< T > &&accessor) noexcept
Move operator.
Definition: Accessor.h:1804
const T * elements_
The elements of this accessor.
Definition: Accessor.h:457
virtual const T * data() const
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:1783
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:460
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:1789
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:1795
This class implements an indexed-based constant accessor providing access to a subset of elements sto...
Definition: Accessor.h:1141
size_t subsetSize_
The number of elements that can be accessed.
Definition: Accessor.h:1215
ConstArraySubsetAccessor< T, TIndex > & operator=(ConstArraySubsetAccessor< T, TIndex > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2443
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2428
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2434
ConstArraySubsetAccessor()=default
Creates a new empty accessor.
const TIndex * subsetIndices_
The subset indices of this accessor.
Definition: Accessor.h:1212
const T * elements_
The elements of this accessor.
Definition: Accessor.h:1209
TIndex IndexType
Definition of the data type of the indices.
Definition: Accessor.h:1147
This class implements an accessor providing access to a elements by using a callback function.
Definition: Accessor.h:1406
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2584
CallbackFunction callback_
The callback function of this accessor.
Definition: Accessor.h:1445
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:1448
ConstCallbackIndexedAccessor()=default
Creates a new empty accessor.
Callback< const T &, const size_t > CallbackFunction
Definition of a callback function providing access to individual elements.
Definition: Accessor.h:1414
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2593
This class implements an accessor providing direct access to a constant array of elements while all e...
Definition: Accessor.h:942
const T * element_
The element of this accessor.
Definition: Accessor.h:986
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2204
ConstElementAccessor()=default
Creates a new empty accessor.
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:989
ConstElementAccessor< T > & operator=(ConstElementAccessor< T > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2213
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2198
This class implements a base class for all indexed-based accessors allowing a constant reference acce...
Definition: Accessor.h:241
virtual bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:1644
virtual bool nextElement(const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:1664
virtual const T & operator[](const size_t &index) const =0
Returns one element of this accessor object by a given index.
ConstIndexedAccessor()=default
Creates a new indexed-based accessor object.
virtual bool firstElement(T &element, size_t &index) const
Returns the first element of this accessor.
Definition: Accessor.h:1650
This class implements an indexed-based constant accessor providing access to a subset of elements sto...
Definition: Accessor.h:1356
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:1747
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:1753
const ConstIndexedAccessor< T > & child_
Definition: Accessor.h:1390
const TIndex * subsetIndices_
The subset indices of this accessor.
Definition: Accessor.h:1393
size_t subsetSize_
The number of elements that can be accessed.
Definition: Accessor.h:1396
ConstIndexedAccessorSubsetAccessor(const ConstIndexedAccessor< T > &child, const TIndex *subsetIndices, const size_t subsetSize)
Creates a new accessor which uses an accessor as base.
Definition: Accessor.h:1729
This class implements an accessor providing direct access to a constant (unordered) map of elements.
Definition: Accessor.h:1001
ConstMapAccessor()=default
Creates a new empty accessor.
virtual bool firstElement(T &element, TKey &key) const
Returns the first element of this accessor.
Definition: Accessor.h:2258
virtual bool nextElement(const TKey &previousKey, T &nextElement, TKey &nextKey) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:2272
const std::unordered_map< TKey, T > * elementMap_
The elements of this accessor.
Definition: Accessor.h:1062
ConstMapAccessor< T, TKey > & operator=(ConstMapAccessor< T, TKey > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2301
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2241
virtual const T & operator[](const TKey &key) const
Returns one element of this accessor object.
Definition: Accessor.h:2292
virtual bool canAccess(const TKey &key) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:2247
This class implements an accessor providing direct access to a constant array of elements.
Definition: Accessor.h:600
T Type
Definition of the element type of this accessor.
Definition: Accessor.h:606
ConstTemplateArrayAccessor()=default
Creates a new empty accessor.
const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:1925
bool firstElement(T &element, size_t &index) const
Returns the first element of this accessor.
Definition: Accessor.h:1899
size_t KeyType
Definition of the key (or e.g., index) type of this accessor.
Definition: Accessor.h:611
bool isEmpty() const
Returns whether this accessor provides no elements.
Definition: Accessor.h:1887
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:696
const T * data() const
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:1875
ConstTemplateArrayAccessor< T > & operator=(ConstArrayAccessor< T > &&accessor) noexcept
Move operator.
Definition: Accessor.h:1932
size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:1881
bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:1893
const T * elements_
The elements of this accessor.
Definition: Accessor.h:693
bool nextElement(const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:1912
This class implements an indexed-based constant accessor providing access to a subset of elements sto...
Definition: Accessor.h:1231
const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2551
const T * data() const
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:2499
TIndex IndexType
Definition of the data type of the indices.
Definition: Accessor.h:1247
size_t subsetSize_
The number of elements that can be accessed.
Definition: Accessor.h:1345
size_t KeyType
Definition of the key (or e.g., index) type of this accessor.
Definition: Accessor.h:1242
T Type
Definition of the element type of this accessor.
Definition: Accessor.h:1237
ConstTemplateArraySubsetAccessor< T, TIndex > & operator=(ConstTemplateArraySubsetAccessor< T, TIndex > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2559
bool isEmpty() const
Returns whether this accessor provides no elements.
Definition: Accessor.h:2511
ConstTemplateArraySubsetAccessor()=default
Creates a new empty accessor.
bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:2517
const TIndex * subsetIndices_
The subset indices of this accessor.
Definition: Accessor.h:1342
bool firstElement(T &element, size_t &index) const
Returns the first element of this accessor.
Definition: Accessor.h:2523
bool nextElement(const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:2537
const T * elements_
The elements of this accessor.
Definition: Accessor.h:1339
size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2505
This class implements a base class for accessors allowing a non-constant reference access.
Definition: Accessor.h:166
virtual T & operator[](const TKey &key)=0
Returns one element of this accessor object by a given key.
NonconstAccessor()=default
Creates a new indexed-based accessor object.
virtual T * data()
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:1638
This class implements an accessor providing direct access to an array of elements.
Definition: Accessor.h:707
T * elements_
The elements of this accessor.
Definition: Accessor.h:788
virtual const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2000
virtual T * data()
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:2018
NonconstArrayAccessor< T > & operator=(NonconstArrayAccessor< T > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2030
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:791
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2024
NonconstArrayAccessor()=default
Creates a new empty accessor.
This class implements a base class for all indexed-based accessors allowing a non-constant reference ...
Definition: Accessor.h:284
virtual bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:1678
virtual bool firstElement(T &element, size_t &index) const
Returns the first element of this accessor.
Definition: Accessor.h:1684
virtual const T & operator[](const size_t &index) const =0
Returns one element of this accessor object by a given key.
NonconstIndexedAccessor< T > * pointer()
Returns the pointer to this object if this accessor holds at least one element (if this accessor is n...
Definition: Accessor.h:1710
virtual bool nextElement(const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:1697
virtual T & operator[](const size_t &index)=0
Returns one element of this accessor object by a given index.
NonconstIndexedAccessor()=default
Creates a new accessor object.
This class implements an accessor providing direct access to an (unordered) map of elements.
Definition: Accessor.h:1074
NonconstMapAccessor()=default
Creates a new empty accessor.
std::unordered_map< TKey, T > * elementMap_
The elements of this accessor.
Definition: Accessor.h:1128
virtual bool canAccess(const TKey &key) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:2320
virtual bool firstElement(T &element, TKey &key) const
Returns the first element of this accessor.
Definition: Accessor.h:2331
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2365
virtual const T & operator[](const TKey &key) const
Returns one element of this accessor object.
Definition: Accessor.h:2371
virtual bool nextElement(const TKey &previousKey, T &nextElement, TKey &nextKey) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:2345
This class implements an accessor providing direct access to an array of elements.
Definition: Accessor.h:805
bool nextElement(const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
Returns the next element which follows a given key of the previous element.
Definition: Accessor.h:2141
NonconstTemplateArrayAccessor()=default
Creates a new empty accessor.
size_t KeyType
Definition of the key (or e.g., index) type of this accessor.
Definition: Accessor.h:816
size_t size_
The number of elements that can be accessed.
Definition: Accessor.h:931
bool firstElement(T &element, size_t &index) const
Returns the first element of this accessor.
Definition: Accessor.h:2128
const T * data() const
Returns a pointer to the elements of this accessor if the data exists within one memory block without...
Definition: Accessor.h:2098
bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:2122
NonconstTemplateArrayAccessor< T > & operator=(NonconstTemplateArrayAccessor< T > &&accessor) noexcept
Move operator.
Definition: Accessor.h:2168
bool isEmpty() const
Returns whether this accessor provides no elements.
Definition: Accessor.h:2116
T Type
Definition of the element type of this accessor.
Definition: Accessor.h:811
T * elements_
The elements of this accessor.
Definition: Accessor.h:928
size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:2110
const T & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:2154
This class implements an accessor that guarantees memory access to the elements of an indexed accesso...
Definition: Accessor.h:1459
const T & operator[](const size_t index) const
Returns one element of this accessor.
Definition: Accessor.h:2637
size_t size_
The number of elements the accessor provides.
Definition: Accessor.h:1501
const T * data_
The pointer to the memory block of the accessor.
Definition: Accessor.h:1498
const T * data() const
Returns the pointer to the memory block providing the data of the accessor.
Definition: Accessor.h:2621
std::vector< T > intermediateValues_
The individual elements of the accessor, if necessary.
Definition: Accessor.h:1504
size_t size() const
Returns the number of elements the accessor provides.
Definition: Accessor.h:2629
ScopedConstMemoryAccessor(const TAccessor &accessor)
Creates a new scoped accessor object by a given indexed accessor object.
Definition: Accessor.h:2600
This class implements an accessor that guarantees memory access to the elements of an indexed accesso...
Definition: Accessor.h:1516
T * data_
The pointer to the memory block of the accessor.
Definition: Accessor.h:1569
size_t size_
The number of elements the accessor provides.
Definition: Accessor.h:1572
ScopedNonconstMemoryAccessor(NonconstIndexedAccessor< T > &accessor)
Creates a new scoped accessor object by a given indexed accessor object.
Definition: Accessor.h:2653
NonconstIndexedAccessor< T > * accessor_
The given accessor object providing the data for this object, nullptr if no accessor object was provi...
Definition: Accessor.h:1566
T * data()
Returns the pointer to the memory block providing the data of the accessor.
Definition: Accessor.h:2728
T & operator[](const size_t index)
Returns one element of this accessor.
Definition: Accessor.h:2744
~ScopedNonconstMemoryAccessor()
Destructs the scoped accessor object.
Definition: Accessor.h:2713
std::vector< T > intermediateValues_
The individual elements of the accessor, if necessary.
Definition: Accessor.h:1575
size_t size() const
Returns the number of elements the accessor provides.
Definition: Accessor.h:2736
This class implements an accessor providing direct access to std::shared_ptr<T> elements returned as ...
Definition: Accessor.h:497
SharedPointerConstArrayAccessor< T > & operator=(SharedPointerConstArrayAccessor< T > &&accessor)=default
Move operator.
SharedPointerConstArrayAccessor(SharedPointerConstArrayAccessor< T > &&accessor)=default
Move constructor.
std::vector< SharedPointer > SharedPointers
Definition of a vector holding the shared pointer objects.
Definition: Accessor.h:508
std::shared_ptr< T > SharedPointer
Definition of the shared pointer object.
Definition: Accessor.h:503
SharedPointerConstArrayAccessor()=default
Creates a new empty accessor.
std::vector< const T * > elements_
The pointers to the actual elements wrapped in the shared pointers.
Definition: Accessor.h:560
virtual size_t size() const
Returns the number of accessible elements of this accessor object.
Definition: Accessor.h:1839
virtual const T *const & operator[](const size_t &index) const
Returns one element of this accessor object.
Definition: Accessor.h:1845
This class implements a base class for all accessors allowing to access temporary elements.
Definition: Accessor.h:202
virtual T operator[](const TKey &key) const =0
Returns one element of this accessor object by a given index.
TemporaryAccessor()=default
Creates a new indexed-based accessor object.
virtual bool canAccess(const TKey &key) const =0
Returns whether this accessor has a specific element.
T Type
Definition of the element type of this accessor.
Definition: Accessor.h:208
This class implements a base class for all indexed-based accessors allowing to access temporary eleme...
Definition: Accessor.h:341
virtual T operator[](const size_t &index) const =0
Returns one element of this accessor object by a given index.
virtual bool canAccess(const size_t &index) const
Returns whether this accessor has a specific element.
Definition: Accessor.h:1723
TemporaryIndexedAccessor()=default
Creates a new indexed-based accessor object.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15