Fixed DevStudio 2003 build with memory check code.
[pwlib.git] / samples / factory / main.cxx
blobbd038da0d75f39122bbc59301498b2a6f5c358e5
2 #include "abstract.h"
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
14 public:
15 Factory()
16 : PProcess() { }
17 void Main();
20 PCREATE_PROCESS(Factory)
23 template <class BaseClass, class TypeClass = PString>
24 class Display
26 public:
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;
35 cout << endl;
38 static void TestFactory()
40 typename PFactory<BaseClass, TypeClass>::KeyList_T keyList = PFactory<BaseClass, TypeClass>::GetKeyList();
41 unsigned i;
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]);
46 if (c == NULL)
47 cout << "Cannot instantiate class " << keyList[i] << endl;
48 else
49 cout << keyList[i] << "::Function returned \"" << c->Function() << "\", instance " << (void *)c << endl;
56 void Factory::Main()
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");