Changeset 4487 in orxonox.OLD for orxonox/trunk/src/util/loading
- Timestamp:
- Jun 3, 2005, 12:56:57 AM (19 years ago)
- Location:
- orxonox/trunk/src/util/loading
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/loading/factory.cc
r4261 r4487 30 30 set everything to zero and define factoryName 31 31 */ 32 Factory::Factory (const char* name)32 Factory::Factory (const char* factoryName) 33 33 { 34 34 this->factoryName = NULL; 35 this->setFactoryName( name);35 this->setFactoryName(factoryName); 36 36 next = NULL; 37 37 … … 51 51 if (this->next) 52 52 delete this->next; 53 54 if (this->factoryName) 55 delete []this->factoryName; 53 56 } 54 57 55 void Factory::setFactoryName(const char* name) 58 /** 59 \brief sets the name of this factory 60 */ 61 void Factory::setFactoryName(const char* factoryName) 56 62 { 57 if ( factoryName)58 delete factoryName;59 factoryName = new char[strlen(name)+1];60 strcpy( factoryName, name);63 if (this->factoryName) 64 delete this->factoryName; 65 this->factoryName = new char[strlen(factoryName)+1]; 66 strcpy(this->factoryName, factoryName); 61 67 } 62 68 … … 88 94 } 89 95 90 const char* grabParameter(const TiXmlElement* root, const char* name) 96 /** 97 \param root: The XML-element to grab a parameter from 98 \param parameterName: the parameter to grab 99 \returns the Value of the parameter if found, NULL otherwise 100 */ 101 const char* grabParameter(const TiXmlElement* root, const char* parameterName) 91 102 { 92 103 const TiXmlElement* element; … … 95 106 if (root == NULL) 96 107 return NULL; 97 assert( name != NULL);108 assert( parameterName != NULL); 98 109 99 element = root->FirstChildElement( name);110 element = root->FirstChildElement( parameterName); 100 111 if( element == NULL) return NULL; 101 112 -
orxonox/trunk/src/util/loading/factory.h
r4261 r4487 16 16 /*! 17 17 \file factory.h 18 \brief philosophy stuff18 \brief A loadable object handler 19 19 */ 20 20 … … 34 34 */ 35 35 #define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##Factory = new tFactory<CLASS_NAME>(#CLASS_NAME) 36 //! The Factory is 36 37 //! The Factory is a loadable object handler 37 38 class Factory { 38 39 39 40 public: 40 Factory (const char* name = NULL);41 Factory (const char* factoryName = NULL); 41 42 ~Factory (); 42 43 … … 45 46 void initialize(); 46 47 void registerFactory( Factory* factory); 47 void setFactoryName(const char* name); 48 const char* getFactoryName() {return factoryName;}; 49 void setNext( Factory* factory) {next = factory;} 50 Factory* getNext() {return next;} 48 void setFactoryName(const char* factoryName); 49 /** \returns the name of the factory */ 50 const char* getFactoryName() { return this->factoryName; }; 51 /** \brief sets the Next factory in the list \param nextFactory the next factory */ 52 inline void setNext( Factory* nextFactory) { this->next = nextFactory; }; 53 /** \returns the next factory */ 54 Factory* getNext(void) const { return this->next; }; 51 55 56 protected: 57 char* factoryName; //!< the name of the factory 52 58 private: 53 char* factoryName; 54 55 Factory* next; 59 Factory* next; //!< pointer to the next factory. 56 60 }; 57 61 62 /** 63 \brief a factory that is able to load any kind of Object 64 (this is a Functor) 65 */ 58 66 template<class T> class tFactory : public Factory 59 67 { 60 68 public: 61 tFactory(const char* name);69 tFactory(const char* factoryName); 62 70 virtual ~tFactory(); 63 71 … … 66 74 }; 67 75 76 /** 77 \brief construnts a factory with 78 \param factoryName the name of the factory 79 */ 68 80 template<class T> 69 tFactory<T>::tFactory(const char* name) : Factory(name)81 tFactory<T>::tFactory(const char* factoryName) : Factory(factoryName) 70 82 { 71 PRINTF(5)("fileName: %s \n", name);83 PRINTF(5)("fileName: %s loadable\n", this->factoryName); 72 84 } 73 85 … … 90 102 // helper function 91 103 92 const char* grabParameter(const TiXmlElement* root, const char* name);104 const char* grabParameter(const TiXmlElement* root, const char* parameterName); 93 105 94 106 #endif /* _FACTORY_H */ -
orxonox/trunk/src/util/loading/game_loader.cc
r4445 r4487 37 37 38 38 /** 39 \brief simple constructor40 39 \brief simple constructor 40 */ 41 41 GameLoader::GameLoader () 42 42 { … … 46 46 47 47 /** 48 \brief simple deconstructor49 48 \brief simple deconstructor 49 */ 50 50 GameLoader::~GameLoader () {} 51 51 … … 64 64 } 65 65 66 66 /** 67 \brief initializes the GameLoader 68 */ 67 69 ErrorMessage GameLoader::init() 68 70 { … … 80 82 /** 81 83 \brief reads a campaign definition file into a campaign class 82 \param file name to be loaded84 \param fileName to be loaded 83 85 \returns the loaded campaign 84 86 85 87 this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 86 88 */ 87 ErrorMessage GameLoader::loadCampaign(const char* name)89 ErrorMessage GameLoader::loadCampaign(const char* fileName) 88 90 { 89 91 ErrorMessage errorCode; 90 char* campaignName = ResourceManager::getFullName( name);92 char* campaignName = ResourceManager::getFullName(fileName); 91 93 if (campaignName) 92 94 { … … 101 103 /** 102 104 \brief loads a debug campaign for test purposes only. 103 \param the identifier of the campaign.105 \param campaignID the identifier of the campaign. 104 106 \returns error message if not able to do so. 105 107 */ … … 198 200 */ 199 201 ErrorMessage GameLoader::destroy() 200 {} 202 { 203 204 } 201 205 202 206 203 207 /** 204 208 \brief reads a campaign definition file into a campaign class 205 \param file name to be loaded209 \param fileName to be loaded 206 210 \returns the loaded campaign 207 211 208 212 this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 209 213 */ 210 Campaign* GameLoader::fileToCampaign(const char *name)214 Campaign* GameLoader::fileToCampaign(const char* fileName) 211 215 { 212 216 /* do not entirely load the campaign. just the current world … … 215 219 */ 216 220 217 if( name == NULL)221 if( fileName == NULL) 218 222 { 219 223 PRINTF(2)("No filename specified for loading"); … … 221 225 } 222 226 223 TiXmlDocument* XMLDoc = new TiXmlDocument( name);227 TiXmlDocument* XMLDoc = new TiXmlDocument( fileName); 224 228 // load the campaign document 225 229 if( !XMLDoc->LoadFile()) 226 230 { 227 231 // report an error 228 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", name, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());232 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 229 233 delete XMLDoc; 230 234 return NULL; … … 255 259 /** 256 260 \brief handle keyboard commands 257 \param the event to handle261 \param event the event to handle 258 262 */ 259 263 void GameLoader::process(const Event& event) … … 290 294 291 295 292 /* 296 /** 293 297 \brief this changes to the next level 294 298 */ … … 300 304 301 305 302 /* 306 /** 303 307 \brief change to the previous level - not implemented 304 308 -
orxonox/trunk/src/util/loading/game_loader.h
r4411 r4487 42 42 43 43 public: 44 ~GameLoader (); 45 44 46 static GameLoader* getInstance(); 45 47 … … 55 57 void previousLevel(); 56 58 59 /** \brief a world command to send to the GameLoader \param cmd the command */ 57 60 bool worldCommand(Command* cmd); 58 61 ErrorMessage loadDebugCampaign(Uint32 campaignID); 59 62 60 void registerFactory( Factory* factory );63 void registerFactory( Factory* factory ); 61 64 BaseObject* fabricate( TiXmlElement* data); 62 65 … … 65 68 private: 66 69 GameLoader (); 67 ~GameLoader ();68 Uint32 startTime; //!> start time of the campaign69 static GameLoader* singletonRef;70 bool isPaused;71 70 72 Campaign* currentCampaign; //!> the current campaign playing 71 Campaign* fileToCampaign(const char* name); 72 73 private: 74 static GameLoader* singletonRef; //!< The singleton-reference to this object 75 76 Uint32 startTime; //!< start time of the campaign 77 bool isPaused; //!< if the game is paused 78 79 Campaign* currentCampaign; //!< the current campaign playing 73 80 74 Campaign* fileToCampaign(const char* name); 75 EventHandler* eventHandler; 81 EventHandler* eventHandler; //!< reference to the eventHandler 76 82 77 Factory* first;83 Factory* first; //!< the first factory of them all 78 84 }; 79 85 -
orxonox/trunk/src/util/loading/load_param.cc
r4299 r4487 23 23 /** 24 24 \param object The object this Parameter is loaded too. 25 \param paramName The name of the parameter loaded. 26 \param paramCount how many parameters this loading-function takes 27 \param ... the parameter information 25 \param root: the XML-element to load this option from. 26 \param paramName: The name of the parameter loaded. 27 \param paramCount: how many parameters this loading-function takes 28 \param ...: the parameter information 28 29 */ 29 30 BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName, int paramCount, ...) -
orxonox/trunk/src/util/loading/load_param.h
r4318 r4487 38 38 */ 39 39 40 #define l_INT_TYPE int41 #define l_INT_FUNC atoi42 #define l_INT_NAME "int"43 44 #define l_LONG_TYPE long45 #define l_LONG_FUNC atol46 #define l_LONG_NAME "long"47 48 #define l_SHORT_TYPE short49 #define l_SHORT_FUNC atoi50 #define l_SHORT_NAME "short"51 52 #define l_FLOAT_TYPE float53 #define l_FLOAT_FUNC atof54 #define l_FLOAT_NAME "float"55 56 #define l_STRING_TYPE const char*57 #define l_STRING_FUNC 58 #define l_STRING_NAME "string"59 60 61 /** 62 \brief a Macro to easily implement many different Constructors for the LoadParam-Class 40 #define l_INT_TYPE int //!< The type of an INT 41 #define l_INT_FUNC atoi //!< the function to call to parse INT 42 #define l_INT_NAME "int" //!< the name of an INT 43 44 #define l_LONG_TYPE long //!< The type of a LONG 45 #define l_LONG_FUNC atol //!< The function to parse a LONG 46 #define l_LONG_NAME "long" //!< The name of a LONG 47 48 #define l_SHORT_TYPE short //!< The type of a SHORT 49 #define l_SHORT_FUNC atoi //!< The function to parse a SHORT 50 #define l_SHORT_NAME "short" //!< The name of a SHORT 51 52 #define l_FLOAT_TYPE float //!< The type of a FLOAT 53 #define l_FLOAT_FUNC atof //!< The function to parse a FLOAT 54 #define l_FLOAT_NAME "float" //!< The name of a FLOAT 55 56 #define l_STRING_TYPE const char* //!< The type fo a STRING 57 #define l_STRING_FUNC //!< The function to parse a STRING 58 #define l_STRING_NAME "string" //!< The name of a STRING 59 60 // 1. TYPE 61 /** 62 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 1 argument 63 63 \param type1 The type of the first functionParameter 64 64 */ … … 75 75 76 76 // 2. TYPES 77 /** 78 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 2 arguments 79 \param type1 The type of the first functionParameter 80 \param type2 The type of the second functionParameter 81 */ 77 82 #define LoadParam2(type1, type2) \ 78 83 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE)) \ … … 94 99 95 100 // 3. TYPES 101 /** 102 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 3 arguments 103 \param type1 The type of the first functionParameter 104 \param type2 The type of the second functionParameter 105 \param type3 The type of the third functionParameter 106 */ 96 107 #define LoadParam3(type1, type2, type3) \ 97 108 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE))\ … … 113 124 114 125 // 4. TYPES 126 /** 127 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 4 arguments 128 \param type1 The type of the first functionParameter 129 \param type2 The type of the second functionParameter 130 \param type3 The type of the third functionParameter 131 \param type4 The type of the forth functionParameter 132 */ 115 133 #define LoadParam4(type1, type2, type3, type4) \ 116 134 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE)) \ … … 132 150 133 151 // 5. TYPES 152 /** 153 \brief a Macro to easily implement many different Constructors for the LoadParam-Class with 5 arguments 154 \param type1 The type of the first functionParameter 155 \param type2 The type of the second functionParameter 156 \param type3 The type of the third functionParameter 157 \param type4 The type of the forth functionParameter 158 \param type5 The type of the fifth functionParameter 159 */ 134 160 #define LoadParam5(type1, type2, type3, type4, type5) \ 135 161 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE)) \ … … 161 187 void setDescription(const char* descriptionText); 162 188 /** \returns the descriptionString */ 163 const char* getDescription(void) { return this->description; };189 const char* getDescription(void) { return this->description; }; 164 190 165 191 void print(void) const; 166 192 private: 167 char* paramName; //!< The name of the parameter 168 int paramCount; //!< The count of parameters 169 char** types; //!< What kind of parameters does this function take ?? 170 char* description; //!< A longer description about this function 171 }; 172 193 char* paramName; //!< The name of the parameter 194 int paramCount; //!< The count of parameters 195 char** types; //!< What kind of parameters does this function take ?? 196 char* description; //!< A longer description about this function 197 }; 198 199 //! A class for descriptions of a loadable module 173 200 class LoadClassDescription 174 201 { … … 184 211 static void printAll(const char* fileName = NULL); 185 212 186 static bool parametersDescription; //!< if parameter-description should be enabled.187 static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded)188 213 private: 189 char* className; //!< name of the class 190 tList<LoadParamDescription>* paramList; //!< List of parameters this class knows. 191 }; 192 193 // abstract Base class 214 static bool parametersDescription; //!< if parameter-description should be enabled. 215 static tList<LoadClassDescription>* classList; //!< a list, that holds all the loadable classes. (after one instance has been loaded) 216 char* className; //!< name of the class 217 tList<LoadParamDescription>* paramList; //!< List of parameters this class knows. 218 }; 219 220 //! abstract Base class for a Loadable parameter 194 221 class BaseLoadParam 195 222 { … … 201 228 202 229 protected: 203 LoadClassDescription* classDesc;//!< The LoadClassDescription of this LoadParameter204 LoadParamDescription* paramDesc;//!< The LoadParameterDescription of this LoadParameter205 const char* loadString;//!< The string loaded by this LoadParam230 LoadClassDescription* classDesc; //!< The LoadClassDescription of this LoadParameter 231 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 232 const char* loadString; //!< The string loaded by this LoadParam 206 233 }; 207 234 … … 211 238 { 212 239 public: 240 //! makes functions with one string loadable 213 241 LoadParam1(l_STRING); 242 //! makes functions with two strings loadable 214 243 LoadParam2(l_STRING, l_STRING); 244 //! makes functions with three strings loadable 215 245 LoadParam3(l_STRING, l_STRING, l_STRING); 246 //! makes functions with four strings loadable 216 247 LoadParam4(l_STRING, l_STRING, l_STRING, l_STRING); 217 248 249 //! makes functions with one int loadable 218 250 LoadParam1(l_INT); 251 //! makes functions with two ints loadable 219 252 LoadParam2(l_INT, l_INT); 253 //! makes functions with three ints loadable 220 254 LoadParam3(l_INT, l_INT, l_INT); 255 //! makes functions with four ints loadable 221 256 LoadParam4(l_INT, l_INT, l_INT, l_INT); 222 257 258 //! makes functions with one float loadable 223 259 LoadParam1(l_FLOAT); 260 //! makes functions with two floats loadable 224 261 LoadParam2(l_FLOAT, l_FLOAT); 262 //! makes functions with three floats loadable 225 263 LoadParam3(l_FLOAT, l_FLOAT, l_FLOAT); 264 //! makes functions with four floats loadable 226 265 LoadParam4(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT); 227 266 };
Note: See TracChangeset
for help on using the changeset viewer.