/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christian Meyer co-programmer: Benjamin Grauer */ #include "factory.h" #include "game_loader.h" using namespace std; /* -------------------------------------------------- * Factory * -------------------------------------------------- */ /** \brief constructor set everything to zero and define factoryName */ Factory::Factory (const char* factoryName) { this->factoryName = NULL; this->setFactoryName(factoryName); next = NULL; initialize(); } /** \brief destructor clear the Q */ Factory::~Factory () { // printf("%s\n", this->factoryName); // Factory* tmpDel = this->next; // this->next = NULL; if (this->next) delete this->next; if (this->factoryName) delete []this->factoryName; } /** \brief sets the name of this factory */ void Factory::setFactoryName(const char* factoryName) { if (this->factoryName) delete this->factoryName; this->factoryName = new char[strlen(factoryName)+1]; strcpy(this->factoryName, factoryName); } /** \brief generates the associated object from data */ BaseObject* Factory::fabricate(const TiXmlElement* data) { return NULL; } /** \brief make this particular factory known to the LevelFactory */ void Factory::initialize() { GameLoader* gl = GameLoader::getInstance(); gl->registerFactory( this); } /** \brief add a Factory to the Q */ void Factory::registerFactory( Factory* factory) { if( next == NULL) setNext( factory); else next->registerFactory( factory); } /** \param root: The XML-element to grab a parameter from \param parameterName: the parameter to grab \returns the Value of the parameter if found, NULL otherwise */ const char* grabParameter(const TiXmlElement* root, const char* parameterName) { const TiXmlElement* element; const TiXmlNode* node; if (root == NULL) return NULL; assert( parameterName != NULL); element = root->FirstChildElement( parameterName); if( element == NULL) return NULL; node = element->FirstChild(); while( node != NULL) { if( node->ToText()) return node->Value(); node = node->NextSibling(); } return NULL; }