[Orxonox-commit 692] r3224 - in branches/core4/src: core network
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Jun 23 20:14:46 CEST 2009
Author: rgrieder
Date: 2009-06-23 20:14:46 +0200 (Tue, 23 Jun 2009)
New Revision: 3224
Modified:
branches/core4/src/core/CoreIncludes.h
branches/core4/src/core/Identifier.h
branches/core4/src/core/OrxonoxClass.h
branches/core4/src/network/NetworkFunction.h
Log:
Removed three macros: Two (ClassByString and ClassByID) by replacing them with an equivalent inline function and the other one by moving some macro-code to an actual function. Most of what RegisterObject() does can simply be done within a template function in the ClassIdentifier.
Also removed some mysterious public functions of OrxonoxClass (WorldEntity::getParents() doesn't exactly do what you would expect) that only served internal purposes. Instead the ClassIdentifier became a friend of OrxonoxClass and now does the necessary work.
Modified: branches/core4/src/core/CoreIncludes.h
===================================================================
--- branches/core4/src/core/CoreIncludes.h 2009-06-23 17:28:48 UTC (rev 3223)
+++ branches/core4/src/core/CoreIncludes.h 2009-06-23 18:14:46 UTC (rev 3224)
@@ -55,34 +55,16 @@
@param bRootClass True if the class is directly derived from OrxonoxClass
*/
#define InternRegisterObject(ClassName, bRootClass) \
- this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)); \
- if (orxonox::Identifier::isCreatingHierarchy()) \
- { \
- if (this->getParents()) \
- { \
- orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeClassHierarchy(this->getParents(), bRootClass); \
- this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
- } \
- this->setConfigValues(); \
+ if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
return; \
- } \
- orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this)
+ else \
+ ((void)0)
/**
- @brief Intern macro, containing the specific part of RegisterRootObject.
- @param ClassName The name of the class
-*/
-#define InternRegisterRootObject(ClassName) \
- if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \
- this->createParents(); \
- InternRegisterObject(ClassName, true)
-
-/**
@brief RegisterObject - with and without debug output.
@param ClassName The name of the class
*/
#define RegisterObject(ClassName) \
- COUT(5) << "*** Register Object: " << #ClassName << std::endl; \
InternRegisterObject(ClassName, false)
/**
@@ -90,8 +72,7 @@
@param ClassName The name of the class
*/
#define RegisterRootObject(ClassName) \
- COUT(5) << "*** Register Root-Object: " << #ClassName << std::endl; \
- InternRegisterRootObject(ClassName)
+ InternRegisterObject(ClassName, true)
/**
@brief Creates the entry in the Factory.
@@ -114,18 +95,26 @@
#define Class(ClassName) \
orxonox::ClassIdentifier<ClassName>::getIdentifier()
-/**
- @brief Returns the Identifier with a given name through the factory.
- @param String The name of the class
-*/
-#define ClassByString(String) \
- orxonox::Factory::getIdentifier(String)
-/**
- @brief Returns the Identifier with a given network ID through the factory.
- @param networkID The network ID of the class
-*/
-#define ClassByID(networkID) \
- orxonox::Factory::getIdentifier(networkID)
+namespace orxonox
+{
+ /**
+ @brief Returns the Identifier with a given name through the factory.
+ @param String The name of the class
+ */
+ inline Identifier* ClassByString(const std::string& name)
+ {
+ return Factory::getIdentifier(name);
+ }
+ /**
+ @brief Returns the Identifier with a given network ID through the factory.
+ @param networkID The network ID of the class
+ */
+ inline Identifier* ClassByID(uint32_t id)
+ {
+ return Factory::getIdentifier(id);
+ }
+}
+
#endif /* _CoreIncludes_H__ */
Modified: branches/core4/src/core/Identifier.h
===================================================================
--- branches/core4/src/core/Identifier.h 2009-06-23 17:28:48 UTC (rev 3223)
+++ branches/core4/src/core/Identifier.h 2009-06-23 18:14:46 UTC (rev 3224)
@@ -348,8 +348,9 @@
public:
static ClassIdentifier<T> *getIdentifier();
static ClassIdentifier<T> *getIdentifier(const std::string& name);
- void addObject(T* object);
+ bool initialiseObject(T* object, const std::string& className, bool bRootClass);
+
void updateConfigValues(bool updateChildren = true) const;
private:
@@ -427,12 +428,37 @@
@param object The object to add
*/
template <class T>
- inline void ClassIdentifier<T>::addObject(T* object)
+ bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
{
- COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
- object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
- // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
- object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
+ if (bRootClass)
+ COUT(5) << "*** Register Root-Object: " << className << std::endl;
+ else
+ COUT(5) << "*** Register Object: " << className << std::endl;
+
+ object->identifier_ = this;
+ if (Identifier::isCreatingHierarchy())
+ {
+ if (bRootClass && !object->parents_)
+ object->parents_ = new std::set<const Identifier*>();
+
+ if (object->parents_)
+ {
+ this->initializeClassHierarchy(object->parents_, bRootClass);
+ object->parents_->insert(object->parents_->end(), this);
+ }
+
+ object->setConfigValues();
+ return true;
+ }
+ else
+ {
+ COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
+ object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
+
+ // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
+ object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
+ return false;
+ }
}
/**
Modified: branches/core4/src/core/OrxonoxClass.h
===================================================================
--- branches/core4/src/core/OrxonoxClass.h 2009-06-23 17:28:48 UTC (rev 3223)
+++ branches/core4/src/core/OrxonoxClass.h 2009-06-23 18:14:46 UTC (rev 3224)
@@ -62,19 +62,6 @@
/** @brief Returns the Identifier of the object. @return The Identifier */
inline Identifier* getIdentifier() const { return this->identifier_; }
- /** @brief Sets the Identifier of the object. Used by the RegisterObject-macro. */
- inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; }
-
- /** @brief Returns the list of all parents of the object. @return The list */
- inline std::set<const Identifier*>* getParents() const { return this->parents_; }
-
- /** @brief Creates the parents-list. */
- inline void createParents() { this->parents_ = new std::set<const Identifier*>(); }
-
- /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
- inline MetaObjectList& getMetaList() { return (*this->metaList_); }
-
-
bool isA(const Identifier* identifier);
bool isExactlyA(const Identifier* identifier);
bool isChildOf(const Identifier* identifier);
Modified: branches/core4/src/network/NetworkFunction.h
===================================================================
--- branches/core4/src/network/NetworkFunction.h 2009-06-23 17:28:48 UTC (rev 3223)
+++ branches/core4/src/network/NetworkFunction.h 2009-06-23 18:14:46 UTC (rev 3224)
@@ -37,8 +37,8 @@
#include <string>
#include <boost/preprocessor/cat.hpp>
-#include "core/OrxonoxClass.h"
#include "core/Functor.h"
+#include "core/Identifier.h"
#include "FunctionCallManager.h"
#include "synchronisable/Synchronisable.h"
More information about the Orxonox-commit
mailing list