Changeset 790 for code/trunk/src
- Timestamp:
- Feb 7, 2008, 5:01:44 PM (17 years ago)
- Location:
- code/trunk
- Files:
-
- 9 deleted
- 24 edited
- 160 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
Property
svn:ignore
set to
dependencies
-
Property
svn:ignore
set to
-
code/trunk/src/CMakeLists.txt
r258 r790 1 PROJECT(Orxonox) 1 INCLUDE_DIRECTORIES(.) 2 INCLUDE_DIRECTORIES(orxonox) 2 3 3 # create a few variables to simplify life 4 SET(SRC_FILES orxonox/orxonox.cc loader/LevelLoader.cc xml/xmlParser.cc orxonox/core/IdentifierList.cc orxonox/core/Identifier.cc orxonox/core/MetaObjectList.cc orxonox/core/Factory.cc orxonox/core/OrxonoxClass.cc orxonox/objects/BaseObject.cc orxonox/objects/test1.cc orxonox/objects/test2.cc orxonox/objects/test3.cc) 5 SET(INC_FILES loader/LevelLoader.h xml/xmlParser.h orxonox/core/IdentifierIncludes.h orxonox/core/Identifier.h orxonox/core/Factory.h orxonox/core/ClassFactory.h orxonox/core/IdentifierList.h orxonox/core/ObjectList.h orxonox/core/MetaObjectList.h orxonox/core/Iterator.h orxonox/core/OrxonoxClass.h orxonox/objects/BaseObject.h orxonox/objects/Test.h orxonox/objects/test1.h orxonox/objects/test2.h orxonox/objects/test3.h) 6 7 #Creates an executable 8 ADD_EXECUTABLE(../bin/main ${SRC_FILES} ${INC_FILES}) 9 #Links the executable against OGRE and OIS 10 TARGET_LINK_LIBRARIES(../bin/main ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${CEGUI_LIBRARIES} ${CEGUI_OGRE_LIBRARIES}) 11 4 ADD_SUBDIRECTORY(util) 5 ADD_SUBDIRECTORY(orxonox/core) 6 ADD_SUBDIRECTORY(audio) 7 ADD_SUBDIRECTORY(network) 8 ADD_SUBDIRECTORY(loader) 9 ADD_SUBDIRECTORY(orxonox) -
code/trunk/src/loader/LevelLoader.cc
r164 r790 1 #include <string.h> 2 #include <iostream> 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Nicolas Perrenoud <nicolape@ee.ethz.ch> 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 #include "OrxonoxStableHeaders.h" 29 30 #include <OgreOverlay.h> 31 #include <OgreOverlayManager.h> 32 33 #include "core/Error.h" 34 #include "core/Debug.h" 35 #include "core/CoreIncludes.h" 36 37 #include "audio/AudioManager.h" 38 #include "core/BaseObject.h" 39 #include "orxonox/Orxonox.h" 3 40 4 41 #include "LevelLoader.h" 5 #include "../xml/xmlParser.h"6 7 using namespace std;8 42 9 43 namespace loader 10 44 { 11 45 12 LevelLoader::LevelLoader(string file, string dir) 13 { 14 // Load XML level file 15 dir.append("/"); 16 dir.append(file); 17 rootNode = XMLNode::openFileHelper(dir.c_str(),"WorldDataFile"); 18 // TODO: Error handling 19 20 // Assing general level infos to class variables 21 this->name_ = rootNode.getChildNode("name").getText(); 22 this->description_ = rootNode.getChildNode("description").getText(); 23 this->image_ = rootNode.getChildNode("image").getText(); 24 25 this->loadingScreen(); 26 27 // Assign sub-nodes 28 if (rootNode.nChildNode("LightManager")==1) 46 LevelLoader::LevelLoader(std::string file, std::string path) 29 47 { 30 // Init Luightmanager... 48 valid_ = false; 49 50 // Load XML level file 51 path.append("/"); 52 path.append(file); 53 54 // Open xml file 55 doc_.LoadFile(path.c_str()); 56 57 // Check if file was loaded 58 if (doc_.LoadFile()) 59 { 60 TiXmlHandle hDoc(&doc_); 61 TiXmlHandle hRoot(0); 62 TiXmlElement* pElem; 63 64 // Check for root element 65 pElem = hDoc.FirstChildElement("orxonoxworld").Element(); 66 if (pElem) 67 { 68 // Set root element 69 hRoot = TiXmlHandle(pElem); 70 rootElement_ = hRoot.Element(); 71 72 // Set level description 73 pElem = hRoot.FirstChild("description").Element(); 74 if (pElem) 75 { 76 description_ = pElem->GetText(); 77 } 78 79 // Set level name 80 name_ = rootElement_->Attribute("name"); 81 image_ = rootElement_->Attribute("image"); 82 83 valid_ = true; 84 } 85 else 86 { 87 orxonox::Error("Level file has no valid root node"); 88 } 89 } 90 else 91 { 92 orxonox::Error("Could not load level file "); 93 } 31 94 } 32 33 /* 34 35 worldNode = rootNode.getChildNode("WorldEntities"); 36 scriptNode = rootNode.getChildNode("ScriptManager"); 37 cameraNode = rootNode.getChildNode("CameraMan"); 38 lightNode = rootNode.getChildNode("LightManager"); 39 */ 95 96 void LevelLoader::loadLevel() 97 { 98 if (valid_) 99 { 100 TiXmlElement* loadElem; 101 TiXmlElement* audioElem; 102 TiXmlElement* worldElem; 103 TiXmlElement* tElem; 104 TiXmlNode* tNode; 105 106 Ogre::OverlayManager& omgr = Ogre::OverlayManager::getSingleton(); 107 Ogre::Overlay* mLoadOverlay; // FIXME: may be uninitialized 108 109 // Set loading screen 110 loadElem = rootElement_->FirstChildElement("loading"); 111 if (loadElem) 112 { 113 // Set background 114 tElem = loadElem->FirstChildElement("background"); 115 if (tElem) 116 { 117 loadingBackgroundColor_ = tElem->Attribute("color"); 118 loadingBackgroundImage_ = tElem->Attribute("image"); 119 } 120 // Set bar 121 tElem = loadElem->FirstChildElement("bar"); 122 if (tElem) 123 { 124 loadingBarImage_ = tElem->Attribute("image");; 125 loadingBarTop_ = tElem->Attribute("top"); 126 loadingBarLeft_ = tElem->Attribute("left"); 127 loadingBarWidth_ = tElem->Attribute("width"); 128 loadingBarHeight_ = tElem->Attribute("height"); 129 } 130 131 132 mLoadOverlay = (Ogre::Overlay*)omgr.getByName("Orxonox/LoadingScreenSample"); 133 mLoadOverlay->show(); 134 135 COUT(0) << "This is Orxonox" << std::endl; 136 COUT(0) << "the hottest 3D action shooter ever to exist" << std::endl; 137 COUT(0) << "Level: " << name() << std::endl << "Description:" << description() << std::endl << "Image:" << image() << std::endl; 138 COUT(4) << "Backgroundcolor: " << loadingBackgroundColor_ << std::endl << "Backgroundimage:" << loadingBackgroundImage_ << std::endl; 139 140 } 141 142 // Load audio 143 audio::AudioManager* auMan = orxonox::Orxonox::getSingleton()->getAudioManagerPointer(); 144 audioElem = rootElement_->FirstChildElement("audio"); 145 146 if (audioElem) 147 { 148 audioElem = audioElem->FirstChildElement("ambient"); 149 if (audioElem) 150 { 151 tNode = 0; 152 //FIXME something is wrong, probably missing == 153 while( tNode = audioElem->IterateChildren( tNode ) ) 154 { 155 if (tNode->Type() == TiXmlNode::ELEMENT) 156 { 157 158 tElem = tNode->ToElement(); 159 std::string elemVal = tElem->Value(); 160 if (elemVal == "ogg") 161 { 162 COUT(3) << "Adding sound "<< tElem->Attribute("src") << std::endl; 163 164 auMan->ambientAdd(tElem->Attribute("src")); 165 } 166 } 167 } 168 auMan->ambientStart(); 169 } 170 } 171 172 // Load world 173 worldElem = rootElement_->FirstChildElement("world"); 174 if (worldElem) 175 { 176 tNode = 0; 177 //FIXME something is wrong, probably missing == 178 while (tNode = worldElem->IterateChildren(tNode)) 179 { 180 if (tNode->Type() == TiXmlNode::ELEMENT) 181 { 182 tElem = tNode->ToElement(); 183 orxonox::Identifier* id = ID(tElem->Value()); 184 if (id) 185 { 186 orxonox::BaseObject* obj = id->fabricate(); 187 obj->loadParams(tElem); 188 } 189 else 190 { 191 COUT(2) << "Warning: '"<< tElem->Value() <<"' is not a valid classname." << std::endl; 192 } 193 } 194 } 195 } 196 197 if (loadElem) 198 { 199 // FIXME: check for potential initialisation of mLoadOverlay 200 mLoadOverlay->hide(); 201 } 202 203 204 COUT(0) << "Loading finished!" << std::endl << std::endl; 205 } 206 } 207 208 LevelLoader::~LevelLoader() 209 { 210 211 } 40 212 41 213 } 42 43 LevelLoader::~LevelLoader()44 {45 46 47 }48 49 50 string LevelLoader::name()51 {52 return this->name_;53 }54 55 string LevelLoader::description()56 {57 return this->description_;58 }59 60 string LevelLoader::image()61 {62 return this->image_;63 }64 65 void LevelLoader::loadingScreen()66 {67 cout << "\n\n\nThis is Orxonox\nthe hottest 3D action shooter ever to exist\n\n\n";68 cout << "Level: " << name() << "\nDescription:" << description() << "\nImage:"<<image()<<"\n\n\n";69 }70 71 /*72 73 74 void LevelLoader::loadWorld(WorldManager* wm)75 {76 if (!worldNode.getChildNode("lights").isEmpty())77 {78 79 80 }81 }82 83 84 void LevelLoader::loadLights(LightManager* lm)85 {86 if (!lightNode.getChildNode("lights").isEmpty())87 {88 int nLights = lightNode.getChildNode("lights").nChildNode("light");89 for (int i=0; i<nLights;i++)90 {91 XMLNode t = lightNode.getChildNode("lights").getChildNode("light",i);92 const char* diffuse = t.getAttribute("diffuse-color");93 const char* coor = t.getAttribute("abs-coor");94 lm->addLight(diffuse,coor);95 }96 }97 lm->setAmbient(lightNode.getChildNode("ambient").getAttribute("color"));98 }99 100 void LevelLoader::loadCameras(CameraManager* cm)101 {102 if (!cameraNode.getChildNode("cameras").isEmpty())103 {104 int nCameras = cameraNode.getChildNode("cameras").nChildNode("camera");105 for (int i=0; i<nCameras;i++)106 {107 XMLNode t = cameraNode.getChildNode("cameras").getChildNode("camera",i);108 109 110 cm->addCamera();111 }112 }113 }114 115 116 void LevelLoader::loadScripts(ScriptManager* sm)117 {118 if (!scriptNode.getChildNode("scripts").isEmpty())119 {120 int nScripts = scriptNode.getChildNode("scripts").nChildNode("script");121 for (int i=0; i<nScripts;i++)122 {123 XMLNode t = scriptNode.getChildNode("scripts").getChildNode("script",i);124 sm->addScript(t.getAttribute("file"));125 }126 127 }128 }129 */130 131 132 }133 -
code/trunk/src/loader/LevelLoader.h
r164 r790 2 2 * Orxonox - www.orxonox.net 3 3 * Level Loader class 4 * 4 * 5 5 * @author Nicolas Perrenoud <nicolape@ee.ethz.ch> 6 6 */ 7 7 8 #ifndef _LevelLoader_H__ 9 #define _LevelLoader_H__ 10 8 11 #include <string> 9 #include <iostream>10 12 11 #include "../xml/xmlParser.h" 13 #include "LoaderPrereqs.h" 14 #include "util/tinyxml/tinyxml.h" 12 15 13 #ifndef __MODULE_LEVELLOADER__ 14 #define __MODULE_LEVELLOADER__ 15 16 using namespace std; 16 class TiXmlDocument; // Forward declaration 17 class TiXmlElement; // Forward declaration 17 18 18 19 namespace loader 19 20 { 20 class LevelLoader 21 { 22 private: 23 24 // XML Nodes 25 XMLNode rootNode; 26 XMLNode worldNode; 27 XMLNode scriptNode; 28 XMLNode cameraNode; 29 XMLNode lightNode; 30 31 // Level information 32 string name_; 33 string description_; 34 string image_; 35 36 public: 21 class _LoaderExport LevelLoader 22 { 23 public: 24 // Constructors, loads the level file and some information data 25 LevelLoader(std::string file, std::string dir = "levels"); 26 // Destructor 27 virtual ~LevelLoader(); 28 // Loads all level data 29 void loadLevel(); 37 30 38 // Constructors 39 LevelLoader(string file, string dir="levels"); 40 ~LevelLoader(); 41 42 void loadingScreen(); 43 44 // Getters 45 string name(); 46 string description(); 47 string image(); 48 49 // Managers 50 51 52 }; 31 // Getters 32 inline std::string name() {return name_; }; 33 inline std::string description() {return description_; }; 34 inline std::string image() {return image_; }; 35 private: 36 //! Level information 37 std::string name_; 38 std::string description_; 39 std::string image_; 40 std::string loadingBackgroundColor_; 41 std::string loadingBackgroundImage_; 42 std::string loadingBarImage_; 43 std::string loadingBarTop_; 44 std::string loadingBarLeft_; 45 std::string loadingBarWidth_; 46 std::string loadingBarHeight_; 47 48 //! Set to true if it was possible to load the level file 49 bool valid_; 50 51 // Xml-Stuff 52 TiXmlDocument doc_; 53 TiXmlElement *rootElement_; 54 }; 53 55 } 54 #endif 56 57 #endif /* _LevelLoader_H__ */ -
code/trunk/src/orxonox/core/ClassFactory.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file ClassFactory.h 30 @brief Definition and implementation of the ClassFactory class 31 32 The ClassFactory is able to create new objects of a specific class. 33 */ 34 1 35 #ifndef _ClassFactory_H__ 2 36 #define _ClassFactory_H__ 3 37 38 #include <string> 39 40 #include "CorePrereqs.h" 41 42 #include "Factory.h" 4 43 #include "Identifier.h" 44 #include "Debug.h" 5 45 6 46 namespace orxonox … … 9 49 // ### ClassFactory ### 10 50 // ############################### 51 //! The ClassFactory is able to create new objects of a specific class. 11 52 template <class T> 12 53 class ClassFactory : public BaseFactory 13 54 { 14 55 public: 15 static bool create( );56 static bool create(const std::string& name); 16 57 BaseObject* fabricate(); 17 58 18 59 private: 19 ClassFactory() {} 20 ClassFactory(const ClassFactory& factory) {} 21 ~ClassFactory() {}60 ClassFactory() {} // Don't create 61 ClassFactory(const ClassFactory& factory) {} // Don't copy 62 virtual ~ClassFactory() {} // Don't delete 22 63 23 64 static T* createNewObject(); 24 65 }; 25 66 67 /** 68 @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory. 69 @return Always true (this is needed because the compiler only allows assignments before main()) 70 */ 26 71 template <class T> 27 bool ClassFactory<T>::create( )72 bool ClassFactory<T>::create(const std::string& name) 28 73 { 74 COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl; 29 75 ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>); 30 31 ClassIdentifier<T>::getIdentifier()->startCreatingHierarchy(); 32 #if HIERARCHY_VERBOSE 33 std::cout << "*** Create Factory -> Create Class\n"; 34 #endif 35 BaseObject* temp = ClassIdentifier<T>::getIdentifier()->fabricate(); 36 delete temp; 37 ClassIdentifier<T>::getIdentifier()->stopCreatingHierarchy(); 76 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 38 77 39 78 return true; 40 79 } 41 80 81 /** 82 @brief Creates and returns a new object of class T. 83 @return The new object 84 */ 42 85 template <class T> 43 86 BaseObject* ClassFactory<T>::fabricate() … … 46 89 } 47 90 91 /** 92 @brief Creates and returns a new object of class T; this is a wrapper for the new operator. 93 @return The new object 94 */ 48 95 template <class T> 49 96 T* ClassFactory<T>::createNewObject() … … 53 100 } 54 101 55 #endif 102 #endif /* _ClassFactory_H__ */ -
code/trunk/src/orxonox/core/Factory.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file Factory.cc 30 @brief Implementation of the Factory class. 31 */ 32 33 #include "Identifier.h" 34 #include "Debug.h" 35 #include "BaseObject.h" 1 36 #include "Factory.h" 2 #include "Identifier.h"3 37 4 38 namespace orxonox 5 39 { 6 Factory* Factory::pointer_s = NULL; 7 40 /** 41 @returns the Identifier with a given name. 42 @param name The name of the wanted Identifier 43 */ 8 44 Identifier* Factory::getIdentifier(const std::string& name) 9 45 { 10 if (!pointer_s) 11 pointer_s = new Factory; 12 13 return pointer_s->identifierMap_[name]; 46 return getFactoryPointer()->identifierStringMap_[name]; 14 47 } 15 48 49 /** 50 @returns the Identifier with a given network ID. 51 @param id The network ID of the wanted Identifier 52 */ 53 Identifier* Factory::getIdentifier(const unsigned int id) 54 { 55 return getFactoryPointer()->identifierNetworkIDMap_[id]; 56 } 57 58 /** 59 @brief Adds a new Identifier to both maps. 60 @param name The name of the identifier 61 @param identifier The identifier to add 62 */ 16 63 void Factory::add(const std::string& name, Identifier* identifier) 17 64 { 18 if (!pointer_s) 19 pointer_s = new Factory; 65 getFactoryPointer()->identifierStringMap_[name] = identifier; 66 getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; 67 } 20 68 21 pointer_s->identifierMap_[name] = identifier; 69 /** 70 @brief Removes the entry with the old network ID and adds a new one. 71 @param identifier The identifier to change 72 @param oldID The old networkID 73 @param newID The new networkID 74 */ 75 void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID) 76 { 77 getFactoryPointer()->identifierNetworkIDMap_.erase(oldID); 78 getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier; 79 } 80 81 /** 82 @brief Creates the class-hierarchy by creating and destroying one object of each type. 83 */ 84 void Factory::createClassHierarchy() 85 { 86 COUT(3) << "*** Factory -> Create class-hierarchy" << std::endl; 87 std::map<std::string, Identifier*>::iterator it; 88 it = getFactoryPointer()->identifierStringMap_.begin(); 89 (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy(); 90 for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it) 91 { 92 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 93 BaseObject* temp = (*it).second->fabricate(); 94 delete temp; 95 } 96 (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy(); 97 COUT(3) << "*** Factory -> Finished class-hierarchy creation" << std::endl; 98 } 99 100 /** 101 @brief Ensures the Factory gets created in the right moment. 102 @return The Factory. 103 */ 104 Factory* Factory::getFactoryPointer() 105 { 106 static Factory theOneAndOnlyFactoryInstance = Factory(); 107 return &theOneAndOnlyFactoryInstance; 22 108 } 23 109 } -
code/trunk/src/orxonox/core/Factory.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file Factory.h 30 @brief Definition of the Factory and the BaseFactory class. 31 32 The Factory is a singleton, containing two maps to map either the name or the network ID 33 of a class with the corresponding Identifier. 34 35 Usage: 36 ID(classname) or ID(networkID) returns the corresponding Identifier. 37 38 39 BaseObject is the parent of ClassFactory which is defined in ClassFactory.h. 40 It can't be defined in ClassFactory.h, because of circular dependencies. 41 */ 42 1 43 #ifndef _Factory_H__ 2 44 #define _Factory_H__ … … 5 47 #include <string> 6 48 49 #include "CorePrereqs.h" 50 7 51 namespace orxonox 8 52 { 9 class BaseObject; 10 class Identifier; 53 class BaseObject; // Forward declaration 11 54 12 55 // ############################### 13 56 // ### Factory ### 14 57 // ############################### 15 class Factory 58 //! The Factory is used to map the name or the network ID of a class with its Identifier. 59 class _CoreExport Factory 16 60 { 17 61 public: 18 62 static Identifier* getIdentifier(const std::string& name); 63 static Identifier* getIdentifier(const unsigned int id); 19 64 static void add(const std::string& name, Identifier* identifier); 65 static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID); 66 static void createClassHierarchy(); 67 68 static Factory* getFactoryPointer(); // avoid overriding order problem in the static intialisation process 20 69 21 70 private: 22 Factory() {} 23 Factory(const Factory& factory) {} 24 ~Factory() {} 71 Factory() {} // don't create 72 Factory(const Factory& factory) {} // don't copy 73 ~Factory() {} // don't delete 25 74 26 st atic Factory* pointer_s;27 std::map< std::string, Identifier*> identifierMap_;75 std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier 76 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier 28 77 }; 29 78 … … 31 80 // ### BaseFactory ### 32 81 // ############################### 33 class BaseFactory 82 //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies. 83 class _CoreExport BaseFactory 34 84 { 35 85 public: 36 86 virtual BaseObject* fabricate() = 0; 87 virtual ~BaseFactory() {}; 37 88 }; 38 89 } 39 90 40 #endif 91 #endif /* _Factory_H__ */ -
code/trunk/src/orxonox/core/Identifier.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file Identifier.cc 30 @brief Implementation of the Identifier class. 31 */ 32 1 33 #include "Identifier.h" 34 #include "Factory.h" 2 35 3 36 namespace orxonox … … 6 39 // ### Identifier ### 7 40 // ############################### 8 int Identifier::hierarchyCreatingCounter_s = 0; 41 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero (this static member variable is ok: it's used in main(), not before) 9 42 43 /** 44 @brief Constructor: No factory, no object created, new ObjectList and a unique networkID. 45 */ 10 46 Identifier::Identifier() 11 47 { … … 14 50 15 51 this->children_ = new IdentifierList; 52 53 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables 54 static unsigned int classIDcounter_s = 0; 55 this->classID_ = classIDcounter_s++; 16 56 } 17 57 58 /** 59 @brief Destructor: Deletes the IdentifierList containing the children. 60 */ 18 61 Identifier::~Identifier() 19 62 { 20 delete &this->name_;21 22 63 delete this->children_; 23 64 } 24 65 66 /** 67 @brief Initializes the Identifier with an IdentifierList containing all parents of the class the Identifier belongs to. 68 @param parents The IdentifierList containing all parents 69 */ 25 70 void Identifier::initialize(const IdentifierList* parents) 26 71 { 27 #if HIERARCHY_VERBOSE 28 std::cout << "*** Initialize " << this->name_ << "-Singleton.\n"; 29 #endif 72 COUT(4) << "*** Initialize " << this->name_ << "-Singleton." << std::endl; 30 73 this->bCreatedOneObject_ = true; 31 74 … … 36 79 { 37 80 this->parents_.add(temp1->identifier_); 38 temp1->identifier_->getChildren().add(this); 81 temp1->identifier_->getChildren().add(this); // We're a child of our parents 39 82 40 83 temp1 = temp1->next_; … … 43 86 } 44 87 88 /** 89 @brief Creates an object of the type the Identifier belongs to. 90 @return The new object 91 */ 45 92 BaseObject* Identifier::fabricate() 46 93 { 47 94 if (this->factory_) 48 95 { 49 return this->factory_->fabricate(); 96 return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type. 50 97 } 51 98 else 52 99 { 53 std::cout << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n"; 54 std::cout << "Aborting..."; 100 // Abstract classes don't have a factory and therefore can't create new objects 101 COUT(1) << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract." << std::endl; 102 COUT(1) << "Aborting..." << std::endl; 55 103 abort(); 104 return NULL; 56 105 } 57 106 } 58 107 108 /** 109 @brief Sets the network ID to a new value and changes the entry in the Factory. 110 @param id The new network ID 111 */ 112 void Identifier::setNetworkID(unsigned int id) 113 { 114 Factory::changeNetworkID(this, this->classID_, id); 115 this->classID_ = id; 116 } 117 118 /** 119 @returns a reference to the Identifier map, containing all Identifiers. 120 */ 121 std::map<std::string, Identifier*>& Identifier::getIdentifierMap() 122 { 123 static std::map<std::string, Identifier*> identifierMapStaticReference = std::map<std::string, Identifier*>(); 124 return identifierMapStaticReference; 125 } 126 127 /** 128 @returns true, if the Identifier is at least of the given type. 129 @param identifier The identifier to compare with 130 */ 59 131 bool Identifier::isA(const Identifier* identifier) const 60 132 { … … 62 134 } 63 135 136 /** 137 @returns true, if the Identifier is exactly of the given type. 138 @param identifier The identifier to compare with 139 */ 64 140 bool Identifier::isDirectlyA(const Identifier* identifier) const 65 141 { … … 67 143 } 68 144 145 /** 146 @returns true, if the assigned identifier is a child of the given identifier. 147 @param identifier The identifier to compare with 148 */ 69 149 bool Identifier::isChildOf(const Identifier* identifier) const 70 150 { … … 72 152 } 73 153 154 /** 155 @returns true, if the assigned identifier is a parent of the given identifier. 156 @param identifier The identifier to compare with 157 */ 74 158 bool Identifier::isParentOf(const Identifier* identifier) const 75 159 { -
code/trunk/src/orxonox/core/Identifier.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file Identifier.h 30 @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes. 31 32 The Identifier contains all needed informations about the class it belongs to: 33 - the name 34 - a list with all objects 35 - parents and childs 36 - the factory (if available) 37 - the networkID that can be synchronised with the server 38 - all configurable variables (if available) 39 40 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 41 isDirectlyA(...), isChildOf(...) and isParentOf(...). 42 43 To create the class-hierarchy, the Identifier has some intern functions and variables. 44 45 Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier. 46 47 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. 48 You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier. 49 */ 50 1 51 #ifndef _Identifier_H__ 2 52 #define _Identifier_H__ 3 53 4 #include <iostream> 5 54 #include <map> 55 #include <string> 56 #include <utility> 57 58 #include "CorePrereqs.h" 59 60 #include "ObjectList.h" 6 61 #include "IdentifierList.h" 7 #include "ObjectList.h" 8 #include "Factory.h" 9 10 #define HIERARCHY_VERBOSE false 11 62 #include "Debug.h" 63 #include "Iterator.h" 12 64 13 65 namespace orxonox 14 66 { 15 class BaseObject; 67 class BaseFactory; // Forward declaration 68 class BaseObject; // Forward declaration 16 69 17 70 // ############################### 18 71 // ### Identifier ### 19 72 // ############################### 20 class Identifier 73 //! The Identifier is used to identify the class of an object and to store informations about the class. 74 /** 75 The Identifier contains all needed informations about the class it belongs to: 76 - the name 77 - a list with all objects 78 - parents and childs 79 - the factory (if available) 80 - the networkID that can be synchronised with the server 81 - all configurable variables (if available) 82 83 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 84 isDirectlyA(...), isChildOf(...) and isParentOf(...). 85 86 You can't directly create an Identifier, it's just the base-class for ClassIdentifier. 87 */ 88 class _CoreExport Identifier 21 89 { 22 90 template <class T> 23 friend class ClassIdentifier; 91 friend class ClassIdentifier; // Forward declaration 24 92 25 93 template <class T> 26 friend class SubclassIdentifier; 27 28 template <class T> 29 friend class ClassFactory; 94 friend class SubclassIdentifier; // Forward declaration 95 96 friend class Factory; // Forward declaration 30 97 31 98 public: 99 /** @brief Sets the Factory. @param factory The factory to assign */ 32 100 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 101 33 102 BaseObject* fabricate(); 34 35 103 bool isA(const Identifier* identifier) const; 36 104 bool isDirectlyA(const Identifier* identifier) const; … … 38 106 bool isParentOf(const Identifier* identifier) const; 39 107 108 static std::map<std::string, Identifier*>& getIdentifierMap(); 109 110 /** @brief Removes all objects of the corresponding class. */ 111 virtual void removeObjects() const = 0; 112 113 /** @returns the name of the class the Identifier belongs to. */ 40 114 inline const std::string& getName() const { return this->name_; } 115 116 /** @returns the parents of the class the Identifier belongs to. */ 41 117 inline const IdentifierList& getParents() const { return this->parents_; } 118 119 /** @returns the children of the class the Identifier belongs to. */ 42 120 inline IdentifierList& getChildren() const { return *this->children_; } 43 121 122 /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */ 44 123 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 124 125 /** @returns the network ID to identify a class through the network. */ 126 inline const unsigned int getNetworkID() const { return this->classID_; } 127 128 /** @brief Sets the network ID to a new value. @param id The new value */ 129 void setNetworkID(unsigned int id); 130 131 /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */ 132 inline ConfigValueContainer* getConfigValueContainer(const std::string& varname) 133 { return this->configValues_[varname]; } 134 135 /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */ 136 inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 137 { this->configValues_[varname] = container; } 45 138 46 139 private: 47 140 Identifier(); 48 Identifier(const Identifier& identifier) {} 141 Identifier(const Identifier& identifier) {} // don't copy 49 142 virtual ~Identifier(); 50 143 void initialize(const IdentifierList* parents); 51 144 145 /** 146 @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 147 */ 52 148 inline static void startCreatingHierarchy() 53 149 { 54 150 hierarchyCreatingCounter_s++; 55 #if HIERARCHY_VERBOSE 56 std::cout << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n"; 57 #endif 58 } 59 151 COUT(4) << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl; 152 } 153 154 /** 155 @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 156 */ 60 157 inline static void stopCreatingHierarchy() 61 158 { 62 159 hierarchyCreatingCounter_s--; 63 #if HIERARCHY_VERBOSE 64 std::cout << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";65 #endif 66 }67 68 IdentifierList parents_; 69 IdentifierList* children_;70 71 std::string name_;72 73 BaseFactory* factory_;74 bool bCreatedOneObject_;75 st atic int hierarchyCreatingCounter_s;160 COUT(4) << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl; 161 } 162 163 IdentifierList parents_; //!< The Parents of the class the Identifier belongs to 164 IdentifierList* children_; //!< The Children of the class the Identifier belongs to 165 166 std::string name_; //!< The name of the class the Identifier belongs to 167 168 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 169 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 170 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 171 unsigned int classID_; //!< The network ID to identify a class through the network 172 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 76 173 }; 77 174 … … 80 177 // ### ClassIdentifier ### 81 178 // ############################### 179 //! The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 180 /** 181 ClassIdentifier is a Singleton, which means that only one object of a given type T exists. 182 This makes it possible to store informations about a class, sharing them with all 183 objects of that class without defining static variables in every class. 184 */ 82 185 template <class T> 83 186 class ClassIdentifier : public Identifier … … 85 188 public: 86 189 static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass); 190 static void addObject(T* object); 87 191 static ClassIdentifier<T>* getIdentifier(); 88 static void addObject(T* object); 192 void removeObjects() const; 193 void setName(const std::string& name); 89 194 90 195 private: 91 196 ClassIdentifier(); 92 ClassIdentifier(const ClassIdentifier<T>& identifier) {} 93 ~ClassIdentifier() ;94 95 static ClassIdentifier<T>* pointer_s;96 ObjectList<T>* objects_;197 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 198 ~ClassIdentifier() {} // don't delete 199 200 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 201 bool bSetName_; //!< True if the name is set 97 202 }; 98 203 99 template <class T>100 ClassIdentifier<T>* ClassIdentifier<T>::pointer_s = NULL;101 204 /** 205 @brief Constructor: Creates the ObjectList. 206 */ 102 207 template <class T> 103 208 ClassIdentifier<T>::ClassIdentifier() 104 209 { 105 this->objects_ = new ObjectList<T>; 106 } 107 108 template <class T> 109 ClassIdentifier<T>::~ClassIdentifier() 110 { 111 delete this->objects_; 112 this->pointer_s = NULL; 113 } 114 210 this->objects_ = ObjectList<T>::getList(); 211 this->bSetName_ = false; 212 } 213 214 /** 215 @brief Registers a class, which means that the name and the parents get stored. 216 @param parents An IdentifierList, containing the Identifiers of all parents of the class 217 @param name A string, containing exactly the name of the class 218 @param bRootClass True if the class is either an Interface or the BaseObject itself 219 @return The ClassIdentifier itself 220 */ 115 221 template <class T> 116 222 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass) 117 223 { 118 #if HIERARCHY_VERBOSE 119 std::cout << "*** Register Class in " << name << "-Singleton.\n"; 120 #endif 121 if (! pointer_s)224 COUT(4) << "*** Register Class in " << name << "-Singleton." << std::endl; 225 226 // Check if at least one object of the given type was created 227 if (!getIdentifier()->bCreatedOneObject_) 122 228 { 123 #if HIERARCHY_VERBOSE 124 std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n"; 125 #endif 126 pointer_s = new ClassIdentifier(); 229 // If no: We have to store the informations and initialize the Identifier 230 getIdentifier()->setName(name); 231 232 COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 233 if (bRootClass) 234 getIdentifier()->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case. 235 else 236 getIdentifier()->initialize(parents); 127 237 } 128 238 129 if (!pointer_s->bCreatedOneObject_) 239 return getIdentifier(); 240 } 241 242 /** 243 @brief Creates the only instance of this class for the template class T. 244 @return The Identifier itself 245 */ 246 template <class T> 247 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 248 { 249 static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>(); 250 static bool bIdentifierCreated = false; 251 252 if (!bIdentifierCreated) 130 253 { 131 #if HIERARCHY_VERBOSE 132 std::cout << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n"; 133 #endif 134 pointer_s->name_ = name; 135 Factory::add(name, pointer_s); 136 137 if (bRootClass) 138 pointer_s->initialize(NULL); 139 else 140 pointer_s->initialize(parents); 254 COUT(4) << "*** Create Identifier Singleton." << std::endl; 255 bIdentifierCreated = true; 141 256 } 142 257 143 return pointer_s; 144 } 145 146 template <class T> 147 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 148 { 149 if (!pointer_s) 258 return &theOneAndOnlyInstance; 259 } 260 261 /** 262 @brief Sets the name of the class. 263 @param name The name 264 */ 265 template <class T> 266 void ClassIdentifier<T>::setName(const std::string& name) 267 { 268 // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map 269 if (!this->bSetName_) 150 270 { 151 #if HIERARCHY_VERBOSE 152 std::cout << "*** Create Singleton.\n"; 153 #endif 154 pointer_s = new ClassIdentifier(); 271 this->name_ = name; 272 this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this)); 273 this->bSetName_ = true; 155 274 } 156 157 return pointer_s; 158 } 159 275 } 276 277 /** 278 @brief Adds an object of the given type to the ObjectList. 279 @param object The object to add 280 */ 160 281 template <class T> 161 282 void ClassIdentifier<T>::addObject(T* object) 162 283 { 163 #if HIERARCHY_VERBOSE 164 std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n"; 165 #endif 166 object->getMetaList()->add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object)); 167 } 168 284 COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl; 285 object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object)); 286 } 287 288 /** 289 @brief Removes all objects of the corresponding class. 290 */ 291 template <class T> 292 void ClassIdentifier<T>::removeObjects() const 293 { 294 for (Iterator<T> it = ObjectList<T>::start(); it;) 295 delete *(it++); 296 } 169 297 170 298 // ############################### 171 299 // ### SubclassIdentifier ### 172 300 // ############################### 173 template <class B> 301 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. 302 /** 303 You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>. 304 If you assign something else, the program aborts. 305 Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object. 306 */ 307 template <class T> 174 308 class SubclassIdentifier 175 309 { 176 310 public: 177 SubclassIdentifier(); 178 179 SubclassIdentifier<B>& operator=(Identifier* identifier) 180 { 181 if (!identifier->isA(ClassIdentifier<B>::getIdentifier())) 311 /** 312 @brief Constructor: Automaticaly assigns the Identifier of the given class. 313 */ 314 SubclassIdentifier() 315 { 316 this->identifier_ = ClassIdentifier<T>::getIdentifier(); 317 } 318 319 /** 320 @brief Overloading of the = operator: assigns the identifier and checks its type. 321 @param identifier The Identifier to assign 322 @return The SubclassIdentifier itself 323 */ 324 SubclassIdentifier<T>& operator=(Identifier* identifier) 325 { 326 if (!identifier->isA(ClassIdentifier<T>::getIdentifier())) 182 327 { 183 std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n";184 std::cout << "Error: SubclassIdentifier<" << ClassIdentifier<B>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";185 std::cout << "Aborting...\n";328 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 329 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 330 COUT(1) << "Aborting..." << std::endl; 186 331 abort(); 187 332 } … … 190 335 } 191 336 337 /** 338 @brief Overloading of the * operator: returns the assigned identifier. 339 @return The assigned identifier 340 */ 192 341 Identifier* operator*() 193 342 { … … 195 344 } 196 345 346 /** 347 @brief Overloading of the -> operator: returns the assigned identifier. 348 @return The assigned identifier 349 */ 197 350 Identifier* operator->() const 198 351 { … … 200 353 } 201 354 202 B* fabricate() 355 /** 356 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T. 357 @return The new object 358 */ 359 T* fabricate() 203 360 { 204 361 BaseObject* newObject = this->identifier_->fabricate(); 362 363 // Check if the creation was successful 205 364 if (newObject) 206 365 { 207 return dynamic_cast<B*>(newObject); 366 // Do a dynamic_cast, because an object of type T is much better than of type BaseObject 367 return (T*)(newObject); 208 368 } 209 369 else 210 370 { 371 // Something went terribly wrong 211 372 if (this->identifier_) 212 373 { 213 std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n";214 std::cout << "Error: Couldn't fabricate a new Object.\n";215 std::cout << "Aborting...\n";374 COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 375 COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl; 376 COUT(1) << "Aborting..." << std::endl; 216 377 } 217 378 else 218 379 { 219 std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";220 std::cout << "Aborting...\n";380 COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl; 381 COUT(1) << "Aborting..." << std::endl; 221 382 } 222 383 … … 225 386 } 226 387 388 /** @returns the assigned identifier. */ 227 389 inline const Identifier* getIdentifier() const 228 390 { return this->identifier_; } 391 392 /** @returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */ 229 393 inline bool isA(const Identifier* identifier) const 230 394 { return this->identifier_->isA(identifier); } 395 396 /** @returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */ 231 397 inline bool isDirectlyA(const Identifier* identifier) const 232 398 { return this->identifier_->isDirectlyA(identifier); } 399 400 /** @returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */ 233 401 inline bool isChildOf(const Identifier* identifier) const 234 402 { return this->identifier_->isChildOf(identifier); } 403 404 /** @returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */ 235 405 inline bool isParentOf(const Identifier* identifier) const 236 406 { return this->identifier_->isParentOf(identifier); } 237 407 238 408 private: 239 Identifier* identifier_; 409 Identifier* identifier_; //!< The assigned identifier 240 410 }; 241 242 template <class B>243 SubclassIdentifier<B>::SubclassIdentifier()244 {245 this->identifier_ = ClassIdentifier<B>::getIdentifier();246 }247 411 } 248 412 249 #endif 413 #endif /* _Identifier_H__ */ -
code/trunk/src/orxonox/core/IdentifierList.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file IdentifierList.cc 30 @brief Implementation of the IdentifierList class. 31 */ 32 33 #include "Identifier.h" 1 34 #include "IdentifierList.h" 2 #include "Identifier.h"3 35 4 36 namespace orxonox … … 7 39 // ### IdentifierList ### 8 40 // ############################### 41 /** 42 @brief Constructor: Sets first_ to zero. 43 */ 9 44 IdentifierList::IdentifierList() 10 45 { … … 12 47 } 13 48 49 /** 50 @brief Destructor: Deletes all elements in the list, but NOT THE IDENTIFIERS. 51 */ 14 52 IdentifierList::~IdentifierList() 15 53 { … … 23 61 } 24 62 63 /** 64 @brief Adds an Identifier to the list. 65 @param identifier The Identifier to add 66 */ 25 67 void IdentifierList::add(const Identifier* identifier) 26 68 { … … 30 72 } 31 73 74 /** 75 @brief Removes an Identifier from the list. 76 @param identifier The Identifier to remove 77 */ 32 78 void IdentifierList::remove(const Identifier* identifier) 33 79 { … … 35 81 return; 36 82 83 // Check if we have to delete the first element 37 84 if (this->first_->identifier_ == identifier) 38 85 { … … 44 91 } 45 92 93 // Iterate through the list 46 94 IdentifierListElement* temp = this->first_; 47 95 while (temp->next_) … … 60 108 } 61 109 110 /** 111 @brief Checks if a given Identifier is in the list and returns true if yes. 112 @param identifier The Identifier to check 113 @return True if the Identifier is in the list 114 */ 62 115 bool IdentifierList::isInList(const Identifier* identifier) const 63 116 { … … 74 127 } 75 128 129 /** 130 @returns a string, containing a list of the names of all Identifiers in the list. 131 */ 76 132 std::string IdentifierList::toString() const 77 133 { … … 94 150 // ### IdentifierListElement ### 95 151 // ############################### 152 /** 153 @brief Constructor: Creates the list-element with a given identifier. 154 @param identifier The Identifier to store 155 */ 96 156 IdentifierListElement::IdentifierListElement(const Identifier* identifier) 97 157 { … … 99 159 this->next_ = 0; 100 160 } 101 102 IdentifierListElement::~IdentifierListElement()103 {104 }105 161 } -
code/trunk/src/orxonox/core/IdentifierList.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file IdentifierList.h 30 @brief Definition of the IdentifierList class 31 32 The IdentifierList is a single-linked list, containing Identifiers. 33 The IdentifierList is used to store parents and childs of each Identifier. 34 */ 35 1 36 #ifndef _IdentifierList_H__ 2 37 #define _IdentifierList_H__ … … 4 39 #include <string> 5 40 41 #include "CorePrereqs.h" 42 6 43 namespace orxonox 7 44 { 8 class Identifier; 9 45 //! The list-element of the IdentifierList 10 46 class IdentifierListElement 11 47 { 12 48 public: 13 49 IdentifierListElement(const Identifier* identifier); 14 ~IdentifierListElement();15 50 16 const Identifier* identifier_; 17 IdentifierListElement* next_; 51 const Identifier* identifier_; //!< The identifier 52 IdentifierListElement* next_; //!< The next element in the list 18 53 }; 19 54 20 class IdentifierList 55 //! The IdentifierList contains Identifiers 56 class _CoreExport IdentifierList 21 57 { 22 58 public: … … 28 64 std::string toString() const; 29 65 30 IdentifierListElement* first_; 66 IdentifierListElement* first_; //!< The first element in the list 31 67 }; 32 68 } 33 69 34 #endif 70 #endif /* _IdentifierList_H__ */ -
code/trunk/src/orxonox/core/Iterator.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file Iterator.h 30 @brief Definition and implementation of the Iterator class. 31 32 The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type. 33 This is the only way to access the objects stored in an ObjectList. 34 35 Usage: 36 for (Iterator<class> it = ObjectList<class>::start(); it != 0; ++it) 37 { 38 it->someFunction(...); 39 class* myObject = *it; 40 } 41 42 Warning: Don't delete objects directly through the iterator. 43 */ 44 1 45 #ifndef _Iterator_H__ 2 46 #define _Iterator_H__ 3 47 48 #include "CorePrereqs.h" 49 50 #include "ObjectList.h" 51 #include "Debug.h" 52 4 53 namespace orxonox 5 54 { 55 //! The iterator allows to iterate through an ObjectList of a given class. 6 56 template <class T> 7 57 class Iterator 8 58 { 9 59 public: 60 /** 61 @brief Constructor: Sets the element, whereon the iterator points, to zero. 62 */ 10 63 Iterator() 11 64 { … … 13 66 } 14 67 68 /** 69 @brief Constructor: Sets the element, whereon the iterator points, to a given element. 70 @param element The element to start with 71 */ 15 72 Iterator(ObjectListElement<T>* element) 16 73 { … … 18 75 } 19 76 77 /** 78 @brief Overloading of the ++it operator: Iterator points to the next object in the list. 79 @return The Iterator itself 80 */ 20 81 Iterator<T> operator++() 21 82 { … … 24 85 } 25 86 87 /** 88 @brief Overloading of the it++ operator: Iterator points to the next object in the list. 89 @return The Iterator itself 90 */ 91 Iterator<T> operator++(int i) 92 { 93 Iterator<T> copy = *this; 94 this->element_ = this->element_->next_; 95 return copy; 96 } 97 98 /** 99 @brief Overloading of the --it operator: Iterator points to the previous object in the list. 100 @return The Iterator itself 101 */ 26 102 Iterator<T> operator--() 27 103 { … … 30 106 } 31 107 108 /** 109 @brief Overloading of the it-- operator: Iterator points to the previous object in the list. 110 @return The Iterator itself 111 */ 112 Iterator<T> operator--(int i) 113 { 114 Iterator<T> copy = *this; 115 this->element_ = this->element_->prev_; 116 return copy; 117 } 118 119 /** 120 @brief Overloading of the *it operator: returns the pointer to the object. 121 @return The object the Iterator points at 122 */ 32 123 T* operator*() 33 124 { … … 35 126 } 36 127 128 /** 129 @brief Overloading of the it-> operator: returns the pointer to the object. 130 @return The object the Iterator points at 131 */ 37 132 T* operator->() const 38 133 { … … 41 136 } 42 137 138 /** 139 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object. 140 @return True if the iterator points to an existing object. 141 */ 43 142 operator bool() 44 143 { … … 46 145 } 47 146 147 /** 148 @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool. 149 @param compare The integer (must be zero, everything else makes no sense). 150 @return True if the iterator points to an existing object. 151 */ 48 152 bool operator!=(int compare) 49 153 { 154 // Comparing with anything except zero makes no sense 50 155 if (compare != 0) 51 std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n";156 COUT(2) << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works." << std::endl; 52 157 53 158 return (this->element_ != 0); … … 55 160 56 161 private: 57 ObjectListElement<T>* element_; 162 ObjectListElement<T>* element_; //!< The element the Iterator points at 58 163 }; 59 164 } 60 165 61 #endif 166 #endif /* _Iterator_H__ */ -
code/trunk/src/orxonox/core/MetaObjectList.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file MetaObjectList.cc 30 @brief Implementation of the MetaObjectList class. 31 */ 32 1 33 #include "MetaObjectList.h" 2 34 3 35 namespace orxonox 4 36 { 37 /** 38 @brief Constructor: Sets first_ to zero. 39 */ 5 40 MetaObjectList::MetaObjectList() 6 41 { … … 8 43 } 9 44 45 /** 46 @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList. 47 */ 10 48 MetaObjectList::~MetaObjectList() 11 49 { -
code/trunk/src/orxonox/core/MetaObjectList.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file MetaObjectList.h 30 @brief Definition of the MetaObjectList class. 31 32 The MetaObjectList is a single-linked list, containing all list-elements and their 33 lists wherein the object, owning the MetaObjectList, is registered. 34 This allows much faster deletion of objects because no iteration is needed. 35 */ 36 1 37 #ifndef _MetaObjectList_H__ 2 38 #define _MetaObjectList_H__ 3 39 40 #include "CorePrereqs.h" 41 4 42 #include "ObjectList.h" 5 43 #include "Identifier.h" 44 #include "Debug.h" 6 45 7 46 namespace orxonox 8 47 { 48 //! Base-class of MetaObjectListElement, because those is a template 9 49 class BaseMetaObjectListElement 10 50 { 11 51 public: 52 /** @brief Default destructor */ 12 53 virtual ~BaseMetaObjectListElement() {}; 13 54 14 BaseMetaObjectListElement* next_; 55 BaseMetaObjectListElement* next_; //!< The next Element in the list 15 56 }; 16 57 … … 18 59 // ### MetaObjectListElement ### 19 60 // ############################### 61 //! The list-element of the MetaObjectList 20 62 template <class T> 21 63 class MetaObjectListElement : public BaseMetaObjectListElement … … 23 65 public: 24 66 MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element); 25 ~MetaObjectListElement();67 virtual ~MetaObjectListElement(); 26 68 27 ObjectListElement<T>* element_; 28 ObjectList<T>* list_; 69 ObjectListElement<T>* element_; //!< The list element, containing the object 70 ObjectList<T>* list_; //!< The list, containing the element 29 71 }; 30 72 73 /** 74 @brief Constructor: Creates the list-element with given list and element. 75 */ 31 76 template <class T> 32 77 MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element) … … 37 82 } 38 83 84 /** 85 @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement. 86 */ 39 87 template <class T> 40 88 MetaObjectListElement<T>::~MetaObjectListElement() … … 43 91 this->element_->next_->prev_ = this->element_->prev_; 44 92 else 45 this->list_->last_ = this->element_->prev_; 93 this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list 46 94 47 95 if (this->element_->prev_) 48 96 this->element_->prev_->next_ = this->element_->next_; 49 97 else 50 this->list_->first_ = this->element_->next_; 98 this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 51 99 52 100 53 #if HIERARCHY_VERBOSE 54 std::cout << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n"; 55 #endif 101 COUT(4) << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl; 56 102 delete this->element_; 57 103 } … … 61 107 // ### ObjectList ### 62 108 // ############################### 109 //! The MetaObjectList contains ObjectListElements and their ObjectLists. 110 /** 111 The MetaObjectList is a single-linked list, containing all list-elements and their 112 lists wherein the object that owns the MetaObjectList is registered. 113 This allows much faster deletion of objects because no iteration is needed. 114 */ 63 115 class MetaObjectList 64 116 { … … 69 121 void add(ObjectList<T>* list, ObjectListElement<T>* element); 70 122 71 BaseMetaObjectListElement* first_; 123 BaseMetaObjectListElement* first_; //!< The first element in the list 72 124 }; 73 125 126 /** 127 @brief Adds an ObjectList and an element of that list to the MetaObjectList. 128 @param list The ObjectList wherein the element is 129 @param element The element wherein the object is 130 */ 74 131 template <class T> 75 132 void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element) … … 81 138 } 82 139 83 #endif 140 #endif /* _MetaObjectList_H__ */ -
code/trunk/src/orxonox/core/ObjectList.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file ObjectList.h 30 @brief Definition and implementation of the ObjectList class. 31 32 The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class. 33 Newly created objects are added through the RegisterObject-macro in its constructor. 34 Use Iterator<class> to iterate through all objects of the class. 35 */ 36 1 37 #ifndef _ObjectList_H__ 2 38 #define _ObjectList_H__ 3 39 40 #include "CorePrereqs.h" 41 #include "Iterator.h" 42 4 43 namespace orxonox 5 44 { 6 class OrxonoxClass;7 8 45 // ############################### 9 46 // ### ObjectListElement ### 10 47 // ############################### 48 //! The list-element of the ObjectList 11 49 template <class T> 12 50 class ObjectListElement … … 14 52 public: 15 53 ObjectListElement(T* object); 16 ~ObjectListElement(); 17 18 T* object_; 19 ObjectListElement* next_; 20 ObjectListElement* prev_; 54 55 T* object_; //!< The object 56 ObjectListElement* next_; //!< The next element in the list 57 ObjectListElement* prev_; //!< The previous element in the list 21 58 }; 22 59 60 /** 61 @brief Constructor: Creates the list-element with an object. 62 @param object The object to store 63 */ 23 64 template <class T> 24 65 ObjectListElement<T>::ObjectListElement(T* object) … … 29 70 } 30 71 31 template <class T>32 ObjectListElement<T>::~ObjectListElement()33 {34 }35 36 72 37 73 // ############################### 38 74 // ### ObjectList ### 39 75 // ############################### 40 template <class T> 41 class Iterator; 42 76 //! The ObjectList contains all objects of a given class. 77 /** 78 The ObjectList is used by Identifiers to store all objects of a given class. 79 Use Iterator<class> to iterate through all objects in the list. 80 */ 43 81 template <class T> 44 82 class ObjectList 45 83 { 46 84 public: 85 static ObjectList<T>* getList(); 86 87 ObjectListElement<T>* add(T* object); 88 // void remove(OrxonoxClass* object, bool bIterateForwards = true); 89 90 /** @returns the first element in the list */ 91 inline static Iterator<T> start() 92 { return Iterator<T>(getList()->first_); } 93 94 /** @returns the first element in the list */ 95 inline static Iterator<T> begin() 96 { return Iterator<T>(getList()->first_); } 97 98 /** @returns the last element in the list */ 99 inline static Iterator<T> end() 100 { return Iterator<T>(getList()->last_); } 101 102 ObjectListElement<T>* first_; //!< The first element in the list 103 ObjectListElement<T>* last_; //!< The last element in the list 104 105 private: 47 106 ObjectList(); 48 107 ~ObjectList(); 49 ObjectListElement<T>* add(T* object);50 void remove(OrxonoxClass* object, bool bIterateForwards = true);51 52 inline static Iterator<T> start()53 { return Iterator<T>(pointer_s->first_); }54 inline static Iterator<T> end()55 { return Iterator<T>(pointer_s->last_); }56 57 ObjectListElement<T>* first_;58 ObjectListElement<T>* last_;59 60 private:61 static ObjectList<T>* pointer_s;62 108 }; 63 109 64 template <class T>65 ObjectList<T>* ObjectList<T>::pointer_s = 0;66 110 /** 111 @brief Constructor: Sets default values. 112 */ 67 113 template <class T> 68 114 ObjectList<T>::ObjectList() … … 70 116 this->first_ = 0; 71 117 this->last_ = 0; 72 73 this->pointer_s = this; 74 } 75 118 } 119 120 /** 121 @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS. 122 */ 76 123 template <class T> 77 124 ObjectList<T>::~ObjectList() … … 86 133 } 87 134 135 /** 136 @returns a pointer to the only existing instance for the given class T. 137 */ 138 template <class T> 139 ObjectList<T>* ObjectList<T>::getList() 140 { 141 static ObjectList<T> theOnlyObjectListObjectForClassT = ObjectList<T>(); 142 return &theOnlyObjectListObjectForClassT; 143 } 144 145 /** 146 @brief Adds a new object to the end of the list. 147 @param object The object to add 148 @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object 149 */ 88 150 template <class T> 89 151 ObjectListElement<T>* ObjectList<T>::add(T* object) … … 91 153 if (!this->last_) 92 154 { 155 // If the list is empty 93 156 this->last_ = new ObjectListElement<T>(object); 94 this->first_ = this->last_; 157 this->first_ = this->last_; // There's only one object in the list now 95 158 } 96 159 else 97 160 { 161 // If the list isn't empty 98 162 ObjectListElement<T>* temp = this->last_; 99 163 this->last_ = new ObjectListElement<T>(object); … … 105 169 } 106 170 171 172 // /** 173 // @brief Removes an object from the list. 174 // @param object The object to remove 175 // @param bIterateForwards If true: Start searching the object at the beginning of the list 176 // */ 177 /* 107 178 template <class T> 108 179 void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards) … … 111 182 return; 112 183 184 // If there's only one object in the list, we have to set first_ and last_ to zero 113 185 if (this->first_ == this->last_) 114 186 { … … 123 195 } 124 196 197 // Now we are sure we have more than one element in the list 125 198 if (bIterateForwards) 126 199 { 200 // Start at the beginning of the list 201 202 // Check if it's the first object 127 203 if (this->first_->object_ == object) 128 204 { … … 135 211 } 136 212 213 // Iterate through the whole list 137 214 ObjectListElement<T>* temp = this->first_; 138 215 while (temp->next_) … … 146 223 temp2->prev_ = temp; 147 224 else 148 this->last_ = temp; 225 this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer. 149 226 150 227 return; … … 156 233 else 157 234 { 235 // Start at the end of the list 236 237 // Check if it's the last object 158 238 if (this->last_->object_ == object) 159 239 { … … 166 246 } 167 247 248 // Iterate through the whole list 168 249 ObjectListElement<T>* temp = this->last_; 169 250 while (temp->prev_) … … 177 258 temp2->next_ = temp; 178 259 else 179 this->first_ = temp; 260 this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer. 180 261 181 262 return; … … 186 267 } 187 268 } 269 */ 188 270 } 189 271 190 #endif 272 #endif /* _ObjectList_H__ */ -
code/trunk/src/orxonox/core/OrxonoxClass.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file OrxonoxClass.cc 30 @brief Implementation of the OrxonoxClass Class. 31 */ 32 1 33 #include "OrxonoxClass.h" 2 34 3 35 namespace orxonox 4 36 { 37 /** @brief Constructor: Sets the default values. */ 5 38 OrxonoxClass::OrxonoxClass() 6 39 { 40 this->setConfigValues(); 41 7 42 this->identifier_ = 0; 8 43 this->parents_ = 0; 9 44 10 this->metaList_ = new MetaObjectList; 45 this->bActive_ = true; 46 this->bVisible_ = true; 11 47 } 12 48 49 /** @brief Destructor: Deletes, if existing, the list of the parents. */ 13 50 OrxonoxClass::~OrxonoxClass() 14 51 { 52 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 15 53 if (this->parents_) 16 54 delete this->parents_; 17 18 delete this->metaList_;19 55 } 20 56 } -
code/trunk/src/orxonox/core/OrxonoxClass.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 28 /*! 29 @file OrxonoxClass.h 30 @brief Definition of the OrxonoxClass Class. 31 32 All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass. 33 It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy. 34 */ 35 1 36 #ifndef _OrxonoxClass_H__ 2 37 #define _OrxonoxClass_H__ 3 38 4 #include "Identifier.h"5 #include "IdentifierList.h" 6 #include " ObjectList.h"39 #include <string> 40 41 #include "CorePrereqs.h" 7 42 #include "MetaObjectList.h" 43 #include "Iterator.h" 8 44 9 45 namespace orxonox 10 46 { 11 class OrxonoxClass 47 //! The class all objects and interfaces of the game-logic (not the engine) are derived from. 48 /** 49 The BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. 50 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 51 */ 52 class _CoreExport OrxonoxClass 12 53 { 13 54 public: 14 55 OrxonoxClass(); 15 56 virtual ~OrxonoxClass(); 57 58 /** @brief Function to collect the SetConfigValue-macro calls. */ 59 void setConfigValues() {}; 60 61 /** @returns the Identifier of the object */ 16 62 inline Identifier* getIdentifier() const { return this->identifier_; } 63 64 /** @brief Sets the Identifier of the object. Used by the RegisterObject-macro. */ 17 65 inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; } 66 67 /** @returns the list of all parents of the object */ 18 68 inline IdentifierList* getParents() const { return this->parents_; } 69 70 /** @brief Sets the Parents of the object. Used by the RegisterObject-macro. */ 19 71 inline void setParents(IdentifierList* parents) { this->parents_ = parents; } 20 inline MetaObjectList* getMetaList() { return this->metaList_; } 72 73 /** @returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. */ 74 inline MetaObjectList& getMetaList() { return this->metaList_; } 75 76 77 /** @returns true if the objects class is of the given type or a derivative. */ 78 inline bool isA(const Identifier* identifier) 79 { return this->getIdentifier()->isA(identifier); } 80 /** @returns true if the objects class is exactly of the given type. */ 81 inline bool isDirectlyA(const Identifier* identifier) 82 { return this->getIdentifier()->isDirectlyA(identifier); } 83 /** @returns true if the objects class is a child of the given type. */ 84 inline bool isChildOf(const Identifier* identifier) 85 { return this->getIdentifier()->isChildOf(identifier); } 86 /** @returns true if the objects class is a parent of the given type. */ 87 inline bool isParentOf(const Identifier* identifier) 88 { return this->getIdentifier()->isParentOf(identifier); } 89 90 91 /** @returns true if the objects class is of the given type or a derivative. */ 92 inline bool isA(const SubclassIdentifier<class B>* identifier) 93 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 94 /** @returns true if the objects class is exactly of the given type. */ 95 inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier) 96 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); } 97 /** @returns true if the objects class is a child of the given type. */ 98 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 99 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 100 /** @returns true if the objects class is a parent of the given type. */ 101 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 102 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 103 104 105 /** @returns true if the objects class is of the given type or a derivative. */ 106 inline bool isA(const SubclassIdentifier<class B> identifier) 107 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 108 /** @returns true if the objects class is exactly of the given type. */ 109 inline bool isDirectlyA(const SubclassIdentifier<class B> identifier) 110 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); } 111 /** @returns true if the objects class is a child of the given type. */ 112 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 113 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 114 /** @returns true if the objects class is a parent of the given type. */ 115 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 116 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 117 118 119 /** @returns true if the objects class is of the given type or a derivative. */ 120 inline bool isA(const OrxonoxClass* object) 121 { return this->getIdentifier()->isA(object->getIdentifier()); } 122 /** @returns true if the objects class is exactly of the given type. */ 123 inline bool isDirectlyA(const OrxonoxClass* object) 124 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); } 125 /** @returns true if the objects class is a child of the given type. */ 126 inline bool isChildOf(const OrxonoxClass* object) 127 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 128 /** @returns true if the objects class is a parent of the given type. */ 129 inline bool isParentOf(const OrxonoxClass* object) 130 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 131 132 133 /** @brief Sets the name of the object. @param name The name */ 134 inline virtual void setName(const std::string& name) { this->name_ = name; } 135 136 /** @returns the name of the object. */ 137 inline const std::string& getName() const { return this->name_; } 138 139 /** @brief Sets the state of the objects activity. @param bActive True = active */ 140 inline virtual void setActive(bool bActive) { this->bActive_ = bActive; } 141 142 /** @returns the state of the objects activity. */ 143 inline const bool isActive() const { return this->bActive_; } 144 145 /** @brief Sets the state of the objects visibility. @param bVisible True = visible */ 146 inline virtual void setVisible(bool bVisible) { this->bVisible_ = bVisible; } 147 148 /** @returns the state of the objects visibility. */ 149 inline const bool isVisible() const { return this->bVisible_; } 21 150 22 151 private: 23 Identifier* identifier_; 24 IdentifierList* parents_; 25 MetaObjectList* metaList_; 152 Identifier* identifier_; //!< The Identifier of the object 153 IdentifierList* parents_; //!< List of all parents of the object 154 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 155 156 std::string name_; //!< The name of the object 157 bool bActive_; //!< True = the object is active 158 bool bVisible_; //!< True = the object is visible 26 159 }; 160 template class _CoreExport orxonox::ClassIdentifier<OrxonoxClass>; 161 template class _CoreExport orxonox::ObjectList<OrxonoxClass>; 27 162 } 28 163 29 #endif 164 #endif /* _OrxonoxClass_H__ */ -
code/trunk/src/orxonox/objects/Test.h
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #ifndef _Test_H__ 2 29 #define _Test_H__ 3 30 4 #include " BaseObject.h"5 #include "../core/ IdentifierIncludes.h"31 #include "core/BaseObject.h" 32 #include "../core/CoreIncludes.h" 6 33 7 34 namespace orxonox -
code/trunk/src/orxonox/objects/test1.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "test1.h" 2 29 #include "test2.h" 3 30 #include "test3.h" 31 #include "util/tinyxml/tinyxml.h" 32 #include "../Orxonox.h" 33 #include <OgreSceneManager.h> 4 34 5 35 namespace orxonox … … 18 48 Test1::~Test1() 19 49 { 50 } 51 52 void Test1::tick(float dt) 53 { 54 std::cout << "Test1: " << this << std::endl; 20 55 } 21 56 … … 37 72 void Test1::setUsefullClass1(Identifier* identifier) 38 73 { 39 std::cout << "\n";40 std::cout << "Test1: usefullClass1->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";41 std::cout << "Test1: usefullClass1->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";42 std::cout << "Test1: usefullClass1->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";74 std::cout << std::endl; 75 std::cout << "Test1: usefullClass1->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 76 std::cout << "Test1: usefullClass1->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 77 std::cout << "Test1: usefullClass1->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 43 78 this->usefullClass1_ = identifier; 44 79 } … … 46 81 void Test1::setUsefullClass2(Identifier* identifier) 47 82 { 48 std::cout << "\n";49 std::cout << "Test1: usefullClass2->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";50 std::cout << "Test1: usefullClass2->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";51 std::cout << "Test1: usefullClass2->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";83 std::cout << std::endl; 84 std::cout << "Test1: usefullClass2->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 85 std::cout << "Test1: usefullClass2->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 86 std::cout << "Test1: usefullClass2->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 52 87 this->usefullClass2_ = identifier; 53 88 } … … 55 90 void Test1::setUsefullClassOfTypeTest3(Identifier* identifier) 56 91 { 57 std::cout << "\n";58 std::cout << "Test1: usefullClass3->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";59 std::cout << "Test1: usefullClass3->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";60 std::cout << "Test1: usefullClass3->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";92 std::cout << std::endl; 93 std::cout << "Test1: usefullClass3->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 94 std::cout << "Test1: usefullClass3->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 95 std::cout << "Test1: usefullClass3->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 61 96 this->usefullClass3_ = identifier; 62 97 } 98 99 void Test1::loadParams(TiXmlElement* xmlElem) 100 { 101 102 103 104 } 63 105 } -
code/trunk/src/orxonox/objects/test1.h
r258 r790 2 2 #define _Test1_H__ 3 3 4 #include "BaseObject.h" 4 #include "core/BaseObject.h" 5 #include "Tickable.h" 5 6 #include "test3.h" 7 #include "util/tinyxml/tinyxml.h" 6 8 7 9 namespace orxonox 8 10 { 9 class Test1 : public BaseObject 11 class Test1 : public BaseObject, public Tickable 10 12 { 11 13 public: 12 14 Test1(); 13 15 virtual ~Test1(); 16 17 virtual void tick(float dt); 14 18 15 19 bool usefullClass1isA(Identifier* identifier); … … 19 23 void setUsefullClass2(Identifier* identifier); 20 24 void setUsefullClassOfTypeTest3(Identifier* identifier); 25 26 void loadParams(TiXmlElement* xmlElem); 21 27 22 28 private: -
code/trunk/src/orxonox/objects/test2.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "test1.h" 2 29 #include "test2.h" … … 14 41 this->usefullClass2_ = Class(Test2); 15 42 this->usefullClass3_ = Class(Test3); 43 44 timer1.setTimer(1, true, this, &Test2::timerFunction1); 45 timer2.setTimer(5, true, this, &Test2::timerFunction2); 46 timer3.setTimer(10, false, this, &Test2::timerFunction3); 16 47 } 17 48 18 49 Test2::~Test2() 19 50 { 51 } 52 53 void Test2::timerFunction1() 54 { 55 std::cout << "Test2: 1 Sekunde" << std::endl; 56 } 57 58 void Test2::timerFunction2() 59 { 60 std::cout << "Test2: 5 Sekunden" << std::endl; 61 } 62 63 void Test2::timerFunction3() 64 { 65 std::cout << "Test2: 10 Sekunden sind um!" << std::endl; 20 66 } 21 67 … … 37 83 void Test2::setUsefullClass1(Identifier* identifier) 38 84 { 39 std::cout << "\n";40 std::cout << "Test2: usefullClass1->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";41 std::cout << "Test2: usefullClass1->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";42 std::cout << "Test2: usefullClass1->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";85 std::cout << std::endl; 86 std::cout << "Test2: usefullClass1->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 87 std::cout << "Test2: usefullClass1->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 88 std::cout << "Test2: usefullClass1->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 43 89 this->usefullClass1_ = identifier; 44 90 } … … 46 92 void Test2::setUsefullClass2(Identifier* identifier) 47 93 { 48 std::cout << "\n";49 std::cout << "Test2: usefullClass2->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";50 std::cout << "Test2: usefullClass2->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";51 std::cout << "Test2: usefullClass2->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";94 std::cout << std::endl; 95 std::cout << "Test2: usefullClass2->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 96 std::cout << "Test2: usefullClass2->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 97 std::cout << "Test2: usefullClass2->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 52 98 this->usefullClass2_ = identifier; 53 99 } … … 55 101 void Test2::setUsefullClassOfTypeTest3(Identifier* identifier) 56 102 { 57 std::cout << "\n";58 std::cout << "Test2: usefullClass3->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << "\n";59 std::cout << "Test2: usefullClass3->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << "\n";60 std::cout << "Test2: usefullClass3->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << "\n";103 std::cout << std::endl; 104 std::cout << "Test2: usefullClass3->isA(Class(Test1)): " << identifier->isA(Class(Test1)) << std::endl; 105 std::cout << "Test2: usefullClass3->isA(Class(Test2)): " << identifier->isA(Class(Test2)) << std::endl; 106 std::cout << "Test2: usefullClass3->isA(Class(Test3)): " << identifier->isA(Class(Test3)) << std::endl; 61 107 this->usefullClass3_ = identifier; 62 108 } -
code/trunk/src/orxonox/objects/test2.h
r258 r790 2 2 #define _Test2_H__ 3 3 4 #include "BaseObject.h" 4 #include "core/BaseObject.h" 5 #include "../tools/Timer.h" 5 6 6 7 namespace orxonox … … 21 22 void setUsefullClassOfTypeTest3(Identifier* identifier); 22 23 24 void timerFunction1(); 25 void timerFunction2(); 26 void timerFunction3(); 27 23 28 private: 24 29 Identifier* usefullClass1_; … … 26 31 SubclassIdentifier<Test3> usefullClass3_; 27 32 33 Timer<Test2> timer1; 34 Timer<Test2> timer2; 35 Timer<Test2> timer3; 28 36 }; 29 37 } -
code/trunk/src/orxonox/objects/test3.cc
r258 r790 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Fabian 'x3n' Landau 23 * Co-authors: 24 * ... 25 * 26 */ 27 1 28 #include "test1.h" 2 29 #include "test2.h" … … 10 37 { 11 38 RegisterObject(Test3); 39 40 this->setConfigValues(); 41 } 42 43 void Test3::setConfigValues() 44 { 45 SetConfigValue(value_int_, 1); 46 SetConfigValue(value_uint_, 1); 47 SetConfigValue(value_char_, 1); 48 SetConfigValue(value_uchar_, 1); 49 SetConfigValue(value_float_, 1); 50 SetConfigValue(value_double_, 1); 51 SetConfigValue(value_bool_, 1); 52 SetConfigValue(value_string_, "This is a test"); 53 SetConfigValue(value_constchar_, "This is another test"); 54 SetConfigValue(value_vector2_, Vector2(101, 202)); 55 SetConfigValue(value_vector3_, Vector3(13, 26, 39)); 56 SetConfigValue(value_colourvalue_, ColourValue(1.0, 0.5, 0.25, 0.887)); 12 57 } 13 58 … … 15 60 { 16 61 } 17 #define testandcout(code) \18 std::cout << #code << " " << code << "\n"19 62 20 bool Test3::usefullClassesIsATest(Test1* test1)63 void Test3::configOutput() 21 64 { 22 std::cout << "\n"; 23 std::cout << "Test1:\n"; 65 std::cout << this->value_int_ << std::endl; 66 std::cout << this->value_uint_ << std::endl; 67 std::cout << (int)this->value_char_ << std::endl; 68 std::cout << (int)this->value_uchar_ << std::endl; 69 std::cout << this->value_float_ << std::endl; 70 std::cout << this->value_double_ << std::endl; 71 std::cout << this->value_bool_ << std::endl; 72 std::cout << this->value_string_ << std::endl; 73 std::cout << this->value_constchar_ << std::endl; 74 std::cout << this->value_vector2_ << std::endl; 75 std::cout << this->value_vector3_ << std::endl; 76 std::cout << this->value_colourvalue_ << std::endl; 77 } 78 79 #define testandcout(code) \ 80 std::cout << #code << " " << code << std::endl 81 82 void Test3::usefullClassesIsATest(Test1* test1) 83 { 84 std::cout << std::endl; 85 std::cout << "Test1:" << std::endl; 24 86 testandcout(test1->usefullClass1isA(Class(Test1))); 25 87 testandcout(test1->usefullClass1isA(Class(Test2))); 26 88 testandcout(test1->usefullClass1isA(Class(Test3))); 27 std::cout << "\n";89 std::cout << std::endl; 28 90 testandcout(test1->usefullClass2isA(Class(Test1))); 29 91 testandcout(test1->usefullClass2isA(Class(Test2))); 30 92 testandcout(test1->usefullClass2isA(Class(Test3))); 31 std::cout << "\n";93 std::cout << std::endl; 32 94 testandcout(test1->usefullClass3isA(Class(Test1))); 33 95 testandcout(test1->usefullClass3isA(Class(Test2))); … … 35 97 } 36 98 37 boolTest3::usefullClassesIsATest(Test2* test2)99 void Test3::usefullClassesIsATest(Test2* test2) 38 100 { 39 std::cout << "\n";40 std::cout << "Test2: \n";101 std::cout << std::endl; 102 std::cout << "Test2:" << std::endl; 41 103 testandcout(test2->usefullClass1isA(Class(Test1))); 42 104 testandcout(test2->usefullClass1isA(Class(Test2))); 43 105 testandcout(test2->usefullClass1isA(Class(Test3))); 44 std::cout << "\n";106 std::cout << std::endl; 45 107 testandcout(test2->usefullClass2isA(Class(Test1))); 46 108 testandcout(test2->usefullClass2isA(Class(Test2))); 47 109 testandcout(test2->usefullClass2isA(Class(Test3))); 48 std::cout << "\n";110 std::cout << std::endl; 49 111 testandcout(test2->usefullClass3isA(Class(Test1))); 50 112 testandcout(test2->usefullClass3isA(Class(Test2))); -
code/trunk/src/orxonox/objects/test3.h
r258 r790 2 2 #define _Test3_H__ 3 3 4 #include " BaseObject.h"4 #include "core/BaseObject.h" 5 5 6 6 namespace orxonox … … 15 15 virtual ~Test3(); 16 16 17 bool usefullClassesIsATest(Test1* test1); 18 bool usefullClassesIsATest(Test2* test2); 17 void setConfigValues(); 18 19 void usefullClassesIsATest(Test1* test1); 20 void usefullClassesIsATest(Test2* test2); 21 22 void configOutput(); 23 24 private: 25 int value_int_; 26 unsigned int value_uint_; 27 char value_char_; 28 unsigned char value_uchar_; 29 float value_float_; 30 double value_double_; 31 bool value_bool_; 32 std::string value_string_; 33 const char* value_constchar_; 34 Vector2 value_vector2_; 35 Vector3 value_vector3_; 36 ColourValue value_colourvalue_; 19 37 }; 20 38 }
Note: See TracChangeset
for help on using the changeset viewer.