tabs/space

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@193 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-07-28 14:13:46 +00:00
parent 9e4ea0178b
commit da325e4b8e
4 changed files with 358 additions and 352 deletions

View file

@ -12,7 +12,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Header: // $Header:
#ifndef FACTORYPARM_INC_ #ifndef FACTORYPARM_INC_
#define FACTORYPARM_INC_ #define FACTORYPARM_INC_
@ -24,7 +24,7 @@
namespace Loki namespace Loki
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// class template DefaultFactoryError // class template DefaultFactoryError
// Manages the "Unknown Type" error in an object factory // Manages the "Unknown Type" error in an object factory
@ -43,18 +43,18 @@ namespace Loki
throw Exception(); throw Exception();
} }
}; };
//#define ENABLE_FACTORY_BOOK_VERSION_ONLY //#define ENABLE_FACTORY_BOOK_VERSION_ONLY
#ifndef ENABLE_FACTORY_BOOK_VERSION_ONLY #ifndef ENABLE_FACTORY_BOOK_VERSION_ONLY
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/* /*
class template Factory class template Factory
Implements a generic object factory Implements a generic object factory
cretae functions with up to 15 parameters cretae functions with up to 15 parameters
template template
< <
class AbstractProduct, class AbstractProduct,
@ -95,7 +95,7 @@ namespace Loki
// class template FunctorImpl // class template FunctorImpl
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
struct FactoryImplBase struct FactoryImplBase
{ {
typedef EmptyType Parm1; typedef EmptyType Parm1;
typedef EmptyType Parm2; typedef EmptyType Parm2;
@ -441,14 +441,14 @@ namespace Loki
typedef typename Impl::Parm14 Parm14; typedef typename Impl::Parm14 Parm14;
typedef typename Impl::Parm15 Parm15; typedef typename Impl::Parm15 Parm15;
Factory() Factory()
{ {
} }
~Factory() ~Factory()
{ {
associations_.erase(associations_.begin(), associations_.end()); associations_.erase(associations_.begin(), associations_.end());
} }
typedef typename IdToProductMap::iterator iterator; typedef typename IdToProductMap::iterator iterator;
@ -472,7 +472,7 @@ namespace Loki
{ {
ProductCreator creator( p, fn ); ProductCreator creator( p, fn );
return associations_.insert( return associations_.insert(
typename IdToProductMap::value_type(id, creator)).second != 0; typename IdToProductMap::value_type(id, creator)).second != 0;
} }
@ -745,3 +745,6 @@ namespace Loki
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#endif // FACTORY_INC_ #endif // FACTORY_INC_
// $Log:

View file

@ -13,16 +13,16 @@
#if defined(CLASS_LEVEL_THREADING) || defined(OBJECT_LEVEL_THREADING) #if defined(CLASS_LEVEL_THREADING) || defined(OBJECT_LEVEL_THREADING)
// threads only on windows // threads only on windows
#include <windows.h> #include <windows.h>
#define SINGLETON_DEFAULT_THREADING ::Loki::ClassLevelLockable #define SINGLETON_DEFAULT_THREADING ::Loki::ClassLevelLockable
#if defined(CLASS_LEVEL_THREADING) #if defined(CLASS_LEVEL_THREADING)
#define DEFAULT_THREADING ::Loki::ClassLevelLockable #define DEFAULT_THREADING ::Loki::ClassLevelLockable
#else #else
#define DEFAULT_THREADING ::Loki::ObjectLevelLockable #define DEFAULT_THREADING ::Loki::ObjectLevelLockable
#endif #endif
#else #else
#define DEFAULT_THREADING ::Loki::SingleThreaded #define DEFAULT_THREADING ::Loki::SingleThreaded
#endif #endif
#include <cassert> #include <cassert>
@ -220,7 +220,8 @@ namespace Loki
// July 26, 2005: some asserts by Peter Kümmel // July 26, 2005: some asserts by Peter Kümmel
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Log:
#endif #endif
// $Log:

View file

@ -32,362 +32,362 @@ using Loki::SingletonHolder;
namespace FactoryTestParmPrivate namespace FactoryTestParmPrivate
{ {
class AbstractProduct class AbstractProduct
{ {
}; };
class Product : public AbstractProduct class Product : public AbstractProduct
{ {
public: public:
Product() Product()
{} {}
Product(int) Product(int)
{} {}
Product(int, int) Product(int, int)
{} {}
Product(int, int, int) Product(int, int, int)
{} {}
Product(int, int, int, int) Product(int, int, int, int)
{} {}
Product(int, int, int, int, int) Product(int, int, int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int) int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int) int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int) int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int) int, int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int) int, int, int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int) int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int) int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int) int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int) int, int, int, int)
{} {}
Product(int, int, int, int, int, Product(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int) int, int, int, int, int)
{} {}
}; };
template< class T> template< class T>
class CreatorClass class CreatorClass
{ {
public: public:
CreatorClass() CreatorClass()
{ {
} }
T* create0() T* create0()
{ {
return new T; return new T;
} }
T* create1( int) T* create1( int)
{ {
return new T(1); return new T(1);
} }
T* create2( int, int) T* create2( int, int)
{ {
return new T(1,2); return new T(1,2);
} }
T* create3( int, int, int) T* create3( int, int, int)
{ {
return new T(1,2,3); return new T(1,2,3);
} }
T* create4( int, int, int, int) T* create4( int, int, int, int)
{ {
return new T(1,2,3,4); return new T(1,2,3,4);
} }
T* create5( int, int, int, int, int) T* create5( int, int, int, int, int)
{ {
return new T(1,2,3,4,5); return new T(1,2,3,4,5);
} }
T* create6( int, int, int, int, int, T* create6( int, int, int, int, int,
int) int)
{ {
return new T(1,2,3,4,5,6); return new T(1,2,3,4,5,6);
} }
T* create7( int, int, int, int, int, T* create7( int, int, int, int, int,
int, int) int, int)
{ {
return new T(1,2,3,4,5,6,7); return new T(1,2,3,4,5,6,7);
} }
T* create8( int, int, int, int, int, T* create8( int, int, int, int, int,
int, int, int) int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8); return new T(1,2,3,4,5,6,7,8);
} }
T* create9( int, int, int, int, int, T* create9( int, int, int, int, int,
int, int, int, int) int, int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9); return new T(1,2,3,4,5,6,7,8,9);
} }
T* create10(int, int, int, int, int, T* create10(int, int, int, int, int,
int, int, int, int, int) int, int, int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10); return new T(1,2,3,4,5,6,7,8,9,10);
} }
T* create11(int, int, int, int, int, T* create11(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int) int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10,11); return new T(1,2,3,4,5,6,7,8,9,10,11);
} }
T* create12(int, int, int, int, int, T* create12(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int) int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10,11,12); return new T(1,2,3,4,5,6,7,8,9,10,11,12);
} }
T* create13(int, int, int, int, int, T* create13(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int) int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10,11,12,13); return new T(1,2,3,4,5,6,7,8,9,10,11,12,13);
} }
T* create14(int, int, int, int, int, T* create14(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int) int, int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14); return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14);
} }
T* create15(int, int, int, int, int, T* create15(int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int) int, int, int, int, int)
{ {
return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
} }
}; };
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int > Factory< AbstractProduct, int >
>Factory0; >Factory0;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_1( int ) > Factory< AbstractProduct, int, TYPELIST_1( int ) >
>Factory1; >Factory1;
typedef SingletonHolder< typedef SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_2( int, int ) > Factory< AbstractProduct, int, TYPELIST_2( int, int ) >
>Factory2; >Factory2;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_3( int, int, int ) > Factory< AbstractProduct, int, TYPELIST_3( int, int, int ) >
>Factory3; >Factory3;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_4( int, int, int, int ) > Factory< AbstractProduct, int, TYPELIST_4( int, int, int, int ) >
>Factory4; >Factory4;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_5( int, int, int, int, int ) > Factory< AbstractProduct, int, TYPELIST_5( int, int, int, int, int ) >
>Factory5; >Factory5;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_6( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_6( int, int, int, int, int,
int ) > int ) >
>Factory6; >Factory6;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_7( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_7( int, int, int, int, int,
int, int ) > int, int ) >
>Factory7; >Factory7;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_8( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_8( int, int, int, int, int,
int, int, int ) > int, int, int ) >
>Factory8; >Factory8;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_9( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_9( int, int, int, int, int,
int, int, int, int ) > int, int, int, int ) >
>Factory9; >Factory9;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_10( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_10( int, int, int, int, int,
int, int, int, int, int ) > int, int, int, int, int ) >
>Factory10; >Factory10;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_11( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_11( int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int ) > int ) >
>Factory11; >Factory11;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_12( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_12( int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int ) > int, int ) >
>Factory12; >Factory12;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_13( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_13( int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int ) > int, int, int ) >
>Factory13; >Factory13;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_14( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_14( int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int ) > int, int, int, int ) >
>Factory14; >Factory14;
typedef typedef
SingletonHolder< SingletonHolder<
Factory< AbstractProduct, int, TYPELIST_15( int, int, int, int, int, Factory< AbstractProduct, int, TYPELIST_15( int, int, int, int, int,
int, int, int, int, int, int, int, int, int, int,
int, int, int, int, int ) > int, int, int, int, int ) >
>Factory15; >Factory15;
CreatorClass<Product> creaClass; CreatorClass<Product> creaClass;
bool registerAll(){ bool registerAll(){
bool const o0 = Factory0::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create0 ); bool const o0 = Factory0::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create0 );
bool const o1 = Factory1::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create1 ); bool const o1 = Factory1::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create1 );
bool const o2 = Factory2::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create2 ); bool const o2 = Factory2::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create2 );
bool const o3 = Factory3::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create3 ); bool const o3 = Factory3::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create3 );
bool const o4 = Factory4::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create4 ); bool const o4 = Factory4::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create4 );
bool const o5 = Factory5::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create5 ); bool const o5 = Factory5::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create5 );
bool const o6 = Factory6::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create6 ); bool const o6 = Factory6::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create6 );
bool const o7 = Factory7::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create7 ); bool const o7 = Factory7::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create7 );
bool const o8 = Factory8::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create8 ); bool const o8 = Factory8::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create8 );
bool const o9 = Factory9::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create9 ); bool const o9 = Factory9::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create9 );
bool const o10 = Factory10::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create10 ); bool const o10 = Factory10::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create10 );
bool const o11 = Factory11::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create11 ); bool const o11 = Factory11::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create11 );
bool const o12 = Factory12::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create12 ); bool const o12 = Factory12::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create12 );
bool const o13 = Factory13::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create13 ); bool const o13 = Factory13::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create13 );
bool const o14 = Factory14::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create14 ); bool const o14 = Factory14::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create14 );
bool const o15 = Factory15::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create15 ); bool const o15 = Factory15::Instance().Register( 1, &creaClass, &CreatorClass<Product>::create15 );
return o0 && o1 && o2 && o3 && o4 && o5 && o6 && o7 && o8 && o9 && o10 && o11 && o13 && o14 && o15; return o0 && o1 && o2 && o3 && o4 && o5 && o6 && o7 && o8 && o9 && o10 && o11 && o13 && o14 && o15;
} }
bool testFactoryParm() bool testFactoryParm()
{ {
bool reg = registerAll(); bool reg = registerAll();
AbstractProduct* p; AbstractProduct* p;
p = Factory0::Instance().CreateObject(1); p = Factory0::Instance().CreateObject(1);
delete p; delete p;
bool test0=p!=NULL; bool test0=p!=NULL;
p = Factory1::Instance().CreateObject(1,64); p = Factory1::Instance().CreateObject(1,64);
delete p; delete p;
bool test1=p!=NULL; bool test1=p!=NULL;
p = Factory2::Instance().CreateObject(1,64,64); p = Factory2::Instance().CreateObject(1,64,64);
delete p; delete p;
bool test2=p!=NULL; bool test2=p!=NULL;
p = Factory3::Instance().CreateObject(1,64,64,64); p = Factory3::Instance().CreateObject(1,64,64,64);
delete p; delete p;
bool test3=p!=NULL; bool test3=p!=NULL;
p = Factory4::Instance().CreateObject(1,64,64,64,64); p = Factory4::Instance().CreateObject(1,64,64,64,64);
delete p; delete p;
bool test4=p!=NULL; bool test4=p!=NULL;
p = Factory5::Instance().CreateObject(1,64,64,64,64,64); p = Factory5::Instance().CreateObject(1,64,64,64,64,64);
delete p; delete p;
bool test5=p!=NULL; bool test5=p!=NULL;
p = Factory6::Instance().CreateObject(1, 64,64,64,64,64, p = Factory6::Instance().CreateObject(1, 64,64,64,64,64,
64); 64);
delete p; delete p;
bool test6=p!=NULL; bool test6=p!=NULL;
p = Factory7::Instance().CreateObject(1, 64,64,64,64,64, p = Factory7::Instance().CreateObject(1, 64,64,64,64,64,
64,64); 64,64);
delete p; delete p;
bool test7=p!=NULL; bool test7=p!=NULL;
p = Factory8::Instance().CreateObject(1, 64,64,64,64,64, p = Factory8::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64); 64,64,64);
delete p; delete p;
bool test8=p!=NULL; bool test8=p!=NULL;
p = Factory9::Instance().CreateObject(1, 64,64,64,64,64, p = Factory9::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64); 64,64,64,64);
delete p; delete p;
bool test9=p!=NULL; bool test9=p!=NULL;
p = Factory10::Instance().CreateObject(1, 64,64,64,64,64, p = Factory10::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64); 64,64,64,64,64);
delete p; delete p;
bool test10=p!=NULL; bool test10=p!=NULL;
p = Factory11::Instance().CreateObject(1, 64,64,64,64,64, p = Factory11::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64, 64,64,64,64,64,
64); 64);
delete p; delete p;
bool test11=p!=NULL; bool test11=p!=NULL;
p = Factory12::Instance().CreateObject(1, 64,64,64,64,64, p = Factory12::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64, 64,64,64,64,64,
64,64); 64,64);
delete p; delete p;
bool test12=p!=NULL; bool test12=p!=NULL;
p = Factory13::Instance().CreateObject(1, 64,64,64,64,64, p = Factory13::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64, 64,64,64,64,64,
64,64,64); 64,64,64);
delete p; delete p;
bool test13=p!=NULL; bool test13=p!=NULL;
p = Factory14::Instance().CreateObject(1, 64,64,64,64,64, p = Factory14::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64, 64,64,64,64,64,
64,64,64,64); 64,64,64,64);
delete p; delete p;
bool test14=p!=NULL; bool test14=p!=NULL;
p = Factory15::Instance().CreateObject(1, 64,64,64,64,64, p = Factory15::Instance().CreateObject(1, 64,64,64,64,64,
64,64,64,64,64, 64,64,64,64,64,
64,64,64,64,64); 64,64,64,64,64);
delete p; delete p;
bool test15=p!=NULL; bool test15=p!=NULL;
return reg && test0 && return reg && test0 &&
test1 && test2 && test3 && test4 && test5 && test1 && test2 && test3 && test4 && test5 &&
test6 && test7 && test8 && test9 && test10 && test6 && test7 && test8 && test9 && test10 &&
test11 && test12 && test13 && test14 && test15; test11 && test12 && test13 && test14 && test15;
} }
} }
@ -395,21 +395,21 @@ namespace FactoryTestParmPrivate
class FactoryParmTest : public Test class FactoryParmTest : public Test
{ {
public: public:
FactoryParmTest() : Test("FactoryParm.h") {} FactoryParmTest() : Test("FactoryParm.h") {}
virtual void execute(TestResult &result) virtual void execute(TestResult &result)
{ {
printName(result); printName(result);
bool test1=FactoryTestParmPrivate::testFactoryParm(); bool test1=FactoryTestParmPrivate::testFactoryParm();
bool r=test1; bool r=test1;
testAssert("FactoryParm",r,result); testAssert("FactoryParm",r,result);
std::cout << '\n'; std::cout << '\n';
} }
} factoryParmTest; } factoryParmTest;
@ -419,3 +419,4 @@ public:
// $Log: // $Log:

View file

@ -107,4 +107,5 @@ return result;
} }
// $Log:@ // $Log: