Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5777


Ignore:
Timestamp:
Sep 24, 2009, 12:15:20 AM (15 years ago)
Author:
landauf
Message:

simplified ClassFactory creation
fixed typo in Factory

Location:
code/branches/core5/src/libraries/core
Files:
5 edited

Legend:

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

    r5769 r5777  
    5454    {
    5555        public:
     56            virtual ~BaseFactory() {};
    5657            virtual BaseObject* fabricate(BaseObject* creator) = 0;
    57             virtual ~BaseFactory() {};
    5858    };
    5959
     
    6666    {
    6767        public:
    68             static bool create(const std::string& name, bool bLoadable = true);
     68            ClassFactory(const std::string& name, bool bLoadable = true);
    6969            BaseObject* fabricate(BaseObject* creator);
    70 
    71         private:
    72             ClassFactory() {}                               // Don't create
    73             ClassFactory(const ClassFactory& factory) {}    // Don't copy
    74             virtual ~ClassFactory() {}                      // Don't delete
    75 
    76             static T* createNewObject(BaseObject* creator);
    7770    };
    7871
     
    8477    */
    8578    template <class T>
    86     bool ClassFactory<T>::create(const std::string& name, bool bLoadable)
     79    ClassFactory<T>::ClassFactory(const std::string& name, bool bLoadable)
    8780    {
    8881        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    89         ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
     82        ClassIdentifier<T>::getIdentifier(name)->addFactory(this);
    9083        ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
    9184        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    92 
    93         return true;
    9485    }
    9586
     
    10192    inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)
    10293    {
    103         return ClassFactory<T>::createNewObject(creator);
    104     }
    105 
    106     /**
    107         @brief Creates and returns a new object of class T; this is a wrapper for the new operator.
    108         @return The new object
    109     */
    110     template <class T>
    111     inline T* ClassFactory<T>::createNewObject(BaseObject* creator)
    112     {
    113         return new T(creator);
     94        return static_cast<BaseObject*>(new T(creator));
    11495    }
    11596}
  • code/branches/core5/src/libraries/core/CoreIncludes.h

    r5776 r5777  
    8181*/
    8282#define CreateFactory(ClassName) \
    83     bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true)
     83    BaseFactory* ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)
    8484
    8585/**
     
    8888*/
    8989#define CreateUnloadableFactory(ClassName) \
    90     bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false)
     90    BaseFactory* ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)
    9191
    9292/**
  • code/branches/core5/src/libraries/core/Factory.h

    r5769 r5777  
    6969
    7070            /** @brief Returns the factory-map. */
    71             static const std::map<std::string, Identifier*>& getFacbtoryMap()
     71            static const std::map<std::string, Identifier*>& getFactoryMap()
    7272                { return Factory::getFactoryPointer()->identifierStringMap_; }
    7373            /** @brief Returns the begin-iterator of the factory-map. */
  • code/branches/core5/src/libraries/core/Identifier.cc

    r5769 r5777  
    235235            COUT(1) << "Aborting..." << std::endl;
    236236            abort();
    237             return NULL;
     237            return 0;
    238238        }
    239239    }
  • code/branches/core5/src/libraries/core/SubclassIdentifier.h

    r5776 r5777  
    174174                    }
    175175
    176                     assert(false);
     176                    COUT(1) << "Aborting..." << std::endl;
     177                    abort();
    177178                    return 0;
    178179                }
Note: See TracChangeset for help on using the changeset viewer.