Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2013, 4:23:41 PM (12 years ago)
Author:
landauf
Message:

removed constructor arguments from ClassFactories. use the helper-function registerClass() to add the factory to the corresponding identifier

File:
1 edited

Legend:

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

    r9635 r9637  
    117117*/
    118118#define CreateFactory(ClassName) \
    119     RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(#ClassName, true))
     119    RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true)
    120120
    121121/**
     
    124124*/
    125125#define CreateUnloadableFactory(ClassName) \
    126     RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(#ClassName, false))
     126    RegisterFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)
    127127
    128128/**
     
    130130    @param ClassName The name of the class
    131131*/
    132 #define RegisterFactory(ClassName, FactoryInstance) \
    133     Factory* _##ClassName##Factory = FactoryInstance
     132#define RegisterFactory(ClassName, FactoryInstance, bLoadable) \
     133    Identifier* _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)
    134134
    135135/**
     
    143143namespace orxonox
    144144{
     145    /**
     146     * @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory.
     147     */
     148    template <class T>
     149    inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)
     150    {
     151        return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable);
     152    }
     153
     154    /**
     155     * @brief Registers a class in the framework.
     156     * @param name The name of the class
     157     * @param factory The factory which is able to create new instances of this class
     158     * @param bLoadable Whether the class is allowed to be loaded through XML
     159     */
     160    template <class T>
     161    inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true)
     162    {
     163        orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
     164        Identifier* identifier = ClassIdentifier<T>::getIdentifier(name);
     165        identifier->setFactory(factory);
     166        identifier->setLoadable(bLoadable);
     167        return identifier;
     168    }
     169
    145170    /**
    146171        @brief Returns the Identifier with a given name.
Note: See TracChangeset for help on using the changeset viewer.