Changeset 9765 in orxonox.OLD for branches/new_class_id
- Timestamp:
- Sep 19, 2006, 5:49:58 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/util/loading
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/util/loading/load_param.cc
r9763 r9765 17 17 18 18 #include "util/loading/load_param.h" 19 #include "load_param_ description.h"19 #include "load_param_class_description.h" 20 20 #include "compiler.h" 21 21 #include "debug.h" … … 46 46 void LoadParamBase::describe(const std::string& descriptionText) 47 47 { 48 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 48 /// TODO REIMPLEMENT 49 /* if (LoadParamClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) 49 50 { 50 51 this->paramDesc->setDescription(descriptionText); 51 } 52 }*/ 52 53 } 53 54 … … 115 116 116 117 117 // const LoadParamDescription* LoadParamDescription::getClass(const char* className)118 // {119 // tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();120 // LoadClassDescription* enumClassDesc = iterator->firstElement();121 // while (enumClassDesc)122 // {123 // if (!strcmp(enumClassDesc->className, classNameBegin, className))124 // {125 // delete iterator;126 // return enumClassDesc;127 // }128 // enumClassDesc = iterator->nextElement();129 // }130 // delete iterator;131 //132 // return NULL;133 // }134 135 136 137 138 /*139 * @param object The object this Parameter is loaded too.140 * @param root: the XML-element to load this option from.141 * @param paramName: The name of the parameter loaded.142 * @param paramCount: how many parameters this loading-function takes143 * @param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.144 * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)145 */146 /*LoadParam::LoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,147 int paramCount, bool multi, const void* pointerToParam, ...)148 {149 this->setClassID(CL_LOAD_PARAM, "LoadParam");150 this->executor = NULL;151 152 this->loadString = NULL;153 this->pointerToParam = pointerToParam;154 155 if (paramCount == 0 || this->pointerToParam != NULL)156 this->loadString = "none";157 else158 {159 if (likely(!multi))160 this->loadString = grabParameter(root, paramName);161 else162 {163 if (!strcmp(root->Value(), paramName))164 {165 const TiXmlNode* val = root->FirstChild();166 if( val->ToText())167 this->loadString = val->Value();168 }169 }170 }171 172 this->paramDesc = NULL;173 if (LoadClassDescription::parametersDescription)174 {175 // locating the class176 this->classDesc = LoadClassDescription::addClass(object->getClassCName());177 178 if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)179 {180 181 this->paramDesc->paramCount = paramCount;182 this->paramDesc->types = new int[paramCount];183 this->paramDesc->defaultValues = new char*[paramCount];184 185 va_list types;186 va_start (types, pointerToParam);187 char defaultVal[512];188 for(int i = 0; i < paramCount; i++)189 {190 defaultVal[0] = '\0';191 // parameters parsed192 int tmpType = va_arg (types, int);193 this->paramDesc->types[i] = tmpType;194 switch (tmpType)195 {196 case MT_INT:197 sprintf(defaultVal, "%d", va_arg(types, int));198 break;199 // case MT_LONG:200 // sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));201 // break;202 case MT_FLOAT:203 sprintf(defaultVal, "%0.3f", va_arg(types, double));204 break;205 case MT_STRING:206 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));207 break;208 case MT_EXT1:209 sprintf(defaultVal, "");210 break;211 }212 this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];213 strcpy(this->paramDesc->defaultValues[i], defaultVal);214 }215 va_end(types);216 217 int argCount = 0;218 }219 }220 }*/221 222 223 224 225 226 227 228 229 230 231 118 ////////////////////// 232 119 // HELPER FUNCTIONS // -
branches/new_class_id/src/lib/util/loading/load_param.h
r9763 r9765 99 99 bool inLoadCycle; //!< If the Parameter is in a LoadCycle. 100 100 101 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter102 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter103 101 const TiXmlElement* loadElem; //!< The Element to load. 104 102 }; -
branches/new_class_id/src/lib/util/loading/load_param_class_description.cc
r9764 r9765 14 14 */ 15 15 16 #include "load_param_ description.h"16 #include "load_param_class_description.h" 17 17 18 18 #include "multi_type.h" … … 125 125 * A list, that holds all the classes that are loadable (classes not objects!!) 126 126 */ 127 std::list<Load ClassDescription*>* LoadClassDescription::classList = NULL;127 std::list<LoadParamClassDescription*>* LoadParamClassDescription::classList = NULL; 128 128 129 129 /** 130 130 * if the description of Parameters should be executed 131 131 */ 132 bool Load ClassDescription::parametersDescription = false;132 bool LoadParamClassDescription::parametersDescription = false; 133 133 134 134 /** 135 135 * @param className the name of the class to be loadable 136 136 */ 137 Load ClassDescription::LoadClassDescription(const std::string& className)137 LoadParamClassDescription::LoadParamClassDescription(const std::string& className) 138 138 { 139 139 this->className = className; 140 140 141 if (Load ClassDescription::classList == NULL)142 Load ClassDescription::classList = new std::list<LoadClassDescription*>;143 144 Load ClassDescription::classList->push_back(this);141 if (LoadParamClassDescription::classList == NULL) 142 LoadParamClassDescription::classList = new std::list<LoadParamClassDescription*>; 143 144 LoadParamClassDescription::classList->push_back(this); 145 145 } 146 146 … … 148 148 * deletes a classDescription (deletes all the parameterDescriptions as well 149 149 */ 150 Load ClassDescription::~LoadClassDescription()150 LoadParamClassDescription::~LoadParamClassDescription() 151 151 { 152 152 std::list<LoadParamDescription*>::iterator it = this->paramList.begin(); … … 158 158 } 159 159 160 void Load ClassDescription::deleteAllDescriptions()161 { 162 if (Load ClassDescription::classList != NULL)163 { 164 while (!Load ClassDescription::classList->empty())165 { 166 delete Load ClassDescription::classList->front();167 Load ClassDescription::classList->pop_front();168 } 169 delete Load ClassDescription::classList;170 } 171 Load ClassDescription::classList = NULL;160 void LoadParamClassDescription::deleteAllDescriptions() 161 { 162 if (LoadParamClassDescription::classList != NULL) 163 { 164 while (!LoadParamClassDescription::classList->empty()) 165 { 166 delete LoadParamClassDescription::classList->front(); 167 LoadParamClassDescription::classList->pop_front(); 168 } 169 delete LoadParamClassDescription::classList; 170 } 171 LoadParamClassDescription::classList = NULL; 172 172 } 173 173 … … 180 180 Otherwise it returns a new classDescription 181 181 */ 182 Load ClassDescription* LoadClassDescription::addClass(const std::string& className)183 { 184 if (Load ClassDescription::classList != NULL)185 { 186 std::list<Load ClassDescription*>::iterator it = LoadClassDescription::classList->begin();187 while (it != Load ClassDescription::classList->end())182 LoadParamClassDescription* LoadParamClassDescription::addClass(const std::string& className) 183 { 184 if (LoadParamClassDescription::classList != NULL) 185 { 186 std::list<LoadParamClassDescription*>::iterator it = LoadParamClassDescription::classList->begin(); 187 while (it != LoadParamClassDescription::classList->end()) 188 188 { 189 189 if ((*it)->className == className) … … 194 194 } 195 195 } 196 return new Load ClassDescription(className);196 return new LoadParamClassDescription(className); 197 197 } 198 198 … … 201 201 * @param paramName the name of the parameter to add. 202 202 */ 203 LoadParamDescription* Load ClassDescription::addParam(const std::string& paramName)203 LoadParamDescription* LoadParamClassDescription::addParam(const std::string& paramName) 204 204 { 205 205 std::list<LoadParamDescription*>::iterator it = this->paramList.begin(); … … 224 224 * @todo implement it 225 225 */ 226 void Load ClassDescription::printAll(const std::string& fileName)226 void LoadParamClassDescription::printAll(const std::string& fileName) 227 227 { 228 228 PRINT(3)("===============================================================\n"); 229 229 PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n"); 230 if (Load ClassDescription::classList != NULL)231 { 232 std::list<Load ClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin();233 while (classDesc != Load ClassDescription::classList->end())230 if (LoadParamClassDescription::classList != NULL) 231 { 232 std::list<LoadParamClassDescription*>::iterator classDesc = LoadParamClassDescription::classList->begin(); 233 while (classDesc != LoadParamClassDescription::classList->end()) 234 234 { 235 235 PRINT(3)("<%s>\n", (*classDesc)->className.c_str()); … … 255 255 * !! The strings MUST NOT be deleted !! 256 256 */ 257 std::list<std::string> Load ClassDescription::searchClassWithShort(const std::string& classNameBegin)257 std::list<std::string> LoadParamClassDescription::searchClassWithShort(const std::string& classNameBegin) 258 258 { 259 259 /// FIXME … … 262 262 std::list<const std::string&> retVal; 263 263 264 tIterator<Load ClassDescription>* iterator = LoadClassDescription::classList->getIterator();265 Load ClassDescription* enumClassDesc = iterator->firstElement();264 tIterator<LoadParamClassDescription>* iterator = LoadParamClassDescription::classList->getIterator(); 265 LoadParamClassDescription* enumClassDesc = iterator->firstElement(); 266 266 while (enumClassDesc) 267 267 { -
branches/new_class_id/src/lib/util/loading/load_param_class_description.h
r9764 r9765 15 15 16 16 /*! 17 * @file load_param .h17 * @file load_param_class_description.h 18 18 * A Class and macro-functions, that makes our lives easy to load-in parameters 19 19 */ 20 20 21 #ifndef _LOAD_PARAM_ DESCRIPTION_H22 #define _LOAD_PARAM_ DESCRIPTION_H21 #ifndef _LOAD_PARAM_CLASS_DESCRIPTION_H 22 #define _LOAD_PARAM_CLASS_DESCRIPTION_H 23 23 24 #include <list>25 #include <s tring>24 #include "load_param_description.h" 25 #include <set> 26 26 27 27 // Forward Declaration // 28 28 class MultiType; 29 29 30 /************************ 31 *** DESCRIPTION STUFF *** 32 ************************/ 33 //! A class that handles the description of loadable parameters 34 class LoadParamDescription 30 //! A class for descriptions of a loadable module 31 class LoadParamClassDescription 35 32 { 36 friend class LoadParam;37 friend class LoadClassDescription;38 33 public: 39 LoadParam Description(const std::string& paramName);40 ~LoadParam Description();34 LoadParamClassDescription(const std::string& className); 35 ~LoadParamClassDescription(); 41 36 42 void setDescription(const std::string& descriptionText);43 /** @returns the descriptionString */44 const std::string& getDescription() { return this->description; };37 bool operator==(const std::string& className) const { return this->className == className; }; 38 bool operator==(const LoadParamClassDescription& classDescr) const { return this->className == classDescr.className; }; 39 bool operator<(const LoadParamClassDescription& classDescr) const { return this->className < classDescr.className; } 45 40 46 void print() const; 47 48 private: 49 std::string description; //!< A longer description about this function. 50 51 std::vector<std::string> parameters; 52 std::vector<std::string> defaultValues; 53 54 }; 55 56 57 58 59 //! A class for descriptions of a loadable module 60 class LoadClassDescription 61 { 62 friend class LoadParamBase; 63 public: 64 LoadClassDescription(const std::string& className); 65 ~LoadClassDescription(); 66 67 static LoadClassDescription* addClass(const std::string& className); 41 static LoadParamClassDescription* addClass(const std::string& className); 68 42 LoadParamDescription* addParam(const std::string& paramName); 69 43 … … 75 49 76 50 private: 51 typedef std::set<LoadParamClassDescription> ClassDescriptionSet; 52 typedef std::set<LoadParamDescription> ParamDescriptionSet; 53 77 54 static bool parametersDescription; //!< if parameter-description should be enabled. 78 static std::vector<LoadClassDescription*>*classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded)55 static ClassDescriptionSet* classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded) 79 56 std::string className; //!< name of the class 80 57 81 std::vector<LoadParamDescription*> paramList; //!< List of parameters this class knows.58 ParamDescriptionSet parameters; //!< List of parameters this class knows. 82 59 }; 83 60 84 #endif /* _LOAD_PARAM_ DESCRIPTION_H */61 #endif /* _LOAD_PARAM_CLASS_DESCRIPTION_H */ -
branches/new_class_id/src/lib/util/loading/load_param_description.cc
r8362 r9765 17 17 18 18 #include "multi_type.h" 19 #include <stdarg.h>20 19 #include "debug.h" 21 20 … … 24 23 */ 25 24 LoadParamDescription::LoadParamDescription(const std::string& paramName) 26 { 27 this->types = NULL; 28 this->defaultValues = NULL; 29 this->paramName = paramName; 30 } 25 : name(paramName) 26 { } 31 27 32 28 /** … … 35 31 LoadParamDescription::~LoadParamDescription() 36 32 { 37 if (this->defaultValues != NULL)38 {39 for(int i = 0; i < this->paramCount; i++)40 {41 delete[] this->defaultValues[i];42 }43 }44 45 delete[] this->types;46 delete[] this->defaultValues;47 33 } 48 34 … … 60 46 void LoadParamDescription::print() const 61 47 { 62 PRINT(3)(" <%s>", this-> paramName.c_str());63 for ( int i = 0; i < this->paramCount; i++)48 PRINT(3)(" <%s>", this->name.c_str()); 49 for (unsigned int i = 0; i < this->parameterCount; i++) 64 50 { 65 51 if (i > 0) … … 97 83 // } 98 84 } 99 PRINT(3)("</%s>", this-> paramName.c_str());85 PRINT(3)("</%s>", this->name.c_str()); 100 86 if (!this->description.empty()) 101 87 PRINT(3)(" -- %s", this->description.c_str()); 102 88 // default values 103 if (this->param Count > 0)89 if (this->parameterCount > 0) 104 90 { 105 91 PRINT(3)(" (Default: "); 106 for ( int i = 0; i < this->paramCount; i++)92 for (unsigned int i = 0; i < this->parameterCount; i++) 107 93 { 108 94 if (i > 0) 109 95 PRINT(3)(", "); 110 if (this->types[i] & MT_STRING)96 if (this->types[i] == "string") 111 97 { // leave brackets !! 112 PRINT(3)("\"%s\"", this->defaultValues[i]);98 PRINT(3)("\"%s\"", this->defaultValues[i].c_str()); 113 99 } 114 100 else 115 101 { 116 PRINT(3)("%s", this->defaultValues[i]);102 PRINT(3)("%s", this->defaultValues[i].c_str()); 117 103 } 118 104 } … … 121 107 PRINT(3)("\n"); 122 108 } 123 124 /**125 * A list, that holds all the classes that are loadable (classes not objects!!)126 */127 std::list<LoadClassDescription*>* LoadClassDescription::classList = NULL;128 129 /**130 * if the description of Parameters should be executed131 */132 bool LoadClassDescription::parametersDescription = false;133 134 /**135 * @param className the name of the class to be loadable136 */137 LoadClassDescription::LoadClassDescription(const std::string& className)138 {139 this->className = className;140 141 if (LoadClassDescription::classList == NULL)142 LoadClassDescription::classList = new std::list<LoadClassDescription*>;143 144 LoadClassDescription::classList->push_back(this);145 }146 147 /**148 * deletes a classDescription (deletes all the parameterDescriptions as well149 */150 LoadClassDescription::~LoadClassDescription()151 {152 std::list<LoadParamDescription*>::iterator it = this->paramList.begin();153 while (!this->paramList.empty())154 {155 delete this->paramList.front();156 this->paramList.pop_front();157 }158 }159 160 void LoadClassDescription::deleteAllDescriptions()161 {162 if (LoadClassDescription::classList != NULL)163 {164 while (!LoadClassDescription::classList->empty())165 {166 delete LoadClassDescription::classList->front();167 LoadClassDescription::classList->pop_front();168 }169 delete LoadClassDescription::classList;170 }171 LoadClassDescription::classList = NULL;172 }173 174 175 /**176 * adds a class to the list of loadable classes177 * @param className The name of the class to add178 179 this function searches for the className string, and if found just returns the appropriate Class.180 Otherwise it returns a new classDescription181 */182 LoadClassDescription* LoadClassDescription::addClass(const std::string& className)183 {184 if (LoadClassDescription::classList != NULL)185 {186 std::list<LoadClassDescription*>::iterator it = LoadClassDescription::classList->begin();187 while (it != LoadClassDescription::classList->end())188 {189 if ((*it)->className == className)190 {191 return (*it);192 }193 it++;194 }195 }196 return new LoadClassDescription(className);197 }198 199 /**200 * does the same as addClass(const std::string& className), but with params201 * @param paramName the name of the parameter to add.202 */203 LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName)204 {205 std::list<LoadParamDescription*>::iterator it = this->paramList.begin();206 while (it != this->paramList.end())207 {208 if ((*it)->paramName == paramName)209 {210 return NULL;211 }212 it++;213 }214 215 LoadParamDescription* newParam = new LoadParamDescription(paramName);216 217 this->paramList.push_back(newParam);218 return newParam;219 }220 221 /**222 * prints out all loadable Classes, and their parameters223 * @param fileName prints the output to a File224 * @todo implement it225 */226 void LoadClassDescription::printAll(const std::string& fileName)227 {228 PRINT(3)("===============================================================\n");229 PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");230 if (LoadClassDescription::classList != NULL)231 {232 std::list<LoadClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin();233 while (classDesc != LoadClassDescription::classList->end())234 {235 PRINT(3)("<%s>\n", (*classDesc)->className.c_str());236 std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin();237 while (param != (*classDesc)->paramList.end())238 {239 (*param)->print();240 param++;241 }242 PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str());243 classDesc++;244 }245 }246 else247 PRINT(3)("no Classes defined so far\n");248 PRINT(3)("===============================================================\n");249 }250 251 /**252 * searches for classes, which beginn with classNameBegin253 * @param classNameBegin the beginning string of a Class254 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,255 * !! The strings MUST NOT be deleted !!256 */257 std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin)258 {259 /// FIXME260 // NOT USED261 /* unsigned int searchLength = strlen(classNameBegin);262 std::list<const std::string&> retVal;263 264 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();265 LoadClassDescription* enumClassDesc = iterator->firstElement();266 while (enumClassDesc)267 {268 if (strlen(enumClassDesc->className)>searchLength+1 &&269 !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))270 {271 retVal->add(enumClassDesc->className);272 }273 enumClassDesc = iterator->nextElement();274 }275 delete iterator;276 277 return retVal;*/278 std::list<std::string> a;279 return a;280 } -
branches/new_class_id/src/lib/util/loading/load_param_description.h
r9764 r9765 15 15 16 16 /*! 17 * @file load_param .h17 * @file load_param_description.h 18 18 * A Class and macro-functions, that makes our lives easy to load-in parameters 19 19 */ … … 22 22 #define _LOAD_PARAM_DESCRIPTION_H 23 23 24 #include < list>24 #include <vector> 25 25 #include <string> 26 26 … … 34 34 class LoadParamDescription 35 35 { 36 friend class LoadParam;37 friend class LoadClassDescription;38 36 public: 39 37 LoadParamDescription(const std::string& paramName); 40 38 ~LoadParamDescription(); 39 40 bool operator==(const std::string& paramName) const { return this->name == paramName; }; 41 bool operator==(const LoadParamDescription& paramDescr) const { return this->name == paramDescr.name; }; 42 bool operator<(const LoadParamDescription& paramDescr) const { return this->name < paramDescr.name; }; 41 43 42 44 void setDescription(const std::string& descriptionText); … … 47 49 48 50 private: 51 const std::string name; //!< The Name of the Parameter. 52 unsigned int parameterCount; //!< The Count of parameters. 49 53 std::string description; //!< A longer description about this function. 50 54 51 std::vector<std::string> parameters;55 std::vector<std::string> types; 52 56 std::vector<std::string> defaultValues; 53 57 54 58 }; 55 59 56 57 58 59 //! A class for descriptions of a loadable module60 class LoadClassDescription61 {62 friend class LoadParamBase;63 public:64 LoadClassDescription(const std::string& className);65 ~LoadClassDescription();66 67 static LoadClassDescription* addClass(const std::string& className);68 LoadParamDescription* addParam(const std::string& paramName);69 70 static void deleteAllDescriptions();71 72 static void printAll(const std::string& fileName = "");73 static std::list<std::string> searchClassWithShort(const std::string& classNameBegin);74 // static const LoadParamDescription* getClass(const std::string& className);75 76 private:77 static bool parametersDescription; //!< if parameter-description should be enabled.78 static std::vector<LoadClassDescription*>* classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded)79 std::string className; //!< name of the class80 81 std::vector<LoadParamDescription*> paramList; //!< List of parameters this class knows.82 };83 84 60 #endif /* _LOAD_PARAM_DESCRIPTION_H */
Note: See TracChangeset
for help on using the changeset viewer.