[Orxonox-commit 888] r5611 - code/branches/resource2/src/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Aug 5 17:20:06 CEST 2009
Author: rgrieder
Date: 2009-08-05 17:20:06 +0200 (Wed, 05 Aug 2009)
New Revision: 5611
Modified:
code/branches/resource2/src/core/ClassFactory.h
code/branches/resource2/src/core/Factory.cc
code/branches/resource2/src/core/Factory.h
Log:
Stupid TSVN bug: All items in a commit list are always checked by default (which is exactly wrong). It was fixed again in the upcoming 1.6.4 version though.
Modified: code/branches/resource2/src/core/ClassFactory.h
===================================================================
--- code/branches/resource2/src/core/ClassFactory.h 2009-08-05 15:15:35 UTC (rev 5610)
+++ code/branches/resource2/src/core/ClassFactory.h 2009-08-05 15:20:06 UTC (rev 5611)
@@ -53,20 +53,16 @@
template <class T>
class ClassFactory : public BaseFactory
{
- friend class Factory;
-
public:
static bool create(const std::string& name, bool bLoadable = true);
BaseObject* fabricate(BaseObject* creator);
private:
- ClassFactory(bool bLoadable) : bLoadable_(bLoadable) {}
- ClassFactory(const ClassFactory& factory); // Don't copy
+ ClassFactory() {} // Don't create
+ ClassFactory(const ClassFactory& factory) {} // Don't copy
virtual ~ClassFactory() {} // Don't delete
- Identifier* createIdentifier(const std::string& name);
-
- bool bLoadable_;
+ static T* createNewObject(BaseObject* creator);
};
/**
@@ -79,7 +75,9 @@
bool ClassFactory<T>::create(const std::string& name, bool bLoadable)
{
COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
- Factory::add(name, new ClassFactory<T>(bLoadable));
+ ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
+ ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
+ Factory::add(name, ClassIdentifier<T>::getIdentifier());
return true;
}
@@ -91,18 +89,17 @@
template <class T>
inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
{
- return new T(creator);
+ return ClassFactory<T>::createNewObject(creator);
}
/**
+ @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
+ @return The new object
*/
template <class T>
- inline Identifier* ClassFactory<T>::createIdentifier(const std::string& name)
+ inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
{
- Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
- identifier->addFactory(this);
- identifier->setLoadable(this->bLoadable_);
- return identifier;
+ return new T(creator);
}
}
Modified: code/branches/resource2/src/core/Factory.cc
===================================================================
--- code/branches/resource2/src/core/Factory.cc 2009-08-05 15:15:35 UTC (rev 5610)
+++ code/branches/resource2/src/core/Factory.cc 2009-08-05 15:20:06 UTC (rev 5611)
@@ -72,9 +72,10 @@
@param name The name of the identifier
@param identifier The identifier to add
*/
- void Factory::add(const std::string& name, BaseFactory* factory)
+ void Factory::add(const std::string& name, Identifier* identifier)
{
- getFactoryPointer()->factoryMap_[name] = factory;
+ getFactoryPointer()->identifierStringMap_[name] = identifier;
+ getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
}
/**
@@ -103,20 +104,16 @@
void Factory::createClassHierarchy()
{
COUT(3) << "*** Factory: Create class-hierarchy" << std::endl;
- std::map<std::string, BaseFactory*>::iterator it;
- it = getFactoryPointer()->factoryMap_.begin();
- Identifier::startCreatingHierarchy();
- for (it = getFactoryPointer()->factoryMap_.begin(); it != getFactoryPointer()->factoryMap_.end(); ++it)
+ std::map<std::string, Identifier*>::iterator it;
+ it = getFactoryPointer()->identifierStringMap_.begin();
+ (*getFactoryPointer()->identifierStringMap_.begin()).second->startCreatingHierarchy();
+ for (it = getFactoryPointer()->identifierStringMap_.begin(); it != getFactoryPointer()->identifierStringMap_.end(); ++it)
{
- // Create the corresponding identifier first
- Identifier* identifier = it->second->createIdentifier(it->first);
- getFactoryPointer()->identifierStringMap_[it->first] = identifier;
- getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
// To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
- BaseObject* temp = identifier->fabricate(0);
+ BaseObject* temp = (*it).second->fabricate(0);
delete temp;
}
- Identifier::stopCreatingHierarchy();
+ (*getFactoryPointer()->identifierStringMap_.begin()).second->stopCreatingHierarchy();
COUT(3) << "*** Factory: Finished class-hierarchy creation" << std::endl;
}
Modified: code/branches/resource2/src/core/Factory.h
===================================================================
--- code/branches/resource2/src/core/Factory.h 2009-08-05 15:15:35 UTC (rev 5610)
+++ code/branches/resource2/src/core/Factory.h 2009-08-05 15:20:06 UTC (rev 5611)
@@ -60,7 +60,7 @@
public:
static Identifier* getIdentifier(const std::string& name);
static Identifier* getIdentifier(const uint32_t id);
- static void add(const std::string& name, BaseFactory* factory);
+ static void add(const std::string& name, Identifier* identifier);
static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
static void cleanNetworkIDs();
static void createClassHierarchy();
@@ -68,7 +68,7 @@
static Factory* getFactoryPointer(); // avoid overriding order problem in the static intialisation process
/** @brief Returns the factory-map. */
- static const std::map<std::string, Identifier*>& getFactoryMap()
+ static const std::map<std::string, Identifier*>& getFacbtoryMap()
{ return Factory::getFactoryPointer()->identifierStringMap_; }
/** @brief Returns the begin-iterator of the factory-map. */
static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
@@ -84,7 +84,6 @@
std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier
std::map<uint32_t, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier
- std::map<std::string, BaseFactory*> factoryMap_;
};
// ###############################
@@ -95,7 +94,6 @@
{
public:
virtual BaseObject* fabricate(BaseObject* creator) = 0;
- virtual Identifier* createIdentifier(const std::string& name) = 0;
virtual ~BaseFactory() {};
};
}
More information about the Orxonox-commit
mailing list