4 #include <ptlib/pprocess.h>
6 #include <ptclib/http.h>
7 #include <ptclib/ptts.h>
8 #include <ptclib/pwavfile.h>
12 class Factory
: public PProcess
20 PCREATE_PROCESS(Factory
)
23 template <class BaseClass
, class TypeClass
= PString
>
27 static void ConcreteTypes(const char * title
)
29 cout
<< "\nConcrete types for " << title
<< ':' << endl
;
30 typename PFactory
<BaseClass
, TypeClass
>::KeyList_T keys
= PFactory
<BaseClass
, TypeClass
>::GetKeyList();
31 typename PFactory
<BaseClass
, TypeClass
>::KeyList_T::const_iterator r
;
32 for (r
= keys
.begin(); r
!= keys
.end(); ++r
)
33 cout
<< " " << *r
<< endl
;
38 static void TestFactory()
40 typename PFactory
<BaseClass
, TypeClass
>::KeyList_T keyList
= PFactory
<BaseClass
, TypeClass
>::GetKeyList();
42 for (i
= 0; i
< keyList
.size(); i
++) {
43 for (int j
= 0; j
< 3; j
++)
45 MyAbstractClass
* c
= PFactory
<BaseClass
, TypeClass
>::CreateInstance(keyList
[i
]);
47 cout
<< "Cannot instantiate class " << keyList
[i
] << endl
;
49 cout
<< keyList
[i
] << "::Function returned \"" << c
->Function() << "\", instance " << (void *)c
<< endl
;
58 Display
<MyAbstractClass
>::ConcreteTypes("MyAbstractClass by PString");
59 Display
<MyAbstractClass
>::TestFactory();
61 Display
<MyAbstractClass
, unsigned>::ConcreteTypes("MyAbstractClass by unsigned");
62 Display
<MyAbstractClass
, unsigned>::TestFactory();
64 Display
<PURLScheme
>::ConcreteTypes("PURLScheme");
65 Display
<PTextToSpeech
>::ConcreteTypes("PTextToSpeech");
66 Display
<PPluginModuleManager
>::ConcreteTypes("PPluginModuleManager");