Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3224


Ignore:
Timestamp:
Jun 23, 2009, 8:14:46 PM (15 years ago)
Author:
rgrieder
Message:

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.

Location:
code/branches/core4/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/CoreIncludes.h

    r3196 r3224  
    5656*/
    5757#define InternRegisterObject(ClassName, bRootClass) \
    58     this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)); \
    59     if (orxonox::Identifier::isCreatingHierarchy()) \
    60     { \
    61         if (this->getParents()) \
    62         { \
    63             orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeClassHierarchy(this->getParents(), bRootClass); \
    64             this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
    65         } \
    66         this->setConfigValues(); \
     58    if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
    6759        return; \
    68     } \
    69     orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this)
    70 
    71 /**
    72     @brief Intern macro, containing the specific part of RegisterRootObject.
    73     @param ClassName The name of the class
    74 */
    75 #define InternRegisterRootObject(ClassName) \
    76     if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \
    77         this->createParents(); \
    78     InternRegisterObject(ClassName, true)
     60    else \
     61        ((void)0)
    7962
    8063/**
     
    8366*/
    8467#define RegisterObject(ClassName) \
    85     COUT(5) << "*** Register Object: " << #ClassName << std::endl; \
    8668    InternRegisterObject(ClassName, false)
    8769
     
    9173*/
    9274#define RegisterRootObject(ClassName) \
    93     COUT(5) << "*** Register Root-Object: " << #ClassName << std::endl; \
    94     InternRegisterRootObject(ClassName)
     75    InternRegisterObject(ClassName, true)
    9576
    9677/**
     
    11596    orxonox::ClassIdentifier<ClassName>::getIdentifier()
    11697
    117 /**
    118     @brief Returns the Identifier with a given name through the factory.
    119     @param String The name of the class
    120 */
    121 #define ClassByString(String) \
    122     orxonox::Factory::getIdentifier(String)
    12398
    124 /**
    125     @brief Returns the Identifier with a given network ID through the factory.
    126     @param networkID The network ID of the class
    127 */
    128 #define ClassByID(networkID) \
    129     orxonox::Factory::getIdentifier(networkID)
     99namespace orxonox
     100{
     101    /**
     102        @brief Returns the Identifier with a given name through the factory.
     103        @param String The name of the class
     104    */
     105    inline Identifier* ClassByString(const std::string& name)
     106    {
     107        return Factory::getIdentifier(name);
     108    }
     109
     110    /**
     111        @brief Returns the Identifier with a given network ID through the factory.
     112        @param networkID The network ID of the class
     113    */
     114    inline Identifier* ClassByID(uint32_t id)
     115    {
     116        return Factory::getIdentifier(id);
     117    }
     118}
    130119
    131120#endif /* _CoreIncludes_H__ */
  • code/branches/core4/src/core/Identifier.h

    r3223 r3224  
    349349            static ClassIdentifier<T> *getIdentifier();
    350350            static ClassIdentifier<T> *getIdentifier(const std::string& name);
    351             void addObject(T* object);
     351
     352            bool initialiseObject(T* object, const std::string& className, bool bRootClass);
    352353
    353354            void updateConfigValues(bool updateChildren = true) const;
     
    428429    */
    429430    template <class T>
    430     inline void ClassIdentifier<T>::addObject(T* object)
    431     {
    432         COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    433         object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
    434         // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
    435         object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
     431    bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
     432    {
     433        if (bRootClass)
     434            COUT(5) << "*** Register Root-Object: " << className << std::endl;
     435        else
     436            COUT(5) << "*** Register Object: " << className << std::endl;
     437
     438        object->identifier_ = this;
     439        if (Identifier::isCreatingHierarchy())
     440        {
     441            if (bRootClass && !object->parents_)
     442                object->parents_ = new std::set<const Identifier*>();
     443
     444            if (object->parents_)
     445            {
     446                this->initializeClassHierarchy(object->parents_, bRootClass);
     447                object->parents_->insert(object->parents_->end(), this);
     448            }
     449
     450            object->setConfigValues();
     451            return true;
     452        }
     453        else
     454        {
     455            COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
     456            object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
     457
     458            // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
     459            object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
     460            return false;
     461        }
    436462    }
    437463
  • code/branches/core4/src/core/OrxonoxClass.h

    r3223 r3224  
    6363            inline Identifier* getIdentifier() const { return this->identifier_; }
    6464
    65             /** @brief Sets the Identifier of the object. Used by the RegisterObject-macro. */
    66             inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; }
    67 
    68             /** @brief Returns the list of all parents of the object. @return The list */
    69             inline std::set<const Identifier*>* getParents() const { return this->parents_; }
    70 
    71             /** @brief Creates the parents-list. */
    72             inline void createParents() { this->parents_ = new std::set<const Identifier*>(); }
    73 
    74             /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */
    75             inline MetaObjectList& getMetaList() { return (*this->metaList_); }
    76 
    77 
    7865            bool isA(const Identifier* identifier);
    7966            bool isExactlyA(const Identifier* identifier);
  • code/branches/core4/src/network/NetworkFunction.h

    r3223 r3224  
    3838#include <boost/preprocessor/cat.hpp>
    3939
    40 #include "core/OrxonoxClass.h"
    4140#include "core/Functor.h"
     41#include "core/Identifier.h"
    4242#include "FunctionCallManager.h"
    4343#include "synchronisable/Synchronisable.h"
Note: See TracChangeset for help on using the changeset viewer.