Reworked MultiFact(#388): switch in the new implementation

This commit is contained in:
Fischlurch 2014-09-14 23:58:05 +02:00
parent 9a5d9873c8
commit d064623bab
8 changed files with 41 additions and 39 deletions

View file

@ -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)

View file

@ -334,13 +334,13 @@ namespace lib {
class Singleton
: lib::Depend<IMP>
{
typedef lib::Depend<IMP> SingleFac;
typedef lib::Depend<IMP> SingleFact;
Creator
createSingleton_accessFunction()
{
return std::bind (&SingleFac::operator()
, static_cast<SingleFac*>(this));
return std::bind (&SingleFact::operator()
, static_cast<SingleFact*>(this));
}
public:

View file

@ -210,7 +210,7 @@ namespace control {
/* ======== Handling Pattern Table ========== */
typedef lib::MultiFact<HandlingPattern, HandlingPattern::ID> HandlingPatternFactory;
typedef lib::factory::MultiFact<HandlingPattern&, HandlingPattern::ID> HandlingPatternFactory;
/** holds singleton pattern instances by ID */
HandlingPatternFactory patternTable;

View file

@ -94,9 +94,9 @@ namespace session {
function<IndexLink> _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);

View file

@ -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

View file

@ -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 <iostream>
#include <functional>

View file

@ -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 <Ichthyostega@web.de>
@ -65,20 +65,17 @@ namespace test{
, FOU
};
typedef factory::MultiFact<Interface, theID, factory::PassReference> TestFactory;
typedef factory::MultiFact<Interface&, theID> TestFactory;
template<theID ii>
class Implementation
: public Interface
{
operator string()
operator string() override
{
return "Impl-"+lexical_cast<string> (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

View file

@ -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 <Ichthyostega@web.de>
2014, Hermann Vosseler <Ichthyostega@web.de>
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 <boost/lexical_cast.hpp>
//#include <iostream>
#include <functional>
#include <string>
@ -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<string, theID>;
using TestFactory = factory::MultiFact<string, theID>;
TestFactory theFact;
@ -204,7 +199,7 @@ namespace test{
void
produce_smart_pointers()
{
using TestFactory = factory::MuttiFac<Interface, theID, factory::BuildRefcountPtr>;
using TestFactory = factory::MultiFact<Interface, theID, factory::BuildRefcountPtr>;
using PIfa = shared_ptr<Interface>;
TestFactory theFact;
@ -243,7 +238,7 @@ namespace test{
void
pass_additional_arguments()
{
using TestFactory = factory::MuttiFac<Interface*(string), theID>;
using TestFactory = factory::MultiFact<Interface*(string), theID>;
TestFactory theFact;
@ -287,7 +282,7 @@ namespace test{
void
fed_a_custom_finishing_functor()
{
using TestFactory = factory::MuttiFac<int(int), theID, factory::Build<long>::Wrapper>;
using TestFactory = factory::MultiFact<int(int), theID, factory::Build<long>::Wrapper>;
TestFactory theFact;