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 | #include "load_param.h" |
---|
17 | |
---|
18 | #include "list.h" |
---|
19 | #include "base_object.h" |
---|
20 | |
---|
21 | #include <stdarg.h> |
---|
22 | |
---|
23 | |
---|
24 | BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...) |
---|
25 | { |
---|
26 | this->paramDesc = NULL; |
---|
27 | if (LoadClassDescription::parametersDescription) |
---|
28 | { |
---|
29 | // locating the class |
---|
30 | this->classDesc = LoadClassDescription::addClass(object->getClassName()); |
---|
31 | this->paramDesc = this->classDesc->addParam(paramName); |
---|
32 | |
---|
33 | this->paramDesc->types = new char*[paramCount]; |
---|
34 | this->paramDesc->paramCount = paramCount; |
---|
35 | |
---|
36 | va_list types; |
---|
37 | va_start (types, paramCount); |
---|
38 | for(int i = 0; i < paramCount; i++) |
---|
39 | { |
---|
40 | const char* tmpTypeName = va_arg (types, const char*); |
---|
41 | this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; |
---|
42 | strcpy(this->paramDesc->types[i], tmpTypeName); |
---|
43 | } |
---|
44 | va_end(types); |
---|
45 | |
---|
46 | int argCount = 0; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | void BaseLoadParam::describe(const char* descriptionText) |
---|
52 | { |
---|
53 | if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription()) |
---|
54 | { |
---|
55 | this->paramDesc->setDescription(descriptionText); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | LoadParamDescription::LoadParamDescription(const char* paramName) |
---|
60 | { |
---|
61 | this->types = NULL; |
---|
62 | this->description = NULL; |
---|
63 | this->paramName = new char[strlen(paramName)+1]; |
---|
64 | strcpy(this->paramName, paramName); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | LoadParamDescription::~LoadParamDescription(void) |
---|
69 | { |
---|
70 | for(int i = 0; i < this->paramCount; i++) |
---|
71 | { |
---|
72 | delete this->types[i]; |
---|
73 | } |
---|
74 | delete []this->types; |
---|
75 | delete []this->paramName; |
---|
76 | } |
---|
77 | |
---|
78 | void LoadParamDescription::setDescription(const char* descriptionText) |
---|
79 | { |
---|
80 | this->description = descriptionText; |
---|
81 | } |
---|
82 | |
---|
83 | void LoadParamDescription::print(void) const |
---|
84 | { |
---|
85 | PRINT(3)(" <%s>", this->paramName); |
---|
86 | for (int i = 0; i < this->paramCount; i++) |
---|
87 | { |
---|
88 | if (i > 0) |
---|
89 | PRINT(3)(","); |
---|
90 | PRINT(3)("%s", this->types[i]); |
---|
91 | } |
---|
92 | PRINT(3)("</%s>", this->paramName); |
---|
93 | if (this->description) |
---|
94 | PRINT(3)(" -- %s", this->description); |
---|
95 | PRINT(3)("\n"); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>; |
---|
100 | |
---|
101 | /** |
---|
102 | \brief if the description of Parameters should be executed |
---|
103 | */ |
---|
104 | bool LoadClassDescription::parametersDescription = true; |
---|
105 | |
---|
106 | LoadClassDescription::LoadClassDescription(const char* className) |
---|
107 | { |
---|
108 | this->className = new char[strlen(className)+1]; |
---|
109 | strcpy(this->className, className); |
---|
110 | |
---|
111 | classList->add(this); |
---|
112 | |
---|
113 | this->paramList = new tList<LoadParamDescription>; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | LoadClassDescription::~LoadClassDescription(void) |
---|
118 | { |
---|
119 | delete []this->className; |
---|
120 | |
---|
121 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
122 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
123 | while (enumParamDesc) |
---|
124 | { |
---|
125 | delete enumParamDesc; |
---|
126 | enumParamDesc = iterator->nextElement(); |
---|
127 | } |
---|
128 | delete iterator; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | LoadClassDescription* LoadClassDescription::addClass(const char* className) |
---|
133 | { |
---|
134 | tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); |
---|
135 | LoadClassDescription* enumClassDesc = iterator->nextElement(); |
---|
136 | while (enumClassDesc) |
---|
137 | { |
---|
138 | if (!strcmp(enumClassDesc->className, className)) |
---|
139 | { |
---|
140 | delete iterator; |
---|
141 | return enumClassDesc; |
---|
142 | } |
---|
143 | enumClassDesc = iterator->nextElement(); |
---|
144 | } |
---|
145 | delete iterator; |
---|
146 | |
---|
147 | return new LoadClassDescription(className); |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | LoadParamDescription* LoadClassDescription::addParam(const char* paramName) |
---|
152 | { |
---|
153 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
154 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
155 | while (enumParamDesc) |
---|
156 | { |
---|
157 | if (!strcmp(enumParamDesc->paramName, paramName)) |
---|
158 | { |
---|
159 | delete iterator; |
---|
160 | return enumParamDesc; |
---|
161 | } |
---|
162 | enumParamDesc = iterator->nextElement(); |
---|
163 | } |
---|
164 | delete iterator; |
---|
165 | |
---|
166 | this->paramList->add(new LoadParamDescription(paramName)); |
---|
167 | return paramList->lastElement(); |
---|
168 | } |
---|
169 | |
---|
170 | void LoadClassDescription::printAll(void) |
---|
171 | { |
---|
172 | PRINT(3)("==============================================================\n"); |
---|
173 | PRINT(3)(" Listing all the Loadable Options (loaded since Game started.\n\n"); |
---|
174 | tIterator<LoadClassDescription>* classIT = LoadClassDescription::classList->getIterator(); |
---|
175 | LoadClassDescription* enumClassDesc = classIT->nextElement(); |
---|
176 | while (enumClassDesc) |
---|
177 | { |
---|
178 | PRINT(3)("<%s>\n", enumClassDesc->className); |
---|
179 | tIterator<LoadParamDescription>* paramIT = enumClassDesc->paramList->getIterator(); |
---|
180 | LoadParamDescription* enumParamDesc = paramIT->nextElement(); |
---|
181 | while (enumParamDesc) |
---|
182 | { |
---|
183 | enumParamDesc->print(); |
---|
184 | enumParamDesc = paramIT->nextElement(); |
---|
185 | } |
---|
186 | delete paramIT; |
---|
187 | |
---|
188 | PRINT(3)("</%s>\n\n", enumClassDesc->className); |
---|
189 | enumClassDesc = classIT->nextElement(); |
---|
190 | } |
---|
191 | delete classIT; |
---|
192 | |
---|
193 | } |
---|