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