Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2007, 5:57:02 AM (16 years ago)
Author:
landauf
Message:

added factory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchie/src/Identifier.h

    r197 r218  
    66#include "ObjectList.h"
    77#include "OrxonoxClass.h"
     8#include "Factory.h"
    89
    910namespace orxonox
     
    2122            void addObject(OrxonoxClass* object);
    2223            void removeObject(OrxonoxClass* object);
     24
     25            virtual OrxonoxClass* fabricate() {};
    2326
    2427            bool isA(Identifier* identifier);
     
    6164            static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass);
    6265            static ClassIdentifier<T>* getIdentifier();
     66            OrxonoxClass* fabricate();
     67            T* fabricateClass();
    6368
    6469        private:
     
    8388    {
    8489        this->pointer_ = NULL;
     90    }
     91
     92    template <class T>
     93    OrxonoxClass* ClassIdentifier<T>::fabricate()
     94    {
     95        return this->fabricateClass();
     96    }
     97
     98    template <class T>
     99    T* ClassIdentifier<T>::fabricateClass()
     100    {
     101        return new T;
    85102    }
    86103
     
    97114                pointer_->name_ = name;
    98115                pointer_->bIsAbstractClass_ = bIsAbstractClass;
     116
     117                ClassFactory::add(name, pointer_);
     118
    99119                pointer_->initialize(parents);
    100120            }
     
    124144    }
    125145
    126 
    127146    // ##### BaseIdentifier #####
    128147    template <class B>
    129     class BaseIdentifier// : public Identifier
     148    class BaseIdentifier
    130149    {
    131150        public:
    132151            BaseIdentifier();
    133152
    134             //template <class T>
    135             BaseIdentifier<B>& operator= (/*Class*/Identifier/*<T>*/* identifier)
     153            BaseIdentifier<B>& operator= (Identifier* identifier)
    136154            {
    137155                if (!identifier->isA(ClassIdentifier<B>::getIdentifier()))
     
    145163                return *this;
    146164            }
     165
     166            Identifier* operator* ()
     167            {
     168                return this->identifier_;
     169            }
     170
     171            Identifier* operator-> () const
     172            {
     173                return this->identifier_;
     174            }
     175
     176            B* fabricate()
     177            {
     178                OrxonoxClass* newObject = this->identifier_->fabricate();
     179                if (newObject)
     180                {
     181                    return dynamic_cast<B*>(newObject);
     182                }
     183                else
     184                {
     185                    if (this->identifier_)
     186                    {
     187                        std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<B>::getIdentifier()->getName() << "!\n";
     188                        std::cout << "Error: Couldn't fabricate a new Object.\n";
     189                        std::cout << "Aborting...\n";
     190                    }
     191                    else
     192                    {
     193                        std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";
     194                        std::cout << "Aborting...\n";
     195                    }
     196
     197                    abort();
     198                }
     199            }
     200
    147201            inline Identifier* getIdentifier()
    148202                { return this->identifier_; }
Note: See TracChangeset for help on using the changeset viewer.