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 | if (LoadClassDescription::parametersDescription) |
---|
27 | { |
---|
28 | // locating the class |
---|
29 | this->classDesc = LoadClassDescription::addClass(object->getClassName()); |
---|
30 | this->paramDesc = this->classDesc->addParam(paramName); |
---|
31 | |
---|
32 | this->paramDesc->types = new char*[paramCount]; |
---|
33 | this->paramDesc->paramCount = paramCount; |
---|
34 | |
---|
35 | va_list types; |
---|
36 | va_start (types, paramCount); |
---|
37 | for(int i = 0; i < paramCount; i++) |
---|
38 | { |
---|
39 | const char* tmpTypeName = va_arg (types, const char*); |
---|
40 | this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; |
---|
41 | strcpy(this->paramDesc->types[i], tmpTypeName); |
---|
42 | } |
---|
43 | va_end(types); |
---|
44 | |
---|
45 | int argCount = 0; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | void BaseLoadParam::describe(const char* descriptionText) |
---|
51 | { |
---|
52 | if (this->paramDesc) |
---|
53 | { |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | LoadParamDescription::LoadParamDescription(const char* paramName) |
---|
61 | { |
---|
62 | this->types = NULL; |
---|
63 | this->paramName = new char[strlen(paramName)+1]; |
---|
64 | strcpy(this->paramName, paramName); |
---|
65 | } |
---|
66 | |
---|
67 | LoadParamDescription::~LoadParamDescription(void) |
---|
68 | { |
---|
69 | for(int i = 0; i < this->paramCount; i++) |
---|
70 | { |
---|
71 | delete this->types[i]; |
---|
72 | } |
---|
73 | delete []this->types; |
---|
74 | delete []this->paramName; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | tList<LoadClassDescription>* LoadClassDescription::classList = new tList<LoadClassDescription>; |
---|
79 | |
---|
80 | /** |
---|
81 | \brief if the description of Parameters should be executed |
---|
82 | */ |
---|
83 | bool LoadClassDescription::parametersDescription = true; |
---|
84 | |
---|
85 | LoadClassDescription::LoadClassDescription(const char* className) |
---|
86 | { |
---|
87 | this->className = new char[strlen(className)+1]; |
---|
88 | strcpy(this->className, className); |
---|
89 | |
---|
90 | classList->add(this); |
---|
91 | |
---|
92 | this->paramList = new tList<LoadParamDescription>; |
---|
93 | } |
---|
94 | |
---|
95 | LoadClassDescription::~LoadClassDescription(void) |
---|
96 | { |
---|
97 | delete []this->className; |
---|
98 | |
---|
99 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
100 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
101 | while (enumParamDesc) |
---|
102 | { |
---|
103 | delete enumParamDesc; |
---|
104 | enumParamDesc = iterator->nextElement(); |
---|
105 | } |
---|
106 | delete iterator; |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | LoadClassDescription* LoadClassDescription::addClass(const char* className) |
---|
112 | { |
---|
113 | tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator(); |
---|
114 | LoadClassDescription* enumClassDesc = iterator->nextElement(); |
---|
115 | while (enumClassDesc) |
---|
116 | { |
---|
117 | if (!strcmp(enumClassDesc->className, className)) |
---|
118 | { |
---|
119 | delete iterator; |
---|
120 | return enumClassDesc; |
---|
121 | } |
---|
122 | enumClassDesc = iterator->nextElement(); |
---|
123 | } |
---|
124 | delete iterator; |
---|
125 | |
---|
126 | return new LoadClassDescription(className); |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | LoadParamDescription* LoadClassDescription::addParam(const char* paramName) |
---|
131 | { |
---|
132 | tIterator<LoadParamDescription>* iterator = this->paramList->getIterator(); |
---|
133 | LoadParamDescription* enumParamDesc = iterator->nextElement(); |
---|
134 | while (enumParamDesc) |
---|
135 | { |
---|
136 | if (!strcmp(enumParamDesc->paramName, paramName)) |
---|
137 | { |
---|
138 | delete iterator; |
---|
139 | this->paramList->add(enumParamDesc); |
---|
140 | return enumParamDesc; |
---|
141 | } |
---|
142 | enumParamDesc = iterator->nextElement(); |
---|
143 | } |
---|
144 | delete iterator; |
---|
145 | |
---|
146 | this->paramList->add(new LoadParamDescription(paramName)); |
---|
147 | return paramList->lastElement(); |
---|
148 | } |
---|