69 #ifndef LIB_SCOPED_COLLECTION_H 70 #define LIB_SCOPED_COLLECTION_H 78 #include <type_traits> 84 using error::LERR_(CAPACITY);
85 using error::LERR_(INDEX_BOUNDS);
100 ,
size_t siz =
sizeof(I)
117 mutable char buf_[siz];
124 return reinterpret_cast<I&
> (buf_);
137 template<
class TY,
typename...ARGS>
142 &&
sizeof(TY) <= siz,
143 "ElementHolder buffer too small");
145 return *
new(&buf_) TY (std::forward<ARGS> (args)...);
162 , capacity_(maxElements)
176 , capacity_(maxElements)
177 , elements_(new ElementHolder[maxElements])
179 populate_by (builder);
191 ScopedCollection (
size_t maxElements,
void (TY::*builder) (ElementHolder&), TY *
const instance)
193 , capacity_(maxElements)
194 , elements_(new ElementHolder[maxElements])
196 populate_by (builder,instance);
203 template<
typename TY>
206 template<
typename IT>
209 template<
typename IT>
213 return PullFrom<IT> (iter);
219 REQUIRE (level_ <= capacity_,
"Storage corrupted");
225 elements_[level_].destroy();
235 while (level_ < capacity_)
237 elements_[level_].template create<I>();
243 WARN (progress,
"Failure while populating ScopedCollection. " 244 "All elements will be discarded");
260 while (level_ < capacity_)
262 ElementHolder& storageFrame (elements_[level_]);
263 builder (storageFrame);
268 WARN (progress,
"Failure while populating ScopedCollection. " 269 "All elements will be discarded");
280 populate_by (
void (TY::*builder) (ElementHolder&), TY *
const instance)
282 while (level_ < capacity_)
284 ElementHolder& storageFrame (elements_[level_]);
285 (instance->*builder) (storageFrame);
290 WARN (progress,
"Failure while populating ScopedCollection. " 291 "All elements will be discarded");
312 template<
class TY =I,
typename...ARGS>
316 __ensureSufficientCapacity();
317 TY& newElm = elements_[level_].template create<TY>(std::forward<ARGS> (args)...);
327 operator[] (
size_t index)
const 330 return elements_[index].accessObj();
332 throw error::Logic (
"Attempt to access not (yet) existing object in ScopedCollection" 333 , LERR_(INDEX_BOUNDS));
348 size_t size ()
const {
return level_; }
349 size_t capacity ()
const {
return capacity_; }
350 bool empty ()
const {
return 0 == level_; }
363 typedef std::unique_ptr<ElementHolder[]> ElementStorage;
367 ElementStorage elements_;
372 __ensureSufficientCapacity()
374 if (level_ >= capacity_)
375 throw error::State (
"ScopedCollection exceeding the initially defined capacity" 389 ElementHolder* & storageLocation =
reinterpret_cast<ElementHolder* &
> (pos);
396 const ElementHolder* & storageLocation =
reinterpret_cast<const ElementHolder* &
> (pos);
401 template<
typename POS>
406 if ((pos) && (pos < src->_access_end()))
415 I* _access_begin()
const {
return & elements_[0].accessObj(); }
416 I* _access_end()
const {
return & elements_[level_].accessObj(); }
434 template<
class I,
size_t siz>
441 storage.template create<I>();
445 template<
class I,
size_t siz>
446 template<
typename TY>
453 storage.template create<TY>();
466 template<
class I,
size_t siz>
467 template<
typename IT>
472 using ElementType =
typename meta::ValueTypeBinding<IT>::value_type;
482 storage.template create<ElementType> (*iter_);
A fixed collection of non-copyable polymorphic objects.
TY & create(ARGS &&...args)
place object of type TY, forwarding ctor arguments
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.
#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.
Any copy and copy construction prohibited.
TY & emplace(ARGS &&...args)
push new entry at the end of this container and build object of type TY in place there ...
Implementation namespace for support and library code.
void populate_by(CTOR builder)
init all elements at once, invoking a builder functor for each.
Storage Frame to hold one Child object.
Derived specific exceptions within Lumiera's exception hierarchy.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
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.
void populate()
init all elements default constructed
Helpers for type detection, type rewriting and metaprogramming.
Lumiera error handling (C++ interface).
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...
static PullFrom< IT > pull(IT iter)
fills by copy-constructing values pulled from the iterator IT
fills the ScopedCollection with default constructed TY-instances
fills the ScopedCollection with default constructed I-instances
I & emplaceElement()
push a new element of default type to the end of this container
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
friend void iterNext(const ScopedCollection *, I *&pos)
Iteration-logic: switch to next position.