diff --git a/src/lib/muttifac.hpp b/src/lib/muttifac.hpp index c7233d499..aade9423b 100644 --- a/src/lib/muttifac.hpp +++ b/src/lib/muttifac.hpp @@ -89,6 +89,8 @@ namespace lib { template struct PassAsIs { + typedef TAR RawType; + typedef TAR BareType; typedef TAR ResultType; template @@ -107,7 +109,9 @@ namespace lib { template struct BuildRefcountPtr { - typedef std::shared_ptr ResultType; + using RawType = typename std::remove_pointer::type; + using BareType = RawType *; + using ResultType = std::shared_ptr; template ResultType @@ -169,11 +173,11 @@ namespace lib { > struct FabConfig { - using FabProduct = TY; using WrapFunctor = Wrapper; + using BareProduct = typename WrapFunctor::BareType; using WrappedProduct = typename WrapFunctor::ResultType; - typedef FabProduct SIG_Fab(void); + typedef BareProduct SIG_Fab(void); }; @@ -249,13 +253,13 @@ namespace lib { class Singleton : lib::Depend { - typedef lib::Depend SingFac; + typedef lib::Depend SingleFac; Creator createSingleton_accessFunction() { - return std::bind (&SingFac::operator() - , static_cast(this)); + return std::bind (&SingleFac::operator() + , static_cast(this)); } public: diff --git a/tests/library/multifact-test.cpp b/tests/library/multifact-test.cpp index a6fab8c53..86a29dd12 100644 --- a/tests/library/multifact-test.cpp +++ b/tests/library/multifact-test.cpp @@ -200,6 +200,39 @@ namespace test{ void produce_smart_pointers() { + using TestFactory = factory::MuttiFac; + using PIfa = shared_ptr; + + TestFactory theFact; + + // the first "production line" is wired to a free function + theFact.defineProduction (ONE, [] { return new Implementation; }); + theFact.defineProduction (TWO, [] { return new Implementation; }); + theFact.defineProduction (THR, [] { return new Implementation; }); + theFact.defineProduction (FOU, [] { return new Implementation; }); + CHECK (!isnil (theFact)); + + PIfa p1 = theFact(ONE); + PIfa p2 = theFact(TWO); + PIfa p3 = theFact(THR); + PIfa p4 = theFact(FOU); + + PIfa p11 = theFact(ONE); + + CHECK ("Impl-1" == string(*p1)); + CHECK ("Impl-2" == string(*p2)); + CHECK ("Impl-3" == string(*p3)); + CHECK ("Impl-4" == string(*p4)); + + CHECK ("Impl-1" == string(*p11)); + CHECK (!isSameObject(*p1, *p11)); + + PIfa p12(p11); + CHECK (isSameObject(*p11, *p12)); + CHECK ("Impl-1" == string(*p12)); + CHECK (1 == p1.use_count()); + CHECK (2 == p11.use_count()); + CHECK (2 == p12.use_count()); }