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
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/object/ClassFactory.h

    r9563 r9667  
    4343
    4444#include "util/Output.h"
    45 #include "core/class/Identifier.h"
    4645
    4746namespace orxonox
     
    5049    // ###       Factory       ###
    5150    // ###########################
    52     /// Base-class of ClassFactory.
     51    /// Base-class of all factories.
    5352    class _CoreExport Factory
    5453    {
    5554        public:
    56             virtual ~Factory() {};
    57             virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;
     55            virtual ~Factory() {}
     56            virtual Identifiable* fabricate(Context* context) = 0;
    5857    };
    5958
     
    6160    // ###      ClassFactory       ###
    6261    // ###############################
    63     /// The ClassFactory is able to create new objects of a specific class.
     62    /// The ClassFactory is the base-class of all class-spezific factories
    6463    template <class T>
    6564    class ClassFactory : public Factory
    6665    {
     66    };
     67
     68    // ###############################
     69    // ###   ClassFactoryNoArgs    ###
     70    // ###############################
     71    /// The ClassFactoryNoArgs is able to create new objects of a specific class that require no constructor arguments.
     72    template <class T>
     73    class ClassFactoryNoArgs : public ClassFactory<T>
     74    {
    6775        public:
    68             /**
    69                 @brief Constructor: Adds the ClassFactory to the Identifier of the same type.
    70                 @param name The name of the class
    71                 @param bLoadable True if the class can be loaded through XML
    72             */
    73             ClassFactory(const std::string& name, bool bLoadable = true)
    74             {
    75                 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl;
    76                 ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
    77                 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
    78             }
    79 
    8076            /**
    8177                @brief Creates and returns a new object of class T.
    8278                @return The new object
    8379            */
    84             inline OrxonoxClass* fabricate(BaseObject* creator)
     80            inline Identifiable* fabricate(Context* context)
    8581            {
    86                 return static_cast<OrxonoxClass*>(new T(creator));
     82                return static_cast<Identifiable*>(new T());
     83            }
     84    };
     85
     86    // ###############################
     87    // ### ClassFactoryWithContext ###
     88    // ###############################
     89    /// The ClassFactoryWithContext is able to create new objects of a specific class that require a context as constructor argument
     90    template <class T>
     91    class ClassFactoryWithContext : public ClassFactory<T>
     92    {
     93        public:
     94            /**
     95                @brief Creates and returns a new object of class T.
     96                @return The new object
     97            */
     98            inline Identifiable* fabricate(Context* context)
     99            {
     100                return static_cast<Identifiable*>(new T(context));
    87101            }
    88102    };
Note: See TracChangeset for help on using the changeset viewer.