Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 20, 2007, 8:38:53 PM (16 years ago)
Author:
landauf
Message:
  • *cough* fixed another small bug in the object-list *cough*
  • made the object-list a template, to avoid a dynamic_cast in the Iterator
File:
1 edited

Legend:

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

    r221 r224  
    2626    class BaseObject;
    2727
    28     // ##### Identifier #####
     28    // ###############################
     29    // ###       Identifier        ###
     30    // ###############################
    2931    class Identifier
    3032    {
     
    3537        friend class BaseIdentifier;
    3638
    37         template <class T>
    38         friend class Iterator;
    39 
    4039        public:
    41             void addObject(OrxonoxClass* object);
    42             void removeObject(OrxonoxClass* object);
     40            virtual void removeObject(OrxonoxClass* object) {};
    4341
    4442            virtual BaseObject* fabricate() {};
     
    7371            IdentifierList allChildren_;
    7472
    75             ObjectList objects_;
    7673            std::string name_;
    7774
     
    8380
    8481
    85     // ##### ClassIdentifier #####
     82    // ###############################
     83    // ###     ClassIdentifier     ###
     84    // ###############################
    8685    template <class T>
    8786    class ClassIdentifier : public Identifier
    8887    {
     88        template <class U>
     89        friend class Iterator;
     90
    8991        public:
    9092            static ClassIdentifier<T>* registerClass(IdentifierList* parents, std::string name, bool bRootClass, bool bIsAbstractClass);
     
    9294            BaseObject* fabricate();
    9395            T* fabricateClass();
     96            static void addObject(T* object);
     97            void removeObject(OrxonoxClass* object);
    9498
    9599        private:
     
    99103
    100104            static ClassIdentifier<T>* pointer_s;
    101 
     105            ObjectList<T> objects_s;
    102106    };
    103107
     
    182186    }
    183187
    184     // ##### BaseIdentifier #####
     188    template <class T>
     189    void ClassIdentifier<T>::addObject(T* object)
     190    {
     191        std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
     192        ClassIdentifier<T>::getIdentifier()->objects_s.add(object);
     193    }
     194
     195    template <class T>
     196    void ClassIdentifier<T>::removeObject(OrxonoxClass* object)
     197    {
     198        bool bIterateForwards = !Identifier::isCreatingHierarchy();
     199
     200        if (bIterateForwards)
     201            std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n";
     202        else
     203            std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n";
     204
     205        this->objects_s.remove(object, bIterateForwards);
     206
     207        IdentifierListElement* temp = this->directParents_.first_;
     208        while (temp)
     209        {
     210            temp->identifier_->removeObject(object);
     211            temp = temp->next_;
     212        }
     213    }
     214
     215
     216    // ###############################
     217    // ###     BaseIdentifier      ###
     218    // ###############################
    185219    template <class B>
    186220    class BaseIdentifier
Note: See TracChangeset for help on using the changeset viewer.