Changeset 5611 for code/branches/resource2/src/core
- Timestamp:
- Aug 5, 2009, 5:20:06 PM (15 years ago)
- Location:
- code/branches/resource2/src/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/src/core/ClassFactory.h
r5610 r5611 54 54 class ClassFactory : public BaseFactory 55 55 { 56 friend class Factory;57 58 56 public: 59 57 static bool create(const std::string& name, bool bLoadable = true); … … 61 59 62 60 private: 63 ClassFactory( bool bLoadable) : bLoadable_(bLoadable) {}64 ClassFactory(const ClassFactory& factory) ;// Don't copy61 ClassFactory() {} // Don't create 62 ClassFactory(const ClassFactory& factory) {} // Don't copy 65 63 virtual ~ClassFactory() {} // Don't delete 66 64 67 Identifier* createIdentifier(const std::string& name); 68 69 bool bLoadable_; 65 static T* createNewObject(BaseObject* creator); 70 66 }; 71 67 … … 80 76 { 81 77 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl; 82 Factory::add(name, new ClassFactory<T>(bLoadable)); 78 ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>); 79 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable); 80 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 83 81 84 82 return true; … … 92 90 inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator) 93 91 { 94 return new T(creator);92 return ClassFactory<T>::createNewObject(creator); 95 93 } 96 94 97 95 /** 96 @brief Creates and returns a new object of class T; this is a wrapper for the new operator. 97 @return The new object 98 98 */ 99 99 template <class T> 100 inline Identifier* ClassFactory<T>::createIdentifier(const std::string& name)100 inline T* ClassFactory<T>::createNewObject(BaseObject* creator) 101 101 { 102 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 103 identifier->addFactory(this); 104 identifier->setLoadable(this->bLoadable_); 105 return identifier; 102 return new T(creator); 106 103 } 107 104 } -
code/branches/resource2/src/core/Factory.cc
r5610 r5611 73 73 @param identifier The identifier to add 74 74 */ 75 void Factory::add(const std::string& name, BaseFactory* factory)75 void Factory::add(const std::string& name, Identifier* identifier) 76 76 { 77 getFactoryPointer()->factoryMap_[name] = factory; 77 getFactoryPointer()->identifierStringMap_[name] = identifier; 78 getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; 78 79 } 79 80 … … 104 105 { 105 106 COUT(3) << "*** Factory: Create class-hierarchy" << std::endl; 106 std::map<std::string, BaseFactory*>::iterator it;107 it = getFactoryPointer()-> factoryMap_.begin();108 Identifier::startCreatingHierarchy();109 for (it = getFactoryPointer()-> factoryMap_.begin(); it != getFactoryPointer()->factoryMap_.end(); ++it)107 std::map<std::string, Identifier*>::iterator it; 108 it = getFactoryPointer()->identifierStringMap_.begin(); 109 (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy(); 110 for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it) 110 111 { 111 // Create the corresponding identifier first112 Identifier* identifier = it->second->createIdentifier(it->first);113 getFactoryPointer()->identifierStringMap_[it->first] = identifier;114 getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;115 112 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 116 BaseObject* temp = identifier->fabricate(0);113 BaseObject* temp = (*it).second->fabricate(0); 117 114 delete temp; 118 115 } 119 Identifier::stopCreatingHierarchy();116 (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy(); 120 117 COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl; 121 118 } -
code/branches/resource2/src/core/Factory.h
r5610 r5611 61 61 static Identifier* getIdentifier(const std::string& name); 62 62 static Identifier* getIdentifier(const uint32_t id); 63 static void add(const std::string& name, BaseFactory* factory);63 static void add(const std::string& name, Identifier* identifier); 64 64 static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID); 65 65 static void cleanNetworkIDs(); … … 69 69 70 70 /** @brief Returns the factory-map. */ 71 static const std::map<std::string, Identifier*>& getFac toryMap()71 static const std::map<std::string, Identifier*>& getFacbtoryMap() 72 72 { return Factory::getFactoryPointer()->identifierStringMap_; } 73 73 /** @brief Returns the begin-iterator of the factory-map. */ … … 85 85 std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier 86 86 std::map<uint32_t, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier 87 std::map<std::string, BaseFactory*> factoryMap_;88 87 }; 89 88 … … 96 95 public: 97 96 virtual BaseObject* fabricate(BaseObject* creator) = 0; 98 virtual Identifier* createIdentifier(const std::string& name) = 0;99 97 virtual ~BaseFactory() {}; 100 98 };
Note: See TracChangeset
for help on using the changeset viewer.