diff --git a/src/backend/engine/engine-config.h b/src/backend/engine/engine-config.h index 302ad867c..15459ef10 100644 --- a/src/backend/engine/engine-config.h +++ b/src/backend/engine/engine-config.h @@ -64,7 +64,7 @@ namespace engine { EngineConfig(); ~EngineConfig(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; public: /** access point to the Engine Interface. diff --git a/src/include/config-facade.h b/src/include/config-facade.h index a903b6485..a65bd986b 100644 --- a/src/include/config-facade.h +++ b/src/include/config-facade.h @@ -73,7 +73,7 @@ namespace lumiera { private: Config(); ~Config(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; }; diff --git a/src/lib/dependency-factory.hpp b/src/lib/dependency-factory.hpp index 60df2b860..cb7f47ae6 100644 --- a/src/lib/dependency-factory.hpp +++ b/src/lib/dependency-factory.hpp @@ -115,6 +115,9 @@ namespace lib { + + + private: /** pointer to the concrete function * used for building new service instances */ @@ -122,6 +125,21 @@ namespace lib { + /** function to build service instances. + * A service class with private ctor can declare DependencyFactory as friend, + * to indicate this is the expected way to create instances */ + template + static TAR* + create_in_buffer (void* buffer) + { + return new(buffer) TAR; + } + + + /** + * @internal Helper to manage a service instance within an embedded buffer. + * This helper and thus the service instance will be allocated into static memory. + */ template class InstanceHolder : boost::noncopyable @@ -156,7 +174,7 @@ namespace lib { buildInstance () { // place new instance into embedded buffer - TAR* newInstance = new(buff_) TAR; + TAR* newInstance = create_in_buffer(buff_); try { @@ -189,26 +207,30 @@ namespace lib { } - /** - * DSL-style marker function for client code - * to configure the usage of a specific subclass. - * Typically this function is used right within the - * Constructor call for lib::Depend; this allows to - * confine the actual service implementation class - * to a single compilation unit, without the need - * for clients of the respective service to know - * the actual concrete implementation class - */ template - friend InstanceConstructor - buildSingleton() - { - return & createSingletonInstance; - } + friend InstanceConstructor buildSingleton(); }; + /** + * DSL-style marker function for client code + * to configure the usage of a specific subclass. + * Typically this function is used right within the + * Constructor call for lib::Depend; this allows to + * confine the actual service implementation class + * to a single compilation unit, without the need + * for clients of the respective service to know + * the actual concrete implementation class + */ + template + inline DependencyFactory::InstanceConstructor + buildSingleton() + { + return & DependencyFactory::createSingletonInstance; + } + + } // namespace lib #endif diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index bafad229f..8043cacbf 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -102,7 +102,7 @@ namespace asset { clear(); } - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; public: diff --git a/src/proc/assetmanager.hpp b/src/proc/assetmanager.hpp index 7ddcf646e..5d6edafe9 100644 --- a/src/proc/assetmanager.hpp +++ b/src/proc/assetmanager.hpp @@ -126,7 +126,7 @@ namespace asset { AssetManager (); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; }; diff --git a/src/proc/control/stypemanager.hpp b/src/proc/control/stypemanager.hpp index db526d493..81262a4ee 100644 --- a/src/proc/control/stypemanager.hpp +++ b/src/proc/control/stypemanager.hpp @@ -79,7 +79,7 @@ namespace control { STypeManager() ; ~STypeManager(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; /** Lifecycle: reset all type registration information * to the generic pristine default state. This includes diff --git a/src/proc/engine/diagnostic-buffer-provider.hpp b/src/proc/engine/diagnostic-buffer-provider.hpp index 444ba0cc4..4f45764db 100644 --- a/src/proc/engine/diagnostic-buffer-provider.hpp +++ b/src/proc/engine/diagnostic-buffer-provider.hpp @@ -73,7 +73,7 @@ namespace engine { DiagnosticBufferProvider(); ~DiagnosticBufferProvider(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; public: /** build a new Diagnostic Buffer Provider instance, diff --git a/src/proc/mobject/session/query/fake-configrules.hpp b/src/proc/mobject/session/query/fake-configrules.hpp index 7ab8d68c1..62cb0c60f 100644 --- a/src/proc/mobject/session/query/fake-configrules.hpp +++ b/src/proc/mobject/session/query/fake-configrules.hpp @@ -283,7 +283,7 @@ namespace session { { protected: MockConfigRules (); ///< to be used only by the singleton factory - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; virtual ~MockConfigRules() {} diff --git a/src/proc/mobject/session/scope-locator.hpp b/src/proc/mobject/session/scope-locator.hpp index bec11aee9..6ce261308 100644 --- a/src/proc/mobject/session/scope-locator.hpp +++ b/src/proc/mobject/session/scope-locator.hpp @@ -94,7 +94,7 @@ namespace session { protected: ScopeLocator(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; private: lumiera::QueryResolver const& theResolver(); diff --git a/src/proc/mobject/session/sess-manager-impl.hpp b/src/proc/mobject/session/sess-manager-impl.hpp index a39f903cd..120d8a663 100644 --- a/src/proc/mobject/session/sess-manager-impl.hpp +++ b/src/proc/mobject/session/sess-manager-impl.hpp @@ -47,7 +47,7 @@ namespace session { scoped_ptr lifecycle_; SessManagerImpl() throw(); - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; ~SessManagerImpl() ; diff --git a/src/proc/play/output-director.hpp b/src/proc/play/output-director.hpp index a9cd9a217..56e2cb431 100644 --- a/src/proc/play/output-director.hpp +++ b/src/proc/play/output-director.hpp @@ -88,7 +88,7 @@ namespace play { private: OutputDirector() ; ~OutputDirector() ; - friend class lib::DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; void bringDown (SigTerm completedSignal); diff --git a/tests/library/singleton-subclass-test.cpp b/tests/library/singleton-subclass-test.cpp index ef75ee781..a747cb796 100644 --- a/tests/library/singleton-subclass-test.cpp +++ b/tests/library/singleton-subclass-test.cpp @@ -62,7 +62,7 @@ namespace test{ Interface () : TestTargetObj(cnt) {} virtual ~Interface() {} - friend class DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; }; int Interface::cnt = 0; diff --git a/tests/library/singleton-test.cpp b/tests/library/singleton-test.cpp index 4c82c17d1..a4086f7bd 100644 --- a/tests/library/singleton-test.cpp +++ b/tests/library/singleton-test.cpp @@ -58,7 +58,7 @@ namespace test{ protected: TargetObj () : TestTargetObj(cnt) {} - friend class DependencyFactory::InstanceHolder; + friend class lib::DependencyFactory; }; int TargetObj::cnt = 0;