diff --git a/src/lib/scoped-collection.hpp b/src/lib/scoped-collection.hpp index 2c9f85d7a..0ff2d37ef 100644 --- a/src/lib/scoped-collection.hpp +++ b/src/lib/scoped-collection.hpp @@ -47,7 +47,7 @@ ** the container is being filled successively. ** - the "RAII style" usage strives to create all of the content objects ** right away, immediately after the memory allocation. This usage pattern - ** avoids any kind of "lifecylce state". Either the container comes up sane + ** avoids any kind of "lifecycle state". Either the container comes up sane ** and fully populated, or the ctor call fails and any already created ** objects are discarded. ** @note intentionally there is no operation to discard individual objects, @@ -69,13 +69,9 @@ #define LIB_SCOPED_COLLECTION_H -//#include "include/logging.h" -#include "lib/iter-adapter.hpp" #include "lib/error.hpp" -//#include "lib/util.hpp" +#include "lib/iter-adapter.hpp" -//#include -//#include #include #include #include @@ -139,7 +135,6 @@ namespace lib { #define TYPE_SANITY_CHECK \ BOOST_STATIC_ASSERT ((boost::is_base_of::value || boost::is_same::value)) - /** Abbreviation for placement new */ #define EMBEDDED_ELEMENT_CTOR(_CTOR_CALL_) \ TYPE_SANITY_CHECK; \ @@ -244,18 +239,8 @@ namespace lib { , capacity_(maxElements) , elements_(new ElementHolder[maxElements]) { - try { - while (level_ < capacity_) - { - ElementHolder& storageFrame (elements_[level_]); - builder (storageFrame); - ++level_; - }} - catch(...) - { - clear(); - throw; - } } + populate_by (builder); + } /** variation of RAII-style: using a builder function, * which is a member of some object. This supports the @@ -271,18 +256,8 @@ namespace lib { , capacity_(maxElements) , elements_(new ElementHolder[maxElements]) { - try { - while (level_ < capacity_) - { - ElementHolder& storageFrame (elements_[level_]); - (instance->*builder) (storageFrame); - ++level_; - }} - catch(...) - { - clear(); - throw; - } } + populate_by (builder,instance); + } /* == some pre-defined Builders == */ @@ -316,6 +291,7 @@ namespace lib { } } + /** init all elements default constructed */ void populate() try { @@ -333,6 +309,53 @@ namespace lib { throw; } + /** init all elements at once, + * invoking a builder functor for each. + * @param builder to 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. + */ + template + void + populate_by (CTOR builder) + try { + while (level_ < capacity_) + { + ElementHolder& storageFrame (elements_[level_]); + builder (storageFrame); + ++level_; + } } + catch(...) + { + WARN (progress, "Failure while populating ScopedCollection. " + "All elements will be discarded"); + clear(); + throw; + } + + /** variation of element initialisation, + * invoking a member function of some manager object + * for each collection element to be created. + */ + template + void + populate_by (void (TY::*builder) (ElementHolder&), TY * const instance) + try { + while (level_ < capacity_) + { + ElementHolder& storageFrame (elements_[level_]); + (instance->*builder) (storageFrame); + ++level_; + } } + catch(...) + { + WARN (progress, "Failure while populating ScopedCollection. " + "All elements will be discarded"); + clear(); + throw; + } + /** push a new element of default type diff --git a/src/proc/play/output-slot-connection.hpp b/src/proc/play/output-slot-connection.hpp index 71a830c7e..332943ae5 100644 --- a/src/proc/play/output-slot-connection.hpp +++ b/src/proc/play/output-slot-connection.hpp @@ -68,8 +68,8 @@ namespace play { using lib::transform; using lib::iter_stl::eachElm; - using std::tr1::placeholders::_1; - using std::tr1::bind; +//using std::tr1::placeholders::_1; +//using std::tr1::bind; using std::vector; //using std::tr1::shared_ptr; using boost::scoped_ptr; @@ -186,6 +186,11 @@ namespace play { protected: /* == API for OutputSlot-Impl == */ + void + init() ///< derived classes need to invoke this to build the actual connections + { + connections_.populate_by (&ConnectionStateManager::buildConnection, this); + } typedef typename Connections::ElementHolder& ConnectionStorage; @@ -195,8 +200,7 @@ namespace play { ConnectionStateManager(uint numChannels) - : connections_( numChannels - , bind (&ConnectionStateManager::buildConnection, this, _1 )) + : connections_(numChannels) { } public: diff --git a/tests/components/proc/play/diagnostic-output-slot.hpp b/tests/components/proc/play/diagnostic-output-slot.hpp index 1554ce8cf..920630856 100644 --- a/tests/components/proc/play/diagnostic-output-slot.hpp +++ b/tests/components/proc/play/diagnostic-output-slot.hpp @@ -261,7 +261,9 @@ namespace play { public: SimulatedOutputSequences (uint numChannels) : _Base(numChannels) - { } + { + init(); + } };