Lumiera  0.pre.03
»edit your freedom«
ScopedCollection< I, siz > Class Template Reference

#include "lib/scoped-collection.hpp"

Description

template<class I, size_t siz = sizeof(I)>
class lib::ScopedCollection< I, siz >

A fixed collection of non-copyable polymorphic objects.

All child objects reside in a common chunk of storage and are owned and managed by this collection holder. Array style access and iteration is provided.

Template Parameters
Ithe nominal Base/Interface class for a family of types
sizmaximum storage required for the targets to be held inline

Definition at line 94 of file scoped-collection.hpp.

Public Types

using const_iterator = IterAdapter< const I *, const ScopedCollection * >
 
using iterator = IterAdapter< I *, const ScopedCollection * >
 

Public Member Functions

 ScopedCollection (size_t maxElements)
 
template<class CTOR >
 ScopedCollection (size_t maxElements, CTOR builder)
 creating a ScopedCollection in RAII-style: The embedded elements will be created immediately. More...
 
template<class TY >
 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. More...
 
iterator begin ()
 
const_iterator begin () const
 
size_t capacity () const
 
void clear ()
 
template<class TY = I, typename... ARGS>
TY & emplace (ARGS &&...args)
 push new entry at the end of this container and build object of type TY in place there
 
I & emplaceElement ()
 push a new element of default type to the end of this container More...
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
I & operator[] (size_t index) const
 
void populate ()
 init all elements default constructed
 
template<class CTOR >
void populate_by (CTOR builder)
 init all elements at once, invoking a builder functor for each. More...
 
template<class TY >
void populate_by (void(TY::*builder)(ElementHolder &), TY *const instance)
 variation of element initialisation, invoking a member function of some manager object for each collection element to be created.
 
size_t size () const
 

Static Public Member Functions

template<typename IT >
static PullFrom< IT > pull (IT iter)
 fills by copy-constructing values pulled from the iterator IT More...
 

Classes

class  ElementHolder
 Storage Frame to hold one Child object. More...
 
class  FillAll
 
class  FillWith
 fills the ScopedCollection with default constructed I-instances More...
 
class  PullFrom
 fills the ScopedCollection with default constructed TY-instances More...
 

Friends

iterator begin (ScopedCollection &sco)
 
const iterator begin (ScopedCollection const &sco)
 
template<typename POS >
bool checkPoint (const ScopedCollection *src, POS &pos)
 Iteration-logic: detect iteration end. More...
 
iterator end (ScopedCollection &sco)
 
const iterator end (ScopedCollection const &sco)
 
void iterNext (const ScopedCollection *, I *&pos)
 Iteration-logic: switch to next position. More...
 
void iterNext (const ScopedCollection *, const I *&pos)
 

Private Types

typedef std::unique_ptr< ElementHolder[]> ElementStorage
 

Private Member Functions

void __ensureSufficientCapacity ()
 
I * _access_begin () const
 
I * _access_end () const
 
- Private Member Functions inherited from NonCopyable
 NonCopyable (NonCopyable const &)=delete
 
NonCopyableoperator= (NonCopyable const &)=delete
 

Private Attributes

size_t capacity_
 
ElementStorage elements_
 
size_t level_
 

Constructor & Destructor Documentation

◆ ScopedCollection() [1/2]

ScopedCollection ( size_t  maxElements,
CTOR  builder 
)
inline

creating a ScopedCollection in RAII-style: The embedded elements will be created immediately.

Ctor fails in case of any error during element creation.

Parameters
builderfunctor to be invoked for each "slot". It gets an ElementHolder& as parameter, and should use this to create an object of some I-subclass

Definition at line 166 of file scoped-collection.hpp.

◆ ScopedCollection() [2/2]

ScopedCollection ( size_t  maxElements,
void(TY::*)(ElementHolder &)  builder,
TY *const  instance 
)
inline

variation of RAII-style: using a builder function, which is a member of some object.

This supports the typical usage situation, where a manager object builds a ScopedCollection of some components

Parameters
buildermember function used to create the elements
instancethe owning class instance, on which the builder member function will be invoked ("this").

Definition at line 183 of file scoped-collection.hpp.

Member Function Documentation

◆ pull()

static PullFrom<IT> pull ( IT  iter)
inlinestatic

fills by copy-constructing values pulled from the iterator IT

Parameters
iterconvenience shortcut to pull from any given Lumiera Forward Iterator

Definition at line 203 of file scoped-collection.hpp.

◆ populate_by()

void populate_by ( CTOR  builder)
inline

init all elements at once, invoking a builder functor for each.

Parameters
builderto create the individual elements this functor is responsible to invoke the appropriate ElementHolder::create function, which places a new element into the storage frame passed as parameter.

Definition at line 250 of file scoped-collection.hpp.

◆ emplaceElement()

I& emplaceElement ( )
inline

push a new element of default type to the end of this container

Note
EX_STRONG

Definition at line 294 of file scoped-collection.hpp.

Referenced by ScopedCollection_test::building_StackStyle().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ iterNext

void iterNext ( const ScopedCollection< I, siz > *  ,
I *&  pos 
)
friend

Iteration-logic: switch to next position.

Note
assuming here that the start address of the embedded object coincides with the start of an array element (ElementHolder)

Definition at line 379 of file scoped-collection.hpp.

◆ checkPoint

bool checkPoint ( const ScopedCollection< I, siz > *  src,
POS &  pos 
)
friend

Iteration-logic: detect iteration end.

Definition at line 395 of file scoped-collection.hpp.

+ Inheritance diagram for ScopedCollection< I, siz >:
+ Collaboration diagram for ScopedCollection< I, siz >:

The documentation for this class was generated from the following file: