Changeset 4003 in orxonox.OLD for orxonox/branches
- Timestamp:
- Apr 28, 2005, 2:25:08 AM (21 years ago)
- Location:
- orxonox/branches/ll2trunktemp/src
- Files:
-
- 4 edited
-
defs/stdincl.h (modified) (1 diff)
-
factory.cc (modified) (7 diffs)
-
factory.h (modified) (2 diffs)
-
game_loader.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/ll2trunktemp/src/defs/stdincl.h
r3940 r4003 30 30 #include "factory.h" 31 31 32 #define CREATE_FACTORY(x) \33 class x ## Factory : public Factory { \34 public: \35 x ## Factory (){setNext( NULL); setClassname( #x ); initialize();} \36 ~x ## Factory () {}; \37 private: \38 BaseObject* fabricate( TiXmlElement* root) \39 { \40 if(!strcmp(root->Value(), getClassname())) return new x ( root); \41 else if( getNext() != NULL) return getNext()->fabricate( root); \42 else return NULL; \43 } \44 }; \45 x ## Factory global_ ## x ## Factory;46 47 32 #endif /* _STDINCL_H */ -
orxonox/branches/ll2trunktemp/src/factory.cc
r3994 r4003 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 23 21 24 22 /* -------------------------------------------------- 25 * Factory26 * --------------------------------------------------27 */23 * Factory 24 * -------------------------------------------------- 25 */ 28 26 29 27 /** … … 34 32 Factory::Factory () 35 33 { 36 classname = "NULL"; 37 next = NULL; 34 classname = "NULL"; 35 next = NULL; 36 37 initialize(); 38 38 } 39 39 … … 45 45 Factory::~Factory () 46 46 { 47 //if( next != NULL) delete next; 47 printf("%s\n", this->classname); 48 Factory* tmpDel = this->next; 49 this->next = NULL; 50 // if (tmpDel) 51 // delete tmpDel; 48 52 } 49 50 53 51 54 /** … … 54 57 BaseObject* Factory::fabricate( TiXmlElement* data) 55 58 { 56 return NULL;59 return NULL; 57 60 } 58 61 … … 62 65 void Factory::initialize() 63 66 { 64 assert( classname != NULL);65 GameLoader* gl = GameLoader::getInstance();66 gl->registerFactory( this);67 assert( classname != NULL); 68 GameLoader* gl = GameLoader::getInstance(); 69 gl->registerFactory( this); 67 70 } 68 71 … … 72 75 void Factory::registerFactory( Factory* factory) 73 76 { 74 if( next == NULL) setNext( factory);75 else next->registerFactory( factory);77 if( next == NULL) setNext( factory); 78 else next->registerFactory( factory); 76 79 } 77 80 78 81 const char* grabParameter( TiXmlElement* root, const char* name) 79 82 { 80 TiXmlElement* element;81 TiXmlNode* node;83 TiXmlElement* element; 84 TiXmlNode* node; 82 85 83 assert( root != NULL);84 assert( name != NULL);86 assert( root != NULL); 87 assert( name != NULL); 85 88 86 element = root->FirstChildElement( name);87 if( element == NULL) return NULL;89 element = root->FirstChildElement( name); 90 if( element == NULL) return NULL; 88 91 89 node = element->FirstChild();90 while( node != NULL)91 {92 if( node->ToText()) return node->Value();93 node = node->NextSibling();94 }95 return NULL;92 node = element->FirstChild(); 93 while( node != NULL) 94 { 95 if( node->ToText()) return node->Value(); 96 node = node->NextSibling(); 97 } 98 return NULL; 96 99 } 97 100 -
orxonox/branches/ll2trunktemp/src/factory.h
r3940 r4003 11 11 #include "xmlparser/tinyxml.h" 12 12 13 #define CREATE_FACTORY(x) \ 14 class x ## Factory : public Factory { \ 15 public: \ 16 x ## Factory (){setClassname( #x );} \ 17 ~x ## Factory () {}; \ 18 private: \ 19 BaseObject* fabricate( TiXmlElement* root) \ 20 { \ 21 if(!strcmp(root->Value(), getClassname())) return new x ( root); \ 22 else if( getNext() != NULL) return getNext()->fabricate( root); \ 23 else return NULL; \ 24 } \ 25 }; \ 26 x ## Factory global_ ## x ## Factory; 27 13 28 //! The Factory is 14 29 /** 15 Very philosophic description, huh?30 Very philosophic description, huh? 16 31 */ 17 32 class Factory { … … 20 35 Factory (); 21 36 ~Factory (); 37 22 38 23 virtual BaseObject* fabricate( TiXmlElement* root);24 void initialize();25 void registerFactory( Factory* factory);26 void setClassname(char* name) {classname = name;}27 char* getClassname() {return classname;};28 void setNext( Factory* factory) {next = factory;}29 Factory* getNext() {return next;}39 virtual BaseObject* fabricate( TiXmlElement* root); 40 void initialize(); 41 void registerFactory( Factory* factory); 42 void setClassname(char* name) {classname = name;} 43 char* getClassname() {return classname;}; 44 void setNext( Factory* factory) {next = factory;} 45 Factory* getNext() {return next;} 30 46 31 47 private: 32 char* classname;48 char* classname; 33 49 34 50 Factory* next; -
orxonox/branches/ll2trunktemp/src/game_loader.cc
r3989 r4003 166 166 167 167 if( name == NULL) 168 {169 PRINTF0("No filename specified for loading");170 return NULL;171 }168 { 169 PRINTF0("No filename specified for loading"); 170 return NULL; 171 } 172 172 173 TiXmlDocument* XMLDoc = new TiXmlDocument( name);174 // load the campaign document175 if( !XMLDoc->LoadFile())176 {177 // report an error178 PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());179 delete XMLDoc;180 return NULL;181 }182 183 // check basic validity184 TiXmlElement* root = XMLDoc->RootElement();185 assert( root != NULL);186 187 if( strcmp( root->Value(), "Campaign"))188 {189 // report an error190 PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");191 delete XMLDoc;192 return NULL;193 }194 195 // construct campaign196 Campaign* c = new Campaign( root);197 198 // free the XML data199 delete XMLDoc;200 201 return c;173 TiXmlDocument* XMLDoc = new TiXmlDocument( name); 174 // load the campaign document 175 if( !XMLDoc->LoadFile()) 176 { 177 // report an error 178 PRINTF0("Error loading XML File: %s @ %d:%d\n", XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 179 delete XMLDoc; 180 return NULL; 181 } 182 183 // check basic validity 184 TiXmlElement* root = XMLDoc->RootElement(); 185 assert( root != NULL); 186 187 if( strcmp( root->Value(), "Campaign")) 188 { 189 // report an error 190 PRINTF0("Specified XML File is not an orxonox campaign file (Campaign element missing)\n"); 191 delete XMLDoc; 192 return NULL; 193 } 194 195 // construct campaign 196 Campaign* c = new Campaign( root); 197 198 // free the XML data 199 delete XMLDoc; 200 201 return c; 202 202 } 203 203
Note: See TracChangeset
for help on using the changeset viewer.










