Changeset 9762 in orxonox.OLD for branches/new_class_id/src
- Timestamp:
- Sep 19, 2006, 5:00:10 PM (18 years ago)
- Location:
- branches/new_class_id/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/lang/class_id.h
r9757 r9762 47 47 /** @param name the id to compare @returns false on match (match is same Name) @brief compares an ID with a ClassName */ 48 48 bool operator!=(const std::string& name) const { return *_name != name; }; 49 /** @param classID: the Id to compare @returns true if this id is smaller than the classID's ID */ 50 bool operator<(const ClassID& classID) const { return *this->_id < *classID._id; }; 49 51 50 52 private: -
branches/new_class_id/src/lib/sound/ogg_player.h
r9715 r9762 13 13 #include <ogg/ogg.h> 14 14 #include <vorbis/vorbisfile.h> 15 #include " threading.h"15 #include "util/threading.h" 16 16 17 17 struct File; -
branches/new_class_id/src/lib/util/loading/factory.cc
r9725 r9762 35 35 this->setName(classID.name()); 36 36 37 if( Factory::_factoryList == NULL) 38 Factory::_factoryList = new std::list<Factory*>; 39 40 Factory::_factoryList->push_back(this); 37 Factory::_factoryIDMap[classID] = this; 38 Factory::_factoryStringMap[classID.name()] = this; 41 39 } 42 40 43 /** @brief a reference to the First Factory */ 44 std::list<Factory*>* Factory::_factoryList = NULL; 41 /** @brief A Map of all Factories ordered by ID. */ 42 Factory::FactoryIDMap Factory::_factoryIDMap; 43 44 /** @brief A Map of all Factories ordered by Name. */ 45 Factory::FactoryStringMap Factory::_factoryStringMap; 45 46 46 47 /** … … 49 50 Factory::~Factory () 50 51 { 51 // printf("%s\n", this->factoryName); 52 // Factory* tmpDel = this->next; 53 // this->next = NULL; 54 } 52 FactoryIDMap::iterator it = Factory::_factoryIDMap.find(this->_classID); 53 if (it != Factory::_factoryIDMap.end() && (*it).second == this) 54 Factory::_factoryIDMap.erase(it); 55 55 56 /** 57 * @brief deletes all the Factories. (cleanup) 58 */ 59 void Factory::deleteFactories() 60 { 61 if (Factory::_factoryList != NULL) 62 { 63 while(!Factory::_factoryList->empty()) 64 { 65 delete Factory::_factoryList->front(); 66 Factory::_factoryList->pop_front(); 67 } 68 delete Factory::_factoryList; 69 Factory::_factoryList = NULL; 70 } 56 FactoryStringMap::iterator stringIt = Factory::_factoryStringMap.find(this->_classID.name()); 57 if (stringIt != Factory::_factoryStringMap.end() && (*stringIt).second == this) 58 Factory::_factoryStringMap.erase(stringIt); 71 59 } 72 60 … … 99 87 BaseObject* Factory::fabricate(const TiXmlElement* root) 100 88 { 101 assert (Factory::_factoryList != NULL); 102 103 std::list<Factory*>::const_iterator factory; 104 for (factory = Factory::_factoryList->begin(); factory != Factory::_factoryList->end(); factory++) 105 if (*(*factory) == root->Value()) 106 { 107 PRINTF(2)("Create a new Object of type %s\n", (*factory)->getCName()); 108 return (*factory)->fabricateObject(root); 109 } 110 111 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value()); 112 return NULL; 89 FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(root->Value()); 90 if (it != Factory::_factoryStringMap.end()) 91 { 92 PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName()); 93 return (*it).second->fabricateObject(root); 94 } 95 else 96 { 97 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value()); 98 return NULL; 99 } 113 100 } 114 101 … … 121 108 BaseObject* Factory::fabricate(const std::string& className) 122 109 { 123 if (Factory::_factoryList == NULL) 110 FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(className); 111 if (it != Factory::_factoryStringMap.end()) 112 { 113 PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName()); 114 return (*it).second->fabricateObject(NULL); 115 } 116 else 117 { 118 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str()); 124 119 return NULL; 125 126 std::list<Factory*>::const_iterator factory; 127 for (factory = Factory::_factoryList->begin(); factory != Factory::_factoryList->end(); factory++) 128 if (*(*factory) == className) 129 { 130 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName()); 131 return (*factory)->fabricateObject(NULL); 132 } 133 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str()); 134 return NULL; 120 } 135 121 } 136 122 … … 142 128 BaseObject* Factory::fabricate(const ClassID& classID) 143 129 { 144 if (Factory::_factoryList == NULL) 130 FactoryIDMap::const_iterator it = Factory::_factoryIDMap.find(classID); 131 if (it != Factory::_factoryIDMap.end()) 132 { 133 PRINTF(4)("Create a new Object of type %s\n", (*it).second->getCName()); 134 return (*it).second->fabricateObject(NULL); 135 } 136 else 137 { 138 PRINTF(2)("Could not Fabricate an Object of ClassID '%d'\n", classID.id()); 145 139 return NULL; 140 } 141 } 146 142 147 std::list<Factory*>::const_iterator factory;148 for (factory = Factory::_factoryList->begin(); factory != Factory::_factoryList->end(); factory++)149 if (*(*factory) == classID)150 {151 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());152 return (*factory)->fabricateObject(NULL);153 143 154 } 155 PRINTF(2)("Could not Fabricate an Object of ClassID '%d'\n", classID.id()); 156 return NULL; 144 /** 145 * @brief print out some nice litte debug information about the Factory. 146 */ 147 void Factory::debug() const 148 { 149 PRINTF(0)("Factory of class '%s' with ClassID: %d\n", this->_classID.name().c_str(), this->_classID.id()); 157 150 } 151 152 /** 153 * @brief Prints out some nice Debug information about all factories 154 */ 155 void Factory::debugAll() 156 { 157 PRINTF(0)("Debugging all %d Factories\n", Factory::_factoryStringMap.size()); 158 Factory::FactoryStringMap::const_iterator it; 159 for (it = Factory::_factoryStringMap.begin(); it != Factory::_factoryStringMap.end(); ++it) 160 (*it).second->debug(); 161 } -
branches/new_class_id/src/lib/util/loading/factory.h
r9757 r9762 27 27 #include "parser/tinyxml/tinyxml.h" 28 28 #include "base_object.h" 29 #include < list>29 #include <map> 30 30 31 31 /** … … 34 34 */ 35 35 #define CREATE_FACTORY(CLASS_NAME) \ 36 tFactory<CLASS_NAME> * global_##CLASS_NAME##_Factory = newtFactory<CLASS_NAME>(CLASS_NAME::staticClassID())36 tFactory<CLASS_NAME> global_##CLASS_NAME##_Factory = tFactory<CLASS_NAME>(CLASS_NAME::staticClassID()) 37 37 38 38 //! The Factory is a loadable object handler 39 39 class Factory : public BaseObject 40 40 { 41 //! Declare the ObjectList at the BaseObject List 41 42 ObjectListDeclaration(Factory); 42 43 public: 43 44 virtual ~Factory (); 44 45 static void deleteFactories();46 45 47 46 static BaseObject* fabricate(const std::string& className); … … 49 48 static BaseObject* fabricate(const TiXmlElement* root); 50 49 51 52 50 bool operator==(int classID) const; 53 51 bool operator==(const std::string& className) const; 52 /** @param classID the ID to compare @returns true if the ID's match */ 54 53 bool operator==(const ClassID& classID) const { return _classID == classID; }; 54 55 56 void debug() const; 57 static void debugAll(); 55 58 56 59 protected: 57 60 Factory (const ClassID& id); 61 /** 62 * @brief The core function of the Factory. Creates objects of the Factories Type. 63 * @param root The TiXmlElement of the Factory. 64 * @returns the created Object in BaseType* format. 65 */ 58 66 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 59 67 60 68 private: 69 //! Copy Constructor is hidden. 61 70 Factory (const Factory&) {}; 62 71 63 72 protected: 64 const ClassID _classID; //!< The Class-Identifyer of the Factory. 65 static std::list<Factory*>* _factoryList; //!< List of Registered Factories 73 /** The Type of the FactoryMap that is sorted by ID */ 74 typedef std::map<const ClassID, Factory*> FactoryIDMap; 75 /** The Type of the FactoryMap that is sorted by Name */ 76 typedef std::map<std::string, Factory*> FactoryStringMap; 77 78 const ClassID _classID; //!< The Class-Identifyer of the Factory. 79 static FactoryIDMap _factoryIDMap; //!< List of Registered Factories 80 static FactoryStringMap _factoryStringMap; //!< List of Registered Factories 66 81 }; 67 82 … … 75 90 /** 76 91 * @brief creates a new type Factory to enable the loading of T 77 * @param factoryName the Name of the Factory to load.78 92 * @param classID the ID of the Class to be created. 79 93 */ … … 81 95 : Factory(classID) 82 96 { } 97 /** 98 * @brief copy constructor 99 * @param factory the Factory to copy 100 */ 101 tFactory (const tFactory& factory) : Factory(factory._classID) {}; 83 102 84 private:85 tFactory (const tFactory&) {};86 103 /** 87 104 * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) -
branches/new_class_id/src/orxonox.cc
r9715 r9762 45 45 #include "event_handler.h" 46 46 47 #include "util/loading/factory.h"48 47 #include "loading/fast_factory.h" 49 48 … … 127 126 128 127 // class-less services/factories 129 Factory::deleteFactories();130 128 FastFactory::deleteAll(); 131 129 OrxShell::ShellCommandClass::unregisterAllCommands();
Note: See TracChangeset
for help on using the changeset viewer.