protect private data, add std::vector<IdType> RegisteredIds()
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@356 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
d45e0a1b08
commit
735cde8666
2 changed files with 85 additions and 68 deletions
|
@ -14,6 +14,7 @@
|
|||
#define USE_SEQUENCE
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "loki/Factory.h"
|
||||
#include "loki/Functor.h"
|
||||
|
||||
|
@ -64,9 +65,9 @@ PFactoryNull;
|
|||
typedef SingletonHolder
|
||||
<
|
||||
#ifndef USE_SEQUENCE
|
||||
Factory< AbstractProduct, int, LOKI_TYPELIST_2( int, int ) >,
|
||||
Factory< AbstractProduct, std::string, LOKI_TYPELIST_2( int, int ) >,
|
||||
#else
|
||||
Factory< AbstractProduct, int, Seq< int, int > >,
|
||||
Factory< AbstractProduct, std::string, Seq< int, int > >,
|
||||
#endif
|
||||
CreateUsingNew,
|
||||
Loki::LongevityLifetime::DieAsSmallObjectChild
|
||||
|
@ -180,15 +181,13 @@ Product* createProductRuntime(CreateFunctor func, int a, int b)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////
|
||||
// Register creator functions
|
||||
// No additional typdefs are necessary!
|
||||
//////////////////////////////////////
|
||||
|
||||
AbstractCreator* c = new Creator;
|
||||
Creator creator;
|
||||
AbstractCreator* c = &creator;
|
||||
CreatorT<Product> cT;
|
||||
|
||||
bool reg()
|
||||
|
@ -198,44 +197,79 @@ bool reg()
|
|||
bool const ok3 = PFactoryNull::Instance().Register( 3, c, &AbstractCreator::create );
|
||||
bool const ok4 = PFactoryNull::Instance().Register( 4, &cT, &CreatorT<Product>::create );
|
||||
|
||||
bool const ok5 = PFactory::Instance().Register( 1, createProductParm );
|
||||
bool const ok6 = PFactory::Instance().Register( 2, (Product*(*)(int,int))createProductOver );
|
||||
bool const ok7 = PFactory::Instance().Register( 3, c, &AbstractCreator::createParm );
|
||||
bool const ok8 = PFactory::Instance().Register( 4, &cT, &CreatorT<Product>::createParm );
|
||||
bool const ok5 = PFactory::Instance().Register( "One", createProductParm );
|
||||
bool const ok6 = PFactory::Instance().Register( "Two", (Product*(*)(int,int))createProductOver );
|
||||
bool const ok7 = PFactory::Instance().Register( "Three", c, &AbstractCreator::createParm );
|
||||
bool const ok8 = PFactory::Instance().Register( "Four", &cT, &CreatorT<Product>::createParm );
|
||||
|
||||
bool const ok9 = PFactoryFunctorParm::Instance().Register( 1, createProductRuntime );
|
||||
|
||||
return ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8 && ok9;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// detect memory leaks on MSVC Ide
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//#define MSVC_DETECT_MEMORY_LEAKS
|
||||
#ifdef MSVC_DETECT_MEMORY_LEAKS
|
||||
|
||||
#include <crtdbg.h>
|
||||
#include <cassert>
|
||||
|
||||
void heap_debug()
|
||||
{
|
||||
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
||||
|
||||
// Turn on leak-checking bit
|
||||
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
|
||||
//tmpFlag |= _CRTDBG_CHECK_MasterLWMasterYS_DF;
|
||||
|
||||
// Turn off CRT block checking bit
|
||||
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
|
||||
|
||||
// Set flag to the new value
|
||||
_CrtSetDbgFlag( tmpFlag );
|
||||
}
|
||||
#else
|
||||
void heap_debug()
|
||||
{}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
heap_debug();
|
||||
|
||||
reg();
|
||||
|
||||
AbstractProduct* p;
|
||||
AbstractProduct* p;
|
||||
|
||||
cout << endl << "creator function is a simple function:" << endl;
|
||||
p= PFactoryNull::Instance().CreateObject( 1 );
|
||||
delete p;
|
||||
p= PFactory::Instance().CreateObject( 1, 64,64 );
|
||||
p= PFactory::Instance().CreateObject( "One", 64,64 );
|
||||
delete p;
|
||||
|
||||
cout << endl << "creator function is a overloaded function:" << endl;
|
||||
p= PFactoryNull::Instance().CreateObject( 2 );
|
||||
delete p;
|
||||
p= PFactory::Instance().CreateObject( 2, 64,64 );
|
||||
p= PFactory::Instance().CreateObject( "Two", 64,64 );
|
||||
delete p;
|
||||
|
||||
cout << endl << "creator function is a member function:" << endl;
|
||||
p= PFactoryNull::Instance().CreateObject( 3 );
|
||||
delete p;
|
||||
p= PFactory::Instance().CreateObject( 3, 64,64 );
|
||||
p= PFactory::Instance().CreateObject( "Three", 64,64 );
|
||||
delete p;
|
||||
|
||||
cout << endl << "creator function is a template member function" << endl;
|
||||
p= PFactoryNull::Instance().CreateObject( 4 );
|
||||
delete p;
|
||||
p= PFactory::Instance().CreateObject( 4, 64,64 );
|
||||
p= PFactory::Instance().CreateObject( "Four", 64,64 );
|
||||
delete p;
|
||||
|
||||
CreateFunctor func1(createProductParm);
|
||||
|
@ -245,14 +279,30 @@ int main(int argc, char *argv[])
|
|||
delete p;
|
||||
p= PFactoryFunctorParm::Instance().CreateObject( 1, func2, 64,64 );
|
||||
delete p;
|
||||
|
||||
|
||||
|
||||
cout << endl;
|
||||
cout << "Registered ids: \n";
|
||||
|
||||
std::vector<std::string> ids = PFactory::Instance().RegisteredIds();
|
||||
|
||||
for(std::vector<std::string>::iterator it=ids.begin(); it!=ids.end(); ++it)
|
||||
cout << *it << "\n";
|
||||
|
||||
|
||||
cout << endl;
|
||||
cout << endl;
|
||||
|
||||
system("PAUSE");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.9 2005/11/12 16:52:36 syntheticpp
|
||||
// protect private data, add std::vector<IdType> RegisteredIds()
|
||||
//
|
||||
// Revision 1.8 2005/11/07 12:06:43 syntheticpp
|
||||
// change lifetime policy DieOrder to a msvc7.1 compilable version. Make this the default lifetime for SmallObject
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue