60#ifndef LIB_SCOPED_COLLECTION_H
61#define LIB_SCOPED_COLLECTION_H
76 using LERR_(INDEX_BOUNDS);
77 using LERR_(CAPACITY);
92 ,
size_t siz =
sizeof(I)
116 return * std::launder (
reinterpret_cast<I*
> (&buf_));
129 template<
class TY,
typename...ARGS>
134 &&
sizeof(TY) <= siz,
135 "ElementHolder buffer too small");
137 return *
new(&buf_) TY (std::forward<ARGS> (args)...);
154 , capacity_(maxElements)
168 , capacity_(maxElements)
171 populate_by (builder);
185 , capacity_(maxElements)
188 populate_by (builder,instance);
195 template<
typename TY>
198 template<
typename IT>
201 template<
typename IT>
211 REQUIRE (level_ <= capacity_,
"Storage corrupted");
217 elements_[level_].destroy();
227 while (level_ < capacity_)
229 elements_[level_].template create<I>();
235 WARN (progress,
"Failure while populating ScopedCollection. "
236 "All elements will be discarded");
252 while (level_ < capacity_)
255 builder (storageFrame);
260 WARN (progress,
"Failure while populating ScopedCollection. "
261 "All elements will be discarded");
274 while (level_ < capacity_)
277 (instance->*builder) (storageFrame);
282 WARN (progress,
"Failure while populating ScopedCollection. "
283 "All elements will be discarded");
304 template<
class TY =I,
typename...ARGS>
308 __ensureSufficientCapacity();
309 TY& newElm = elements_[level_].template create<TY>(std::forward<ARGS> (args)...);
319 operator[] (
size_t index)
const
322 return elements_[index].accessObj();
324 throw error::Logic (
"Attempt to access not (yet) existing object in ScopedCollection"
325 ,
LERR_(INDEX_BOUNDS));
340 size_t size ()
const {
return level_; }
342 bool empty ()
const {
return 0 == level_; }
366 if (level_ >= capacity_)
367 throw error::State (
"ScopedCollection exceeding the initially defined capacity"
393 template<
typename POS>
398 if ((pos) && (pos < src->_access_end()))
408 I*
_access_end()
const {
return & elements_[level_].accessObj(); }
426 template<
class I,
size_t siz>
433 storage.template create<I>();
437 template<
class I,
size_t siz>
438 template<
typename TY>
445 storage.template create<TY>();
458 template<
class I,
size_t siz>
459 template<
typename IT>
474 storage.template create<ElementType> (*iter_);
Adapter for building an implementation of the »Lumiera Forward Iterator« concept.
Storage Frame to hold one Child object.
TY & create(ARGS &&...args)
place object of type TY, forwarding ctor arguments
fills the ScopedCollection with default constructed I-instances
fills the ScopedCollection with default constructed TY-instances
meta::ValueTypeBinding< IT >::value_type ElementType
A fixed collection of non-copyable polymorphic objects.
IterAdapter< const I *, const ScopedCollection * > const_iterator
friend iterator begin(ScopedCollection &sco)
I * _access_begin() const
IterAdapter< I *, const ScopedCollection * > iterator
const_iterator begin() const
friend const iterator begin(ScopedCollection const &sco)
I & emplaceElement()
push a new element of default type to the end of this container
friend const iterator end(ScopedCollection const &sco)
void __ensureSufficientCapacity()
ScopedCollection(size_t maxElements, CTOR builder)
creating a ScopedCollection in RAII-style: The embedded elements will be created immediately.
friend bool checkPoint(const ScopedCollection *src, POS &pos)
Iteration-logic: detect iteration end.
ScopedCollection(size_t maxElements, void(TY::*builder)(ElementHolder &), TY *const instance)
variation of RAII-style: using a builder function, which is a member of some object.
static PullFrom< IT > pull(IT iter)
fills by copy-constructing values pulled from the iterator IT
TY & emplace(ARGS &&...args)
push new entry at the end of this container and build object of type TY in place there
friend void iterNext(const ScopedCollection *, I *&pos)
Iteration-logic: switch to next position.
friend iterator end(ScopedCollection &sco)
ScopedCollection(size_t maxElements)
void populate_by(void(TY::*builder)(ElementHolder &), TY *const instance)
variation of element initialisation, invoking a member function of some manager object for each colle...
void populate_by(CTOR builder)
init all elements at once, invoking a builder functor for each.
std::unique_ptr< ElementHolder[]> ElementStorage
void populate()
init all elements default constructed
const_iterator end() const
friend void iterNext(const ScopedCollection *, const I *&pos)
Any copy and copy construction prohibited.
Lumiera error handling (C++ interface).
#define ERROR_LOG_AND_IGNORE(_FLAG_, _OP_DESCR_)
convenience shortcut for a sequence of catch blocks just logging and consuming an error.
Helper template(s) for creating Lumiera Forward Iterators.
Implementation namespace for support and library code.
LumieraError< LERR_(STATE)> State
LumieraError< LERR_(LOGIC)> Logic
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Helpers for type detection, type rewriting and metaprogramming.