[Orxonox-commit 4975] r9644 - in code/branches/core6/src/libraries/core: . class
landauf at orxonox.net
landauf at orxonox.net
Sun Aug 11 22:42:57 CEST 2013
Author: landauf
Date: 2013-08-11 22:42:57 +0200 (Sun, 11 Aug 2013)
New Revision: 9644
Modified:
code/branches/core6/src/libraries/core/CoreIncludes.h
code/branches/core6/src/libraries/core/class/Identifier.h
code/branches/core6/src/libraries/core/class/IdentifierManager.cc
code/branches/core6/src/libraries/core/class/IdentifierManager.h
Log:
small refactoring
Modified: code/branches/core6/src/libraries/core/CoreIncludes.h
===================================================================
--- code/branches/core6/src/libraries/core/CoreIncludes.h 2013-08-11 20:38:29 UTC (rev 9643)
+++ code/branches/core6/src/libraries/core/CoreIncludes.h 2013-08-11 20:42:57 UTC (rev 9644)
@@ -94,7 +94,7 @@
@param bRootClass True if the class is directly derived from orxonox::OrxonoxClass
*/
#define InternRegisterObject(ClassName, bRootClass) \
- if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
+ if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this, #ClassName, bRootClass)) \
return; \
else \
((void)0)
Modified: code/branches/core6/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifier.h 2013-08-11 20:38:29 UTC (rev 9643)
+++ code/branches/core6/src/libraries/core/class/Identifier.h 2013-08-11 20:42:57 UTC (rev 9644)
@@ -114,6 +114,9 @@
inline const std::string& getName() const { return this->name_; }
void setName(const std::string& name);
+ /// Returns the name of the class as it is returned by typeid(T).name()
+ virtual const std::string& getTypeidName() = 0;
+
/// Returns the network ID to identify a class through the network.
inline uint32_t getNetworkID() const { return this->networkID_; }
void setNetworkID(uint32_t id);
@@ -271,7 +274,7 @@
static ClassIdentifier<T>* getIdentifier();
static ClassIdentifier<T>* getIdentifier(const std::string& name);
- bool initialiseObject(T* object, const std::string& className, bool bRootClass);
+ bool initializeObject(T* object, const std::string& className, bool bRootClass);
void setConfigValues(T* object, Configurable*) const;
void setConfigValues(T* object, Identifiable*) const;
@@ -279,13 +282,18 @@
void addObjectToList(T* object, Listable*);
void addObjectToList(T* object, Identifiable*);
- void updateConfigValues(bool updateChildren = true) const;
+ virtual void updateConfigValues(bool updateChildren = true) const;
+ virtual const std::string& getTypeidName()
+ { return this->typeidName_; }
+
private:
- static void initialiseIdentifier();
+ static void initializeIdentifier();
+
ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy
ClassIdentifier()
{
+ this->typeidName_ = typeid(T).name();
SuperFunctionInitialization<0, T>::initialize(this);
}
~ClassIdentifier()
@@ -298,6 +306,7 @@
void updateConfigValues(bool updateChildren, Listable*) const;
void updateConfigValues(bool updateChildren, Identifiable*) const;
+ std::string typeidName_;
static ClassIdentifier<T>* classIdentifier_s;
};
@@ -313,7 +322,7 @@
{
// check if the Identifier already exists
if (!ClassIdentifier<T>::classIdentifier_s)
- ClassIdentifier<T>::initialiseIdentifier();
+ ClassIdentifier<T>::initializeIdentifier();
return ClassIdentifier<T>::classIdentifier_s;
}
@@ -335,24 +344,20 @@
@brief Assigns the static field for the identifier singleton.
*/
template <class T>
- void ClassIdentifier<T>::initialiseIdentifier()
+ /*static */ void ClassIdentifier<T>::initializeIdentifier()
{
- // Get the name of the class
- std::string name = typeid(T).name();
-
- // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
+ // create a new identifier anyway. Will be deleted if not used.
ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
// Get the entry from the map
- ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getIdentifierSingleton(name, proposal);
+ ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getIdentifierSingleton(proposal);
if (ClassIdentifier<T>::classIdentifier_s == proposal)
- {
- orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl;
- }
+ orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;
else
{
- orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl;
+ orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;
+ delete proposal; // delete proposal (it is not used anymore)
}
}
@@ -363,7 +368,7 @@
@param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass)
*/
template <class T>
- bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
+ bool ClassIdentifier<T>::initializeObject(T* object, const std::string& className, bool bRootClass)
{
if (bRootClass)
orxout(verbose, context::object_list) << "Register Root-Object: " << className << endl;
Modified: code/branches/core6/src/libraries/core/class/IdentifierManager.cc
===================================================================
--- code/branches/core6/src/libraries/core/class/IdentifierManager.cc 2013-08-11 20:38:29 UTC (rev 9643)
+++ code/branches/core6/src/libraries/core/class/IdentifierManager.cc 2013-08-11 20:42:57 UTC (rev 9644)
@@ -56,24 +56,23 @@
/**
@brief Returns an identifier by name and adds it if not available
- @param name The name of the identifier as typeid().name() suggests
@param proposal A pointer to a newly created identifier for the case of non existence in the map
@return The identifier (unique instance)
*/
- Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
+ Identifier* IdentifierManager::getIdentifierSingleton(Identifier* proposal)
{
- std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.find(name);
+ const std::string& typeidName = proposal->getTypeidName();
+ std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName);
- if (it != this->identifierByTypeId_.end())
+ if (it != this->identifierByTypeidName_.end())
{
- // There is already an entry: return it and delete the proposal
- delete proposal;
+ // There is already an entry: return it
return it->second;
}
else
{
// There is no entry: put the proposal into the map and return it
- this->identifierByTypeId_[name] = proposal;
+ this->identifierByTypeidName_[typeidName] = proposal;
return proposal;
}
}
@@ -95,7 +94,7 @@
{
orxout(internal_status) << "Create class-hierarchy" << endl;
this->startCreatingHierarchy();
- for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
+ for (std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)
{
// To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
if (it->second->hasFactory())
@@ -113,10 +112,10 @@
*/
void IdentifierManager::destroyAllIdentifiers()
{
- for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeId_.begin(); it != this->identifierByTypeId_.end(); ++it)
+ for (std::map<std::string, Identifier*>::iterator it = this->identifierByTypeidName_.begin(); it != this->identifierByTypeidName_.end(); ++it)
delete (it->second);
- this->identifierByTypeId_.clear();
+ this->identifierByTypeidName_.clear();
this->identifierByString_.clear();
this->identifierByLowercaseString_.clear();
this->identifierByNetworkId_.clear();
Modified: code/branches/core6/src/libraries/core/class/IdentifierManager.h
===================================================================
--- code/branches/core6/src/libraries/core/class/IdentifierManager.h 2013-08-11 20:38:29 UTC (rev 9643)
+++ code/branches/core6/src/libraries/core/class/IdentifierManager.h 2013-08-11 20:42:57 UTC (rev 9644)
@@ -46,7 +46,7 @@
public:
static IdentifierManager& getInstance();
- Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
+ Identifier* getIdentifierSingleton(Identifier* proposal);
void registerIdentifier(Identifier* identifier);
unsigned int getUniqueClassId()
@@ -95,7 +95,7 @@
inline void stopCreatingHierarchy()
{ hierarchyCreatingCounter_s--; }
- std::map<std::string, Identifier*> identifierByTypeId_; //!< Map with the names as received by typeid(). This is only used internally.
+ std::map<std::string, Identifier*> identifierByTypeidName_; //!< Map with the names as received by typeid(). This is only used internally.
std::map<std::string, Identifier*> identifierByString_; //!< Map that stores all Identifiers with their names.
std::map<std::string, Identifier*> identifierByLowercaseString_; //!< Map that stores all Identifiers with their names in lowercase.
More information about the Orxonox-commit
mailing list