Added PSharedptr class
[pwlib.git] / samples / factory / main.cxx
blob758c7c4d3ce330e30a6959be1ca660afea49620d
2 #include <ptlib.h>
4 #include <ptclib/http.h>
5 #include <ptclib/ptts.h>
6 #include <ptclib/pwavfile.h>
8 #include "abstract.h"
11 class Factory : public PProcess
13 public:
14 Factory()
15 : PProcess() { }
16 void Main();
19 PCREATE_PROCESS(Factory)
22 template <class BaseClass, typename TypeClass = PString>
23 class Display
25 public:
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;
34 cout << endl;
37 static void TestFactory()
39 PFactory<BaseClass, TypeClass>::KeyList_T keyList = PFactory<MyAbstractClass, TypeClass>::GetKeyList();
40 unsigned i;
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]);
45 if (c == NULL)
46 cout << "Cannot instantiate class " << keyList[i] << endl;
47 else
48 cout << keyList[i] << "::Function returned \"" << c->Function() << "\", instance " << (void *)c << endl;
55 void Factory::Main()
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");