Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 25, 2013, 9:08:42 PM (12 years ago)
Author:
landauf
Message:

merged core6 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/CoreIncludes.h

    r8858 r9667  
    2828
    2929/**
    30     @defgroup Factory RegisterObject() and CreateFactory()
     30    @defgroup Factory RegisterObject() and RegisterClass()
    3131    @ingroup Object
    3232*/
     
    3535    @file
    3636    @ingroup Object Factory Class Identifier
    37     @brief Defines several very important macros used to register objects, create factories, and to work with identifiers.
    38 
    39     Every class needs the @c RegisterObject(class) macro in its constructor. If the class is an interface
    40     or the @c BaseObject itself, it needs the macro @c RegisterRootObject(class) instead.
    41 
    42     To allow the object being created through the factory, use the @c CreateFactory(class) macro outside
    43     of the class implementation, so it gets executed statically before @c main(). This will at the same time
    44     register @a class in the class-hierarchy. If you don't want @a class to be loadable, but still
    45     register it, call @c CreateUnloadableFactory(class).
     37    @brief Defines several very important macros used to register objects, register classes, and to work with identifiers.
     38
     39    Every class needs the @c RegisterObject(class) macro in its constructor.
     40
     41    To register @a class in the class-hierarchy, use the @c RegisterClass(class) macro outside of the class implementation,
     42    so it gets executed statically before @c main(). If you don't want @a class to be loadable, but still register it, call
     43    @c RegisterUnloadableClass(class).
     44
     45    Abstract classes are registered with @c RegisterAbstractClass(class). For abstract classes, the inheritance must be
     46    defined manually with @c RegisterAbstractClass(class).inheritsFrom(Class(parent)). Multiple parent classes can be defined
     47    by chaining the above command.
    4648
    4749    Example:
    4850    @code
    49     // Create the factory for MyClass
    50     CreateFactory(MyClass);
     51    // register MyClass
     52    RegisterClass(MyClass);
    5153
    5254    // Constructor:
     
    7981
    8082#include "util/Output.h"
    81 #include "Identifier.h"
    82 #include "ClassFactory.h"
    83 #include "ObjectList.h"
    84 
    85 
    86 /**
    87     @brief Intern macro, containing the common parts of @c RegisterObject and @c RegisterRootObject.
    88     @param ClassName The name of the class
    89     @param bRootClass True if the class is directly derived from orxonox::OrxonoxClass
    90 */
    91 #define InternRegisterObject(ClassName, bRootClass) \
    92     if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
     83#include "class/IdentifierManager.h"
     84#include "object/ClassFactory.h"
     85#include "object/ObjectList.h"
     86
     87// resolve macro conflict on windows
     88#if defined(ORXONOX_PLATFORM_WINDOWS)
     89#   include <windows.h>
     90#   undef RegisterClass
     91#endif
     92
     93
     94/**
     95    @brief Registers the class in the framework.
     96    @param ClassName The name of the class
     97*/
     98#define RegisterClass(ClassName) \
     99    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true)
     100
     101/**
     102    @brief Registers the class in the framework (for classes without arguments in their constructor).
     103    @param ClassName The name of the class
     104*/
     105#define RegisterClassNoArgs(ClassName) \
     106    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true)
     107
     108/**
     109    @brief Registers the class in the framework (for classes which should not be loaded through XML).
     110    @param ClassName The name of the class
     111*/
     112#define RegisterUnloadableClass(ClassName) \
     113    RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)
     114
     115/**
     116    @brief Registers an abstract class in the framework.
     117    @param ClassName The name of the class
     118*/
     119#define RegisterAbstractClass(ClassName) \
     120    RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(NULL), false)
     121
     122/**
     123    @brief Registers the class in the framework with a given Factory.
     124    @param ClassName The name of the class
     125*/
     126#define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \
     127    Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)
     128
     129/**
     130    @brief Registers a newly created object in the framework. Has to be called at the beginning of the constructor of @a ClassName.
     131    @param ClassName The name of the class
     132*/
     133#define RegisterObject(ClassName) \
     134    if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this)) \
    93135        return; \
    94136    else \
     
    96138
    97139/**
    98     @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.
    99     @param ClassName The name of the class
    100 */
    101 #define RegisterObject(ClassName) \
    102     InternRegisterObject(ClassName, false)
    103 
    104 /**
    105     @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.
    106     @param ClassName The name of the class
    107 
    108     In contrast to RegisterObject, this is used for classes that inherit directly from
    109     orxonox::OrxonoxClass, namely all interfaces and orxonox::BaseObject.
    110 */
    111 #define RegisterRootObject(ClassName) \
    112     InternRegisterObject(ClassName, true)
    113 
    114 /**
    115     @brief Creates the Factory.
    116     @param ClassName The name of the class
    117 */
    118 #define CreateFactory(ClassName) \
    119     Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)
    120 
    121 /**
    122     @brief Creates the Factory for classes which should not be loaded through XML.
    123     @param ClassName The name of the class
    124 */
    125 #define CreateUnloadableFactory(ClassName) \
    126     Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)
    127 
    128 /**
    129140    @brief Returns the Identifier of the given class.
    130141    @param ClassName The name of the class
     
    137148{
    138149    /**
     150     * @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory.
     151     */
     152    template <class T>
     153    inline Identifier& registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
     154    {
     155        return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable);
     156    }
     157
     158    /**
     159     * @brief Registers a class in the framework.
     160     * @param name The name of the class
     161     * @param factory The factory which is able to create new instances of this class
     162     * @param bLoadable Whether the class is allowed to be loaded through XML
     163     */
     164    template <class T>
     165    inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
     166    {
     167        orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
     168        Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
     169        identifier->setFactory(factory);
     170        identifier->setLoadable(bLoadable);
     171        return *identifier;
     172    }
     173
     174    /**
    139175        @brief Returns the Identifier with a given name.
    140176        @param name The name of the class
     
    142178    inline Identifier* ClassByString(const std::string& name)
    143179    {
    144         return Identifier::getIdentifierByString(name);
     180        return IdentifierManager::getInstance().getIdentifierByString(name);
    145181    }
    146182
     
    151187    inline Identifier* ClassByLowercaseString(const std::string& name)
    152188    {
    153         return Identifier::getIdentifierByLowercaseString(name);
     189        return IdentifierManager::getInstance().getIdentifierByLowercaseString(name);
    154190    }
    155191
     
    160196    inline Identifier* ClassByID(uint32_t id)
    161197    {
    162         return Identifier::getIdentifierByID(id);
     198        return IdentifierManager::getInstance().getIdentifierByID(id);
    163199    }
    164200
    165201    /**
    166202        @brief Returns the Identifier with a given 'this' pointer.
    167         @note This of course only works with OrxonoxClasses.
     203        @note This of course only works with Identifiables.
    168204              The only use is in conjunction with macros that don't know the class type.
    169         @param object Pointer to an OrxonoxClass
     205        @param object Pointer to an Identifiable
    170206    */
    171207    template <class T>
Note: See TracChangeset for help on using the changeset viewer.