| 
                Last change
                  on this file since 4195 was
                  4194,
                  checked in by bensch, 20 years ago
           | 
        
        
          | 
               
orxonox/branches/openAL: merged trunk back to openAL 
merged with command: 
 
svn merge ../trunk/ openAL/ -r 3920:HEAD 
 
 
no conflicts at all 
 
           | 
        
        | 
            File size:
            1.6 KB
           | 
      
      
        
  | Rev | Line |   | 
|---|
| [3940] | 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" | 
|---|
| [4171] | 12 | #include "debug.h" | 
|---|
| [3940] | 13 |  | 
|---|
| [4004] | 14 | /**  | 
|---|
 | 15 |     Creates a factory to a Loadable Class. | 
|---|
 | 16 |     this should be used at the beginning of all the Classes that should be loadable (in the cc-file) | 
|---|
 | 17 | */ | 
|---|
| [4005] | 18 | #define CREATE_FACTORY(x) tFactory<x>* global_ ## x ## Factory = new tFactory<x>(#x) | 
|---|
| [4004] | 19 |  | 
|---|
 | 20 |  | 
|---|
| [4003] | 21 |                  | 
|---|
| [3940] | 22 | //! The Factory is | 
|---|
 | 23 | /** | 
|---|
| [4003] | 24 |    Very philosophic description, huh? | 
|---|
| [3940] | 25 | */ | 
|---|
 | 26 | class Factory { | 
|---|
 | 27 |  | 
|---|
 | 28 |  public: | 
|---|
| [4004] | 29 |   Factory (const char* name = NULL); | 
|---|
| [3940] | 30 |   ~Factory (); | 
|---|
| [4003] | 31 |    | 
|---|
| [3940] | 32 |  | 
|---|
| [4003] | 33 |   virtual BaseObject* fabricate( TiXmlElement* root); | 
|---|
 | 34 |   void initialize(); | 
|---|
 | 35 |   void registerFactory( Factory* factory); | 
|---|
| [4020] | 36 |   void setFactoryName(const char* name); | 
|---|
 | 37 |   const char* getFactoryName() {return factoryName;}; | 
|---|
| [4003] | 38 |   void setNext( Factory* factory) {next = factory;} | 
|---|
 | 39 |   Factory* getNext() {return next;} | 
|---|
| [3940] | 40 |          | 
|---|
 | 41 |  private: | 
|---|
| [4020] | 42 |   char* factoryName; | 
|---|
| [3940] | 43 |          | 
|---|
 | 44 |   Factory* next; | 
|---|
 | 45 | }; | 
|---|
 | 46 |  | 
|---|
| [4004] | 47 | template<class T> class tFactory : public Factory | 
|---|
 | 48 | { | 
|---|
 | 49 |  public: | 
|---|
 | 50 |   tFactory(const char* name); | 
|---|
 | 51 |   virtual ~tFactory(); | 
|---|
 | 52 |    | 
|---|
 | 53 |   private: | 
|---|
 | 54 |   BaseObject* fabricate( TiXmlElement* root); | 
|---|
 | 55 | }; | 
|---|
 | 56 |  | 
|---|
 | 57 | template<class T> | 
|---|
 | 58 | tFactory<T>::tFactory(const char* name) : Factory(name) | 
|---|
 | 59 | { | 
|---|
| [4133] | 60 |   PRINTF(5)("fileName: %s\n", name); | 
|---|
| [4004] | 61 | } | 
|---|
 | 62 |    | 
|---|
 | 63 |  | 
|---|
 | 64 | template<class T> | 
|---|
 | 65 | tFactory<T>::~tFactory() | 
|---|
 | 66 | {} | 
|---|
 | 67 |  | 
|---|
 | 68 | template<class T> | 
|---|
 | 69 | BaseObject* tFactory<T>::fabricate( TiXmlElement* root)  | 
|---|
 | 70 | {  | 
|---|
| [4020] | 71 |   if(!strcmp(root->Value(), getFactoryName())) | 
|---|
| [4004] | 72 |     return new T ( root); | 
|---|
 | 73 |   else if( getNext() != NULL)  | 
|---|
 | 74 |     return getNext()->fabricate( root); | 
|---|
 | 75 |   else  | 
|---|
 | 76 |     return NULL; | 
|---|
 | 77 | } | 
|---|
 | 78 |  | 
|---|
| [3940] | 79 | // helper function | 
|---|
 | 80 |  | 
|---|
 | 81 | const char* grabParameter( TiXmlElement* root, const char* name); | 
|---|
 | 82 |  | 
|---|
 | 83 | #endif /* _FACTORY_H */ | 
|---|
 | 84 |  | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.