From edbf5fd7337bf94ca653e31a6f70ae967021c65d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 1 Feb 2008 15:35:33 +0100 Subject: [PATCH] ConfigRules dependency problems solved by using the new SingletonSubclassFactory --- src/common/configrules.cpp | 11 ++++++++- src/common/configrules.hpp | 31 ++++++++++++------------ src/common/singletonsubclass.hpp | 15 ++++++++++-- src/proc/mobject/session/defsmanager.cpp | 5 ++-- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/common/configrules.cpp b/src/common/configrules.cpp index d72608035..244e88d5f 100644 --- a/src/common/configrules.cpp +++ b/src/common/configrules.cpp @@ -40,9 +40,18 @@ namespace cinelerra ConfigRulesInterface::~ConfigRulesInterface() { }; + } // namespace query - + + namespace + { + /** type of the actual ConfigRules implementation to use */ + singleton::UseSubclass typeinfo; + } + + /** Singleton factory instance, parametrized to actual impl. type. */ + SingletonSub ConfigRules::instance (typeinfo); } // namespace cinelerra diff --git a/src/common/configrules.hpp b/src/common/configrules.hpp index e17914187..ed682e140 100644 --- a/src/common/configrules.hpp +++ b/src/common/configrules.hpp @@ -47,8 +47,8 @@ #define CINELERRA_CONFIGRULES_H #include "common/query.hpp" -#include "common/singleton.hpp" #include "common/typelist.hpp" +#include "common/singletonsubclass.hpp" #include "proc/mobject/session/track.hpp" #include "proc/asset/procpatt.hpp" @@ -65,7 +65,6 @@ namespace cinelerra using std::string; using std::tr1::shared_ptr; - namespace query { class MockConfigRules; } // TODO: need a better way to return a sub-type from a singleton @@ -163,26 +162,18 @@ namespace cinelerra { }; - template - < typename TYPES, - class IMPL - > + template class ConfigRules : public ConfigRulesInterface { protected: ConfigRules () {} virtual ~ConfigRules() {} - - public: - static cinelerra::Singleton instance; + public: // TODO: find out what operations we need to support here for the »real solution« (using Prolog) }; - /** storage for the Singleton instance factory */ - template - cinelerra::Singleton ConfigRules::instance; @@ -206,10 +197,18 @@ namespace cinelerra > InterfaceTypes; - typedef query::ConfigRules< InterfaceTypes, // List of Types to generate interface functions - query::MockConfigRules // actual Implementation to use - > - ConfigRules; // user-visible Interface to the ConfigRules subsystem. + /** + * user-visible Interface to the ConfigRules subsystem. + * Configured as Singleton (with hidden Implementation class) + */ + class ConfigRules + : public query::ConfigRules + { + + public: + static SingletonSub instance; + + }; } // namespace cinelerra diff --git a/src/common/singletonsubclass.hpp b/src/common/singletonsubclass.hpp index 90b26a6b5..8877ba6bf 100644 --- a/src/common/singletonsubclass.hpp +++ b/src/common/singletonsubclass.hpp @@ -135,7 +135,7 @@ namespace cinelerra * needs to know the actual class, because it allocates storage) */ template - SingletonSubclassFactory (singleton::UseSubclass) + SingletonSubclassFactory (singleton::UseSubclass&) { typedef typename singleton::Adapter Adapter; typedef typename Adapter::template TypedLink TypedLink; @@ -154,7 +154,18 @@ namespace cinelerra }; - + /** + * Default Singleton configuration (subclass creating factory) + * @note all Policy template parameters taking default values + */ + template + struct SingletonSub + : public SingletonSubclassFactory + { + template + SingletonSub (TY ref) : SingletonSubclassFactory(ref) {} + }; + } // namespace cinelerra diff --git a/src/proc/mobject/session/defsmanager.cpp b/src/proc/mobject/session/defsmanager.cpp index 2851ea235..5880bc1b3 100644 --- a/src/proc/mobject/session/defsmanager.cpp +++ b/src/proc/mobject/session/defsmanager.cpp @@ -25,7 +25,6 @@ #include "proc/asset/procpatt.hpp" #include "proc/asset/port.hpp" #include "common/configrules.hpp" -#include "common/query/mockconfigrules.hpp" // TODO: better way to handle the includes (rework singleton template?) #include "common/error.hpp" #include @@ -38,6 +37,7 @@ using asset::ProcPatt; using asset::PProcPatt; using cinelerra::ConfigRules; +using cinelerra::query::QueryHandler; using cinelerra::query::CINELERRA_ERROR_CAPABILITY_QUERY; namespace mobject @@ -56,7 +56,8 @@ namespace mobject shared_ptr DefsManager::operator() (const Query& capabilities) { - shared_ptr res = cinelerra::ConfigRules::instance().resolve (capabilities); + QueryHandler& typeHandler = ConfigRules::instance(); + shared_ptr res = typeHandler.resolve (capabilities); if (!res) throw cinelerra::error::Config ( str(format("The following Query could not be resolved: %s.")