Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2013, 2:38:03 PM (11 years ago)
Author:
landauf
Message:

added Factory for classes that don't require a Context as constructor argument

File:
1 edited

Legend:

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

    r9633 r9635  
    5050    // ###       Factory       ###
    5151    // ###########################
    52     /// Base-class of ClassFactory.
     52    /// Base-class of all factories.
    5353    class _CoreExport Factory
    5454    {
     
    6161    // ###      ClassFactory       ###
    6262    // ###############################
    63     /// The ClassFactory is able to create new objects of a specific class.
     63    /// The ClassFactory is able to create new objects of a specific class that require no constructor arguments.
    6464    template <class T>
    6565    class ClassFactory : public Factory
     
    8484            inline Identifiable* fabricate(Context* context)
    8585            {
     86                return static_cast<Identifiable*>(new T());
     87            }
     88    };
     89
     90    // ###############################
     91    // ### ClassFactoryWithContext ###
     92    // ###############################
     93    /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument
     94    template <class T>
     95    class ClassFactoryWithContext : public Factory
     96    {
     97        public:
     98            /**
     99                @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
     100                @param name The name of the class
     101                @param bLoadable True if the class can be loaded through XML
     102            */
     103            ClassFactoryWithContext(const std::string& name, bool bLoadable = true)
     104            {
     105                orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
     106                ClassIdentifier<T>::getIdentifier(name)->setFactory(this);
     107                ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
     108            }
     109
     110            /**
     111                @brief Creates and returns a new object of class T.
     112                @return The new object
     113            */
     114            inline Identifiable* fabricate(Context* context)
     115            {
    86116                return static_cast<Identifiable*>(new T(context));
    87117            }
Note: See TracChangeset for help on using the changeset viewer.