Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2007, 7:19:54 PM (17 years ago)
Author:
landauf
Message:

added "MetaObjectList", containing the list-element of the ObjectList of all classes an object is registered in. this allowes much faster deleting of objects.

Location:
code/branches/objecthierarchie/src
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchie/src/BaseObject.cc

    r244 r246  
    1212    BaseObject::~BaseObject()
    1313    {
    14         UnregisterObject();
    1514    }
    1615}
  • code/branches/objecthierarchie/src/CMakeLists.txt

    r244 r246  
    22
    33# create a few variables to simplify life
    4 SET(SRC_FILES orxonox.cc IdentifierList.cc Identifier.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc)
    5 SET(INC_FILES IdentifierIncludes.h Identifier.h Factory.h ClassFactory.h IdentifierList.h ObjectList.h Iterator.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h)
     4SET(SRC_FILES orxonox.cc IdentifierList.cc Identifier.cc MetaObjectList.cc Factory.cc OrxonoxClass.cc BaseObject.cc test1.cc test2.cc test3.cc)
     5SET(INC_FILES IdentifierIncludes.h Identifier.h Factory.h ClassFactory.h IdentifierList.h ObjectList.h MetaObjectList.h Iterator.h OrxonoxClass.h BaseObject.h Test.h test1.h test2.h test3.h)
    66
    77#Creates an executable
  • code/branches/objecthierarchie/src/Identifier.h

    r244 r246  
    88#include "Factory.h"
    99
    10 #define HIERARCHY_VERBOSE true
     10#define HIERARCHY_VERBOSE false
    1111
    1212
     
    3030
    3131        public:
    32             virtual void removeObject(OrxonoxClass* object) const = 0;
    33             virtual void removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const = 0;
    34 
    3532            inline void addFactory(BaseFactory* factory) { this->factory_ = factory; }
    3633            BaseObject* fabricate();
     
    9390            static ClassIdentifier<T>* getIdentifier();
    9491            static void addObject(T* object);
    95             void removeObject(OrxonoxClass* object) const;
    96             void removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const;
    9792
    9893        private:
     
    172167        std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    173168#endif
    174         ClassIdentifier<T>::getIdentifier()->objects_->add(object);
    175     }
    176 
    177     template <class T>
    178     void ClassIdentifier<T>::removeObject(OrxonoxClass* object) const
    179     {
    180         bool bIterateForwards = !Identifier::isCreatingHierarchy();
    181 
    182         this->removeObjectIntern(object, bIterateForwards);
    183 
    184         IdentifierListElement* temp = this->parents_.first_;
    185         while (temp)
    186         {
    187             temp->identifier_->removeObjectIntern(object, bIterateForwards);
    188             temp = temp->next_;
    189         }
    190     }
    191 
    192     template <class T>
    193     void ClassIdentifier<T>::removeObjectIntern(OrxonoxClass* object, bool bIterateForwards) const
    194     {
    195 #if HIERARCHY_VERBOSE
    196         if (bIterateForwards)
    197             std::cout << "*** Removed object from " << this->name_ << "-list, iterating forwards.\n";
    198         else
    199             std::cout << "*** Removed object from " << this->name_ << "-list, iterating backwards.\n";
    200 #endif
    201 
    202         this->objects_->remove(object, bIterateForwards);
     169        object->getMetaList()->add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));
    203170    }
    204171
  • code/branches/objecthierarchie/src/IdentifierIncludes.h

    r244 r246  
    22#include "Factory.h"
    33#include "ClassFactory.h"
    4 #include "IdentifierList.h"
    5 #include "ObjectList.h"
     4//#include "IdentifierList.h"
     5//#include "ObjectList.h"
    66#include "Iterator.h"
    77#include "OrxonoxClass.h"
     
    3737#endif
    3838
    39 #define UnregisterObject() \
    40     this->getIdentifier()->removeObject(this)
    41 
    4239#define Class(ClassName) \
    4340    ClassIdentifier<ClassName>::getIdentifier()
  • code/branches/objecthierarchie/src/ObjectList.h

    r224 r246  
    4444            ObjectList();
    4545            ~ObjectList();
    46             void add(T* object);
     46            ObjectListElement<T>* add(T* object);
    4747            void remove(OrxonoxClass* object, bool bIterateForwards = true);
    4848
     
    7171
    7272    template <class T>
    73     void ObjectList<T>::add(T* object)
     73    ObjectListElement<T>* ObjectList<T>::add(T* object)
    7474    {
    7575        if (!this->last_)
     
    8585            temp->next_ = this->last_;
    8686        }
     87
     88        return this->last_;
    8789    }
    8890
  • code/branches/objecthierarchie/src/OrxonoxClass.cc

    r219 r246  
    77        this->identifier_ = 0;
    88        this->parents_ = 0;
     9
     10        this->metaList_ = new MetaObjectList;
    911    }
    1012
     
    1315        if (this->parents_)
    1416            delete this->parents_;
     17
     18        delete this->metaList_;
    1519    }
    1620}
  • code/branches/objecthierarchie/src/OrxonoxClass.h

    r240 r246  
    44#include "Identifier.h"
    55#include "IdentifierList.h"
     6#include "ObjectList.h"
     7#include "MetaObjectList.h"
    68
    79namespace orxonox
     
    1214            OrxonoxClass();
    1315            virtual ~OrxonoxClass();
    14             Identifier* getIdentifier() const { return this->identifier_; }
    15             void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; }
    16             IdentifierList* getParents() const { return this->parents_; }
    17             void setParents(IdentifierList* parents) { this->parents_ = parents; }
     16            inline Identifier* getIdentifier() const { return this->identifier_; }
     17            inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; }
     18            inline IdentifierList* getParents() const { return this->parents_; }
     19            inline void setParents(IdentifierList* parents) { this->parents_ = parents; }
     20            inline MetaObjectList* getMetaList() { return this->metaList_; }
    1821
    1922        private:
    2023            Identifier* identifier_;
    2124            IdentifierList* parents_;
     25            MetaObjectList* metaList_;
    2226    };
    2327}
  • code/branches/objecthierarchie/src/orxonox.cc

    r244 r246  
    407407        delete test8_02;
    408408        delete test8_03;
    409 */
    410 /*
     409
     410
    411411        std::cout << "Test 9\n";
    412412        std::cout << "1\n";
     
    441441        Identifier* test10_03 = Class(A3B1C1);
    442442
    443 
    444443        BaseObject* test10_04 = test10_01->fabricate();
    445444        BaseObject* test10_05 = test10_02->fabricate();
     
    451450
    452451        std::cout << "1\n";
    453         int count = 0;
    454         for (Iterator<BaseObject> it; it != 0; ++it)
    455             count++;
     452        int count;
     453        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
    456454        std::cout << "Anzahl BaseObjects: " << count << "\n";
    457 
    458         count = 0;
    459         for (Iterator<A1> it; it != 0; ++it)
    460             count++;
     455        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
    461456        std::cout << "Anzahl A1: " << count << "\n";
    462 
    463         count = 0;
    464         for (Iterator<A1B1> it; it; ++it)
    465             count++;
     457        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
    466458        std::cout << "Anzahl A1B1: " << count << "\n";
    467 
    468         count = 0;
    469         for (Iterator<A1B1C1> it; it; ++it)
    470             count++;
     459        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
    471460        std::cout << "Anzahl A1B1C1: " << count << "\n";
    472 
    473         count = 0;
    474         for (Iterator<A2> it; it; ++it)
    475             count++;
     461        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
    476462        std::cout << "Anzahl A2: " << count << "\n";
    477 
    478463
    479464        std::cout << "2\n";
     
    494479        }
    495480
     481        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     482        std::cout << "Anzahl BaseObjects: " << count << "\n";
     483        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     484        std::cout << "Anzahl A1: " << count << "\n";
     485        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     486        std::cout << "Anzahl A1B1: " << count << "\n";
     487        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     488        std::cout << "Anzahl A1B1C1: " << count << "\n";
     489        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     490        std::cout << "Anzahl A2: " << count << "\n";
     491
    496492        for (Iterator<A2B1C1> it; it; ++it)
    497493            std::cout << "Name: " << it->name_ << "\n";
     
    504500        delete test10_08;
    505501
     502        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     503        std::cout << "Anzahl BaseObjects: " << count << "\n";
     504        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     505        std::cout << "Anzahl A1: " << count << "\n";
     506        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     507        std::cout << "Anzahl A1B1: " << count << "\n";
     508        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     509        std::cout << "Anzahl A1B1C1: " << count << "\n";
     510        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     511        std::cout << "Anzahl A2: " << count << "\n";
     512
    506513        std::cout << "5\n";
    507514        for (Iterator<A2B1C1> it; it; ++it)
     
    515522        delete test10_09;
    516523
     524        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     525        std::cout << "Anzahl BaseObjects: " << count << "\n";
     526        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     527        std::cout << "Anzahl A1: " << count << "\n";
     528        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     529        std::cout << "Anzahl A1B1: " << count << "\n";
     530        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     531        std::cout << "Anzahl A1B1C1: " << count << "\n";
     532        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     533        std::cout << "Anzahl A2: " << count << "\n";
     534
    517535        std::cout << "8\n";
    518536        for (Iterator<A2B1C1> it; it; ++it)
     
    525543        std::cout << "10\n";
    526544        delete test10_10;
     545
     546        count = 0; for (Iterator<BaseObject> it; it != 0; ++it) { count++; }
     547        std::cout << "Anzahl BaseObjects: " << count << "\n";
     548        count = 0; for (Iterator<A1> it; it != 0; ++it) { count++; }
     549        std::cout << "Anzahl A1: " << count << "\n";
     550        count = 0; for (Iterator<A1B1> it; it; ++it) { count++; }
     551        std::cout << "Anzahl A1B1: " << count << "\n";
     552        count = 0; for (Iterator<A1B1C1> it; it; ++it) { count++; }
     553        std::cout << "Anzahl A1B1C1: " << count << "\n";
     554        count = 0; for (Iterator<A2> it; it; ++it) { count++; }
     555        std::cout << "Anzahl A2: " << count << "\n";
    527556
    528557        std::cout << "11\n";
Note: See TracChangeset for help on using the changeset viewer.