Last change
on this file since 4014 was
4010,
checked in by bensch, 20 years ago
|
orxonox/trunk: merged the levelloader from lltrunktemp to the trunk. Big thanks to fuzzy to make this so easy for us, and for implementing it in the first place.
|
File size:
1.6 KB
|
Line | |
---|
1 | /*! |
---|
2 | \file factory.h |
---|
3 | \brief philosophy stuff |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _FACTORY_H |
---|
7 | #define _FACTORY_H |
---|
8 | |
---|
9 | class BaseObject; |
---|
10 | |
---|
11 | #include "xmlparser/tinyxml.h" |
---|
12 | |
---|
13 | /** |
---|
14 | Creates a factory to a Loadable Class. |
---|
15 | this should be used at the beginning of all the Classes that should be loadable (in the cc-file) |
---|
16 | */ |
---|
17 | #define CREATE_FACTORY(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x) |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | //! The Factory is |
---|
22 | /** |
---|
23 | Very philosophic description, huh? |
---|
24 | */ |
---|
25 | class Factory { |
---|
26 | |
---|
27 | public: |
---|
28 | Factory (const char* name = NULL); |
---|
29 | ~Factory (); |
---|
30 | |
---|
31 | |
---|
32 | virtual BaseObject* fabricate( TiXmlElement* root); |
---|
33 | void initialize(); |
---|
34 | void registerFactory( Factory* factory); |
---|
35 | void setClassname(const char* name); |
---|
36 | const char* getClassname() {return classname;}; |
---|
37 | void setNext( Factory* factory) {next = factory;} |
---|
38 | Factory* getNext() {return next;} |
---|
39 | |
---|
40 | private: |
---|
41 | char* classname; |
---|
42 | |
---|
43 | Factory* next; |
---|
44 | }; |
---|
45 | |
---|
46 | template<class T> class tFactory : public Factory |
---|
47 | { |
---|
48 | public: |
---|
49 | tFactory(const char* name); |
---|
50 | virtual ~tFactory(); |
---|
51 | |
---|
52 | private: |
---|
53 | BaseObject* fabricate( TiXmlElement* root); |
---|
54 | }; |
---|
55 | |
---|
56 | template<class T> |
---|
57 | tFactory<T>::tFactory(const char* name) : Factory(name) |
---|
58 | { |
---|
59 | printf("fileName: %s\n", name); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | template<class T> |
---|
64 | tFactory<T>::~tFactory() |
---|
65 | {} |
---|
66 | |
---|
67 | template<class T> |
---|
68 | BaseObject* tFactory<T>::fabricate( TiXmlElement* root) |
---|
69 | { |
---|
70 | if(!strcmp(root->Value(), getClassname())) |
---|
71 | return new T ( root); |
---|
72 | else if( getNext() != NULL) |
---|
73 | return getNext()->fabricate( root); |
---|
74 | else |
---|
75 | return NULL; |
---|
76 | } |
---|
77 | |
---|
78 | // helper function |
---|
79 | |
---|
80 | const char* grabParameter( TiXmlElement* root, const char* name); |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | #endif /* _FACTORY_H */ |
---|
86 | |
---|
Note: See
TracBrowser
for help on using the repository browser.