4 #include <ptclib/http.h>
5 #include <ptclib/ptts.h>
6 #include <ptclib/pwavfile.h>
11 class Factory
: public PProcess
19 PCREATE_PROCESS(Factory
)
22 template <class BaseClass
, typename TypeClass
= PString
>
26 static void ConcreteTypes(const char * title
)
28 cout
<< "\nConcrete types for " << title
<< ':' << endl
;
29 PFactory
<BaseClass
, TypeClass
>::KeyList_T keys
= PFactory
<BaseClass
, TypeClass
>::GetKeyList();
30 PFactory
<BaseClass
, TypeClass
>::KeyList_T::const_iterator r
;
31 for (r
= keys
.begin(); r
!= keys
.end(); ++r
)
32 cout
<< " " << *r
<< endl
;
37 static void TestFactory()
39 PFactory
<BaseClass
, TypeClass
>::KeyList_T keyList
= PFactory
<MyAbstractClass
, TypeClass
>::GetKeyList();
41 for (i
= 0; i
< keyList
.size(); i
++) {
42 for (int j
= 0; j
< 3; j
++)
44 MyAbstractClass
* c
= PFactory
<MyAbstractClass
, TypeClass
>::CreateInstance(keyList
[i
]);
46 cout
<< "Cannot instantiate class " << keyList
[i
] << endl
;
48 cout
<< keyList
[i
] << "::Function returned \"" << c
->Function() << "\", instance " << (void *)c
<< endl
;
57 Display
<MyAbstractClass
>::ConcreteTypes("MyAbstractClass by PString");
58 Display
<MyAbstractClass
>::TestFactory();
60 Display
<MyAbstractClass
, unsigned>::ConcreteTypes("MyAbstractClass by unsigned");
61 Display
<MyAbstractClass
, unsigned>::TestFactory();
63 Display
<PURLScheme
>::ConcreteTypes("PURLScheme");
64 Display
<PTextToSpeech
>::ConcreteTypes("PTextToSpeech");
65 Display
<PPluginModuleManager
>::ConcreteTypes("PPluginModuleManager");