From d064623bab145dd68c80e8acdf4f33bb242fcb33 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 14 Sep 2014 23:58:05 +0200 Subject: [PATCH] Reworked MultiFact(#388): switch in the new implementation --- src/common/query/query-resolver.cpp | 9 +++--- src/lib/{muttifac.hpp => multifact.hpp} | 6 ++-- src/proc/control/handling-patterns.hpp | 2 +- .../placement-index-query-resolver.hpp | 4 +-- tests/40core.tests | 2 +- tests/library/multifact-argument-test.cpp | 2 +- tests/library/multifact-singleton-test.cpp | 30 +++++++++++-------- tests/library/multifact-test.cpp | 25 +++++++--------- 8 files changed, 41 insertions(+), 39 deletions(-) rename src/lib/{muttifac.hpp => multifact.hpp} (98%) diff --git a/src/common/query/query-resolver.cpp b/src/common/query/query-resolver.cpp index 210877a11..f6bdbbf60 100644 --- a/src/common/query/query-resolver.cpp +++ b/src/common/query/query-resolver.cpp @@ -21,7 +21,7 @@ * *****************************************************/ -#include "lib/multifact-arg.hpp" +#include "lib/multifact.hpp" #include "common/query/query-resolver.hpp" namespace lumiera { @@ -53,15 +53,16 @@ namespace lumiera { /** factory used as dispatcher table * for resolving typed queries */ - typedef MultiFact< Resolution(Goal const&) // nominal signature of fabrication + typedef MultiFact< Resolution*(Goal const&) // raw signature of fabrication , Goal::QueryID // select resolution function by kind-of-Query , BuildRefcountPtr // wrapper: manage result set by smart-ptr > DispatcherTable; // /** PImpl of the generic QueryResolver */ - struct QueryDispatcher - : DispatcherTable + class QueryDispatcher + : public DispatcherTable { + public: PReso handle (Goal const& query) diff --git a/src/lib/muttifac.hpp b/src/lib/multifact.hpp similarity index 98% rename from src/lib/muttifac.hpp rename to src/lib/multifact.hpp index c63d31fa2..37b6fdb79 100644 --- a/src/lib/muttifac.hpp +++ b/src/lib/multifact.hpp @@ -334,13 +334,13 @@ namespace lib { class Singleton : lib::Depend { - typedef lib::Depend SingleFac; + typedef lib::Depend SingleFact; Creator createSingleton_accessFunction() { - return std::bind (&SingleFac::operator() - , static_cast(this)); + return std::bind (&SingleFact::operator() + , static_cast(this)); } public: diff --git a/src/proc/control/handling-patterns.hpp b/src/proc/control/handling-patterns.hpp index fdd8948c6..b5eb0520e 100644 --- a/src/proc/control/handling-patterns.hpp +++ b/src/proc/control/handling-patterns.hpp @@ -210,7 +210,7 @@ namespace control { /* ======== Handling Pattern Table ========== */ - typedef lib::MultiFact HandlingPatternFactory; + typedef lib::factory::MultiFact HandlingPatternFactory; /** holds singleton pattern instances by ID */ HandlingPatternFactory patternTable; diff --git a/src/proc/mobject/session/placement-index-query-resolver.hpp b/src/proc/mobject/session/placement-index-query-resolver.hpp index 647a437bb..c786bf5bd 100644 --- a/src/proc/mobject/session/placement-index-query-resolver.hpp +++ b/src/proc/mobject/session/placement-index-query-resolver.hpp @@ -94,9 +94,9 @@ namespace session { function _getIndex; - virtual bool canHandleQuery(Goal::QueryID const&) const; + virtual bool canHandleQuery(Goal::QueryID const&) const override; - virtual operator string() const { return "PlacementIndex"; } + virtual operator string() const override { return "PlacementIndex"; } Explorer* setupExploration (PlacementIndex::ID startID, ScopeQueryKind direction); diff --git a/tests/40core.tests b/tests/40core.tests index 8e6e98eef..e0a71338c 100644 --- a/tests/40core.tests +++ b/tests/40core.tests @@ -385,7 +385,7 @@ out: Impl-1 out: Impl-2 out: Impl-3 out: Impl-4 -out: sizeof\( .+MultiFact.+Interface.+theID.+PassReference.+ \) = +out: sizeof\( .+MultiFact.+Interface.+theID.+PassAsIs.+ \) = return: 0 END diff --git a/tests/library/multifact-argument-test.cpp b/tests/library/multifact-argument-test.cpp index 26a1f0cc6..a115fb141 100644 --- a/tests/library/multifact-argument-test.cpp +++ b/tests/library/multifact-argument-test.cpp @@ -23,7 +23,7 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" -#include "lib/multifact-arg.hpp" +#include "lib/multifact.hpp" #include #include diff --git a/tests/library/multifact-singleton-test.cpp b/tests/library/multifact-singleton-test.cpp index e8fea66d1..6bc9e1978 100644 --- a/tests/library/multifact-singleton-test.cpp +++ b/tests/library/multifact-singleton-test.cpp @@ -1,5 +1,5 @@ /* - MultiFactSingleton(Test) - using lib::multifact to manage a family of singletons + MultiFactSingleton(Test) - using MultiFact to manage a family of singletons Copyright (C) Lumiera.org 2009, Hermann Vosseler @@ -65,20 +65,17 @@ namespace test{ , FOU }; - typedef factory::MultiFact TestFactory; + typedef factory::MultiFact TestFactory; template class Implementation : public Interface { - operator string() + operator string() override { return "Impl-"+lexical_cast (ii); } - - public: - static theID getTypeID() { return ii; } }; /** Factory instance for the tests... */ @@ -95,12 +92,21 @@ namespace test{ - /***************************************************************//** - * @test verify simple setup of the MultiFact template. - * Define a hierarchy of test dummy objects, in order to - * register them automatically for creation through a suitable - * instantiation of MultiFact. Verify we get the correct product - * when invoking this MultiFac flavour. + /******************************************************************//** + * @test verify the use of the MultiFact template to access Singletons. + * While generally speaking the MultiFact allows us to address + * and invoke several "production lines" by ID, an obvious + * use case would be to access a "family" of singletons + * through this mechanism. And indeed, \c MultiFact::Singleton + * is a preconfigured shortcut for this use case. The actual + * singleton access factories are placed into a static context + * (here in the anonymous namespace above) and their access + * operation is wired as "factory function". + * - we use a hierarchy of test dummy objects + * - we set up a singleton factory for several subclasses + * - the registration happens automatically in the ctor + * - we verify that we indeed get the correct flavour. + * * @see lib::MultiFact */ class MultiFactSingleton_test : public Test diff --git a/tests/library/multifact-test.cpp b/tests/library/multifact-test.cpp index f850e0159..55e0e84fd 100644 --- a/tests/library/multifact-test.cpp +++ b/tests/library/multifact-test.cpp @@ -1,8 +1,8 @@ /* - MultiFact(Test) - unittest for the configurable object-family creating factory + MultiFact(Test) - cover the configurable object-family creating factory Copyright (C) Lumiera.org - 2009, Hermann Vosseler + 2014, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -23,11 +23,10 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" -#include "lib/muttifac.hpp" +#include "lib/multifact.hpp" #include "lib/util.hpp" #include -//#include #include #include @@ -37,15 +36,12 @@ namespace lib { namespace test{ using boost::lexical_cast; -// using lib::test::showSizeof; using util::isSameObject; using util::isnil; -// using std::ostream; - using std::string; + using std::function; + using std::string; using std::bind; -// using std::cout; -// using std::endl; using lumiera::error::LUMIERA_ERROR_INVALID; @@ -58,7 +54,6 @@ namespace test{ virtual operator string () =0; }; -// inline ostream& operator<< (ostream& os, Interface& ifa) { return os << string(ifa); } enum theID @@ -107,7 +102,7 @@ namespace test{ - /*************************************************************************//** + /******************************************************************************//** * @test verify the basic usage patterns of the configurable factory template. * - Depending on the concrete fabrication signature, the factory can produce * "things" by invoking suitable fabrication functions. These functions @@ -142,7 +137,7 @@ namespace test{ void produce_simple_values() { - using TestFactory = factory::MuttiFac; + using TestFactory = factory::MultiFact; TestFactory theFact; @@ -204,7 +199,7 @@ namespace test{ void produce_smart_pointers() { - using TestFactory = factory::MuttiFac; + using TestFactory = factory::MultiFact; using PIfa = shared_ptr; TestFactory theFact; @@ -243,7 +238,7 @@ namespace test{ void pass_additional_arguments() { - using TestFactory = factory::MuttiFac; + using TestFactory = factory::MultiFact; TestFactory theFact; @@ -287,7 +282,7 @@ namespace test{ void fed_a_custom_finishing_functor() { - using TestFactory = factory::MuttiFac::Wrapper>; + using TestFactory = factory::MultiFact::Wrapper>; TestFactory theFact;