| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /*  | 
|---|
| 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 5 |  | 
|---|
| 6 |    Copyright (C) 2004 orx | 
|---|
| 7 |  | 
|---|
| 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |    it under the terms of the GNU General Public License as published by | 
|---|
| 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 |    any later version. | 
|---|
| 12 |  | 
|---|
| 13 |    ### File Specific: | 
|---|
| 14 |    main-programmer: Christian Meyer | 
|---|
| 15 |    co-programmer: ... | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include "factory.h" | 
|---|
| 20 | #include "game_loader.h" | 
|---|
| 21 |  | 
|---|
| 22 | using namespace std; | 
|---|
| 23 |  | 
|---|
| 24 | /*  -------------------------------------------------- | 
|---|
| 25 | *                Factory | 
|---|
| 26 | *   -------------------------------------------------- | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 |    \brief constructor | 
|---|
| 31 |     | 
|---|
| 32 |    set everything to zero and define classname | 
|---|
| 33 | */ | 
|---|
| 34 | Factory::Factory () | 
|---|
| 35 | { | 
|---|
| 36 |         classname = "NULL"; | 
|---|
| 37 |         next = NULL; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | /** | 
|---|
| 41 |    \brief destructor | 
|---|
| 42 |     | 
|---|
| 43 |    clear the Q | 
|---|
| 44 | */ | 
|---|
| 45 | Factory::~Factory () | 
|---|
| 46 | { | 
|---|
| 47 |         if( next != NULL)       delete next; | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 | /** | 
|---|
| 52 |    \brief generates the associated object from data | 
|---|
| 53 | */ | 
|---|
| 54 | BaseObject* Factory::fabricate( TiXmlElement* data) | 
|---|
| 55 | { | 
|---|
| 56 |         return NULL; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | /** | 
|---|
| 60 |    \brief make this particular factory known to the LevelFactory | 
|---|
| 61 | */ | 
|---|
| 62 | void Factory::initialize() | 
|---|
| 63 | { | 
|---|
| 64 |         assert( classname != NULL); | 
|---|
| 65 |         GameLoader* gl = GameLoader::getInstance(); | 
|---|
| 66 |         gl->registerFactory( this); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | /** | 
|---|
| 70 |    \brief add a Factory to the Q | 
|---|
| 71 | */ | 
|---|
| 72 | void Factory::registerFactory( Factory* factory) | 
|---|
| 73 | { | 
|---|
| 74 |         if( next == NULL) setNext( factory); | 
|---|
| 75 |         else next->registerFactory( factory); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | const char* grabParameter( TiXmlElement* root, const char* name) | 
|---|
| 79 | { | 
|---|
| 80 |         TiXmlElement* element; | 
|---|
| 81 |         TiXmlNode* node; | 
|---|
| 82 |          | 
|---|
| 83 |         assert( root != NULL); | 
|---|
| 84 |         assert( name != NULL); | 
|---|
| 85 |          | 
|---|
| 86 |         element = root->FirstChildElement( name); | 
|---|
| 87 |         if( element == NULL) return NULL; | 
|---|
| 88 |          | 
|---|
| 89 |         node = element->FirstChild(); | 
|---|
| 90 |         while( node != NULL) | 
|---|
| 91 |         { | 
|---|
| 92 |                 if( node->ToText()) return node->Value(); | 
|---|
| 93 |                 node = node->NextSibling(); | 
|---|
| 94 |         } | 
|---|
| 95 |         return NULL; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|