Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1574


Ignore:
Timestamp:
Jun 9, 2008, 4:35:38 AM (16 years ago)
Author:
landauf
Message:

big change in ObjectList: separated the class into a non-template base and a template wrapper for the base. this also changes the Iterator, there is now a non-template IteratorBase. this brings much more flexibility, like iterating through all objects of a given identifier without knowing the type. however this needs a dynamic_cast, which isn't quite optimal, but I think there are much worser things than that out there. ;)

there isn't much you have to know about this, except there is no more ObjectList<myClass>::start() function but a ObjectList<myClass>::begin() to be more STLish. another thing: ObjectList<myClass>::end() points now to the element _after_ the last element, so it's possible to iterate in a for-loop until (it != ObjectList<myClass>::end()). the reason is the same as above. however, (it) as a boolean still works perfectly fine.

Location:
code/branches/core3
Files:
3 added
20 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/bin/levels/sample.oxw

    r1557 r1574  
    4444for i = 1, 226, 1
    4545do ?>
    46   <Model position="<?lua print(math.random() * 40000 - 20000)?>, <?lua print(math.random() * 40000 - 20000) ?>, <?lua print(math.random() * 40000 - 20000) ?>" scale="<?lua print(math.random() * 100 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random() * 30 + 15) ?>" />
     46  <Model position="<?lua print(math.random() * 40000 - 20000)?>, <?lua print(math.random() * 40000 - 20000) ?>, <?lua print(math.random() * 40000 - 20000) ?>" scale="<?lua print(math.random() * 250 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random() * 30 + 15) ?>" />
    4747<?lua
    4848end
  • code/branches/core3/src/core/CMakeLists.txt

    r1555 r1574  
    55  Error.cc
    66  Language.cc
     7  ObjectListBase.cc
    78  OrxonoxClass.cc
    89  OutputBuffer.cc
  • code/branches/core3/src/core/ClassTreeMask.h

    r1505 r1574  
    7878namespace orxonox
    7979{
    80     // ###############################
    81     // ###    ClassTreeMaskNode    ###
    82     // ###############################
     80    // ###################################
     81    // ###      ClassTreeMaskNode      ###
     82    // ###################################
    8383    //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask.
    8484    /**
     
    116116
    117117
    118     // ###############################
    119     // ###  ClassTreeMaskIterator  ###
    120     // ###############################
     118    // ###################################
     119    // ###    ClassTreeMaskIterator    ###
     120    // ###################################
    121121    //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules.
    122122    /**
     
    146146
    147147
    148     // ###############################
    149     // ###      ClassTreeMask      ###
    150     // ###############################
     148    // ###################################
     149    // ###        ClassTreeMask        ###
     150    // ###################################
    151151    //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not.
    152152    /**
     
    214214            ClassTreeMaskNode* root_;   //!< The root-node of the internal rule-tree, usually BaseObject
    215215    };
     216
     217
     218    // ###################################
     219    // ### ClassTreeMaskObjectIterator ###
     220    // ###################################
     221    //! ...
     222    /**
     223        ...
     224    */
     225    class _CoreExport ClassTreeMaskObjectIterator
     226    {
     227    };
    216228}
    217229
  • code/branches/core3/src/core/CorePrereqs.h

    r1543 r1574  
    125125  template <class T>
    126126  class Iterator;
     127  class IteratorBase;
    127128  class Language;
    128129  class LanguageEntry;
     
    130131  class Loader;
    131132  class MetaObjectList;
    132   template <class T>
    133133  class MetaObjectListElement;
    134134  class Namespace;
     
    136136  template <class T>
    137137  class ObjectList;
    138   template <class T>
    139   class ObjectListElement;
     138  class ObjectListBase;
     139  class ObjectListBaseElement;
    140140  class OrxonoxClass;
    141141  class OutputBuffer;
  • code/branches/core3/src/core/Identifier.cc

    r1543 r1574  
    3939#include "ConsoleCommand.h"
    4040#include "CommandExecutor.h"
     41#include "MetaObjectList.h"
     42#include "ObjectList.h"
     43#include "OrxonoxClass.h"
    4144
    4245namespace orxonox
     
    5255    Identifier::Identifier()
    5356    {
     57        this->objects_ = new ObjectListBase(this);
     58
    5459        this->bCreatedOneObject_ = false;
    5560        this->factory_ = 0;
     
    174179
    175180    /**
     181        @brief Adds an object of the given type to the ObjectList.
     182        @param object The object to add
     183    */
     184    void Identifier::addObject(OrxonoxClass* object)
     185    {
     186        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
     187        object->getMetaList().add(this->objects_, this->objects_->add(object));
     188    }
     189
     190    /**
    176191        @brief Returns true, if the Identifier is at least of the given type.
    177192        @param identifier The identifier to compare with
  • code/branches/core3/src/core/Identifier.h

    r1543 r1574  
    6060#include <utility>
    6161
    62 #include "ObjectList.h"
    6362#include "Debug.h"
    6463#include "Iterator.h"
    65 #include "MetaObjectList.h"
    6664#include "util/String.h"
    6765
     
    108106            bool isDirectParentOf(const Identifier* identifier) const;
    109107
    110             virtual const ObjectList<BaseObject>* getObjectList() const = 0;
    111 
    112             virtual void updateConfigValues() const = 0;
     108            void addObject(OrxonoxClass* object);
     109
     110            /** @brief Returns the list of all existing objects of this class. @return The list */
     111            inline ObjectListBase* getObjects() const
     112                { return this->objects_; }
    113113
    114114            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    115115            inline const std::string& getName() const { return this->name_; }
    116116
     117            virtual void updateConfigValues() const = 0;
    117118
    118119            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
     
    263264            std::string name_;                                             //!< The name of the class the Identifier belongs to
    264265
     266            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    265267            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
    266268            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     
    297299        public:
    298300            ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass);
    299             void addObject(T* object);
    300301            void setName(const std::string& name);
    301             /** @brief Returns the list of all existing objects of this class. @return The list */
    302             inline ObjectList<T>* getObjects() const { return this->objects_; }
    303             /** @brief Returns a list of all existing objects of this class. @return The list */
    304             inline ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; }
    305302
    306303            void updateConfigValues() const;
     
    319316            ~ClassIdentifier() {}                                       // don't delete
    320317
    321             ObjectList<T>* objects_;                                                                    //!< The ObjectList, containing all objects of type T
    322318            bool bSetName_;                                                                             //!< True if the name is set
    323319            std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;              //!< All loadable parameters
     
    336332    ClassIdentifier<T>::ClassIdentifier()
    337333    {
    338 //        this->objects_ = ObjectList<T>::getList();
    339         this->objects_ = new ObjectList<T>();
    340334        this->bSetName_ = false;
    341335    }
     
    408402
    409403    /**
    410         @brief Adds an object of the given type to the ObjectList.
    411         @param object The object to add
    412     */
    413     template <class T>
    414     void ClassIdentifier<T>::addObject(T* object)
    415     {
    416         COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    417         object->getMetaList().add(this->objects_, this->objects_->add(object));
    418     }
    419 
    420     /**
    421404        @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
    422405    */
     
    424407    void ClassIdentifier<T>::updateConfigValues() const
    425408    {
    426         for (Iterator<T> it = this->objects_->start(); it; ++it)
    427             ((T*)*it)->setConfigValues();
     409        for (Iterator<T> it = this->objects_->begin(); it; ++it)
     410            (*it)->setConfigValues();
    428411    }
    429412
  • code/branches/core3/src/core/Iterator.h

    r1543 r1574  
    3535
    3636    Usage:
    37     for (Iterator<class> it = ObjectList<class>::start(); it != 0; ++it)
     37    for (Iterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
    3838    {
    3939        it->someFunction(...);
    40         class* myObject = *it;
     40        myClass* myObject = *it;
    4141    }
    42 
    43     Warning: Don't delete objects directly through the iterator.
    4442*/
    4543
     
    4947#include "CorePrereqs.h"
    5048
    51 #include "ObjectList.h"
     49#include "IteratorBase.h"
    5250
    5351namespace orxonox
    5452{
    55     //! The iterator allows to iterate through an ObjectList of a given class.
     53    //! The Iterator allows to iterate through the ObjectList of a given class.
    5654    template <class T>
    57     class Iterator
     55    class Iterator : public IteratorBase
    5856    {
    5957        public:
     
    6159                @brief Constructor: Sets the element, whereon the iterator points, to zero.
    6260            */
    63             Iterator()
     61            inline Iterator()
    6462            {
    65                 this->element_ = 0;
    6663                ClassIdentifier<T>::getIdentifier()->getObjects()->registerIterator(this);
    6764            }
     
    7168                @param element The element to start with
    7269            */
    73             Iterator(ObjectListElement<T>* element)
     70            inline Iterator(ObjectListBaseElement* element) : IteratorBase((ObjectListBaseElement*)element)
    7471            {
    75                 this->element_ = element;
    7672                ClassIdentifier<T>::getIdentifier()->getObjects()->registerIterator(this);
    7773            }
     
    8076                @brief Unregisters the Iterator from the ObjectList.
    8177            */
    82             ~Iterator()
     78            inline ~Iterator()
    8379            {
    8480                ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterIterator(this);
    85             }
    86 
    87             /**
    88                 @brief Assigns an element to the iterator.
    89                 @param element The element
    90             */
    91             Iterator<T> operator=(ObjectListElement<T>* element)
    92             {
    93                 this->element_ = element;
    9481            }
    9582
     
    9885                @return The Iterator itself
    9986            */
    100             Iterator<T> operator++()
     87            inline Iterator<T> operator++()
    10188            {
    102                 if (this->element_)
    103                     this->element_ = this->element_->next_;
     89                IteratorBase::operator++();
    10490                return *this;
    10591            }
     
    10995                @return The Iterator itself
    11096            */
    111             Iterator<T> operator++(int i)
     97            inline Iterator<T> operator++(int i)
    11298            {
    11399                Iterator<T> copy = *this;
    114                 if (this->element_)
    115                     this->element_ = this->element_->next_;
     100                IteratorBase::operator++();
    116101                return copy;
    117102            }
     
    121106                @return The Iterator itself
    122107            */
    123             Iterator<T> operator--()
     108            inline Iterator<T> operator--()
    124109            {
    125                 if (this->element_)
    126                     this->element_ = this->element_->prev_;
     110                IteratorBase::operator--();
    127111                return *this;
    128112            }
     
    132116                @return The Iterator itself
    133117            */
    134             Iterator<T> operator--(int i)
     118            inline Iterator<T> operator--(int i)
    135119            {
    136120                Iterator<T> copy = *this;
    137                 if (this->element_)
    138                     this->element_ = this->element_->prev_;
     121                IteratorBase::operator--();
    139122                return copy;
    140123            }
     
    144127                @return The object the Iterator points at
    145128            */
    146             T* operator*()
     129            inline T* operator*()
    147130            {
    148                 if (this->element_)
    149                     return this->element_->object_;
    150                 else
    151                     return 0;
     131                return dynamic_cast<T*>(IteratorBase::operator*());
    152132            }
    153133
     
    156136                @return The object the Iterator points at
    157137            */
    158             T* operator->() const
     138            inline T* operator->() const
    159139            {
    160                 if (this->element_)
    161                     return this->element_->object_;
    162                 else
    163                     return 0;
    164 
     140                return dynamic_cast<T*>(IteratorBase::operator->());
    165141            }
    166142
    167143            /**
    168                 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
    169                 @return True if the iterator points to an existing object.
     144                @brief Overloading of the == operator to compare with another Iterator.
     145                @param compare The other Iterator
     146                @return True if the iterators point to the same element
    170147            */
    171             operator bool()
     148            inline bool operator==(const Iterator<T>& compare)
    172149            {
    173                 return (this->element_ != 0);
     150                return (this->element_ == compare.element_);
    174151            }
    175152
    176153            /**
    177                 @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool.
    178                 @param compare The integer (must be zero, everything else makes no sense).
    179                 @return True if the iterator points to an existing object.
     154                @brief Overloading of the != operator to compare with another Iterator.
     155                @param compare The other Iterator
     156                @return True if the iterators point to different elements
    180157            */
    181             bool operator!=(ObjectListElement<T>* compare)
     158            inline bool operator!=(const Iterator<T>& compare)
    182159            {
    183                 return (this->element_ != compare);
     160                return (this->element_ != compare.element_);
    184161            }
    185 
    186         private:
    187             ObjectListElement<T>* element_;     //!< The element the Iterator points at
    188162    };
    189163}
    190164
     165// Include ObjectList.h so the user only has to include one file: Iterator.h
     166#include "ObjectList.h"
     167
    191168#endif /* _Iterator_H__ */
  • code/branches/core3/src/core/Loader.cc

    r1505 r1574  
    3232#include "Identifier.h"
    3333#include "Iterator.h"
     34#include "ObjectList.h"
    3435#include "Debug.h"
    3536#include "CoreIncludes.h"
     
    9192    void Loader::unload(const ClassTreeMask& mask)
    9293    {
    93         for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it; )
     94        for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); )
    9495        {
    9596            if (mask.isIncluded(it->getIdentifier()))
  • code/branches/core3/src/core/MetaObjectList.cc

    r1505 r1574  
    3333
    3434#include "MetaObjectList.h"
     35#include "Debug.h"
    3536
    3637namespace orxonox
    3738{
     39    // ###############################
     40    // ###  MetaObjectListElement  ###
     41    // ###############################
     42    /**
     43        @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
     44    */
     45    MetaObjectListElement::~MetaObjectListElement()
     46    {
     47        COUT(5) << "*** MetaObjectList: Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << std::endl;
     48        this->list_->notifyIterators(this->element_);
     49
     50        if (this->element_->next_)
     51            this->element_->next_->prev_ = this->element_->prev_;
     52        else
     53            this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
     54
     55        if (this->element_->prev_)
     56            this->element_->prev_->next_ = this->element_->next_;
     57        else
     58            this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
     59
     60        delete this->element_;
     61    }
     62
     63
     64    // ###############################
     65    // ###     MetaObjectList      ###
     66    // ###############################
    3867    /**
    3968        @brief Constructor: Sets first_ to zero.
     
    4978    MetaObjectList::~MetaObjectList()
    5079    {
    51         BaseMetaObjectListElement* temp;
     80        MetaObjectListElement* temp;
    5281        while (this->first_)
    5382        {
     
    5786        }
    5887    }
     88
     89    /**
     90        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
     91        @param list The ObjectList wherein the element is
     92        @param element The element wherein the object is
     93    */
     94    void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
     95    {
     96        MetaObjectListElement* temp = this->first_;
     97        this->first_ = new MetaObjectListElement(list, element);
     98        this->first_->next_ = temp;
     99    }
    59100}
  • code/branches/core3/src/core/MetaObjectList.h

    r1543 r1574  
    4141#include "CorePrereqs.h"
    4242
    43 #include "ObjectList.h"
     43#include "ObjectListBase.h"
    4444#include "Identifier.h"
    45 #include "Debug.h"
    4645
    4746namespace orxonox
    4847{
    49     //! Base-class of MetaObjectListElement, because those is a template
    50     class BaseMetaObjectListElement
    51     {
    52         public:
    53             /** @brief Default destructor */
    54             virtual ~BaseMetaObjectListElement() {};
    55 
    56             BaseMetaObjectListElement* next_;       //!< The next Element in the list
    57     };
    58 
    5948    // ###############################
    6049    // ###  MetaObjectListElement  ###
    6150    // ###############################
    6251    //! The list-element of the MetaObjectList
    63     template <class T>
    64     class MetaObjectListElement : public BaseMetaObjectListElement
     52    class _CoreExport MetaObjectListElement
    6553    {
    6654        public:
    67             MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element);
    68             virtual ~MetaObjectListElement();
     55            /**
     56                @brief Constructor: Creates the list-element with given list and element.
     57            */
     58            MetaObjectListElement(ObjectListBase* list, ObjectListBaseElement* element) : next_(0), element_(element), list_(list) {}
     59            ~MetaObjectListElement();
    6960
    70             ObjectListElement<T>* element_;         //!< The list element, containing the object
    71             ObjectList<T>* list_;                   //!< The list, containing the element
     61            MetaObjectListElement* next_;       //!< The next Element in the list
     62            ObjectListBaseElement* element_;    //!< The list element, containing the object
     63            ObjectListBase* list_;              //!< The list, containing the element
    7264    };
    73 
    74     /**
    75         @brief Constructor: Creates the list-element with given list and element.
    76     */
    77     template <class T>
    78     MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element)
    79     {
    80         this->element_ = element;
    81         this->list_ = list;
    82         this->next_ = 0;
    83     }
    84 
    85     /**
    86         @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.
    87     */
    88     template <class T>
    89     MetaObjectListElement<T>::~MetaObjectListElement()
    90     {
    91         COUT(5) << "*** MetaObjectList: Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
    92         this->list_->notifyIterators(this->element_);
    93 
    94         if (this->element_->next_)
    95             this->element_->next_->prev_ = this->element_->prev_;
    96         else
    97             this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
    98 
    99         if (this->element_->prev_)
    100             this->element_->prev_->next_ = this->element_->next_;
    101         else
    102             this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
    103 
    104         delete this->element_;
    105     }
    10665
    10766
     
    10968    // ###     MetaObjectList      ###
    11069    // ###############################
    111     //!  The MetaObjectList contains ObjectListElements and their ObjectLists.
     70    //!  The MetaObjectList contains ObjectListBaseElements and their ObjectListBases.
    11271    /**
    11372        The MetaObjectList is a single-linked list, containing all list-elements and their
     
    12079            MetaObjectList();
    12180            ~MetaObjectList();
    122             template <class T>
    123             void add(ObjectList<T>* list, ObjectListElement<T>* element);
     81            void add(ObjectListBase* list, ObjectListBaseElement* element);
    12482
    125             BaseMetaObjectListElement* first_;      //!< The first element in the list
     83            MetaObjectListElement* first_;      //!< The first element in the list
    12684    };
    127 
    128     /**
    129         @brief Adds an ObjectList and an element of that list to the MetaObjectList.
    130         @param list The ObjectList wherein the element is
    131         @param element The element wherein the object is
    132     */
    133     template <class T>
    134     void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)
    135     {
    136         BaseMetaObjectListElement* temp = this->first_;
    137         this->first_ = new MetaObjectListElement<T>(list, element);
    138         this->first_->next_ = temp;
    139     }
    14085}
    14186
  • code/branches/core3/src/core/ObjectList.h

    r1543 r1574  
    3131    @brief Definition and implementation of the ObjectList class.
    3232
    33     The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class.
    34     Newly created objects are added through the RegisterObject-macro in its constructor.
     33    The ObjectList is a wrapper of an ObjectListBase of a given class.
    3534    Use Iterator<class> to iterate through all objects of the class.
    3635*/
     
    3938#define _ObjectList_H__
    4039
    41 #include <set>
    42 
    4340#include "CorePrereqs.h"
    4441
     42#include "Identifier.h"
    4543#include "Iterator.h"
    46 #include "Identifier.h"
    4744
    4845namespace orxonox
    4946{
    5047    // ###############################
    51     // ###    ObjectListElement    ###
    52     // ###############################
    53     //! The list-element of the ObjectList
    54     template <class T>
    55     class ObjectListElement
    56     {
    57         public:
    58             ObjectListElement(T* object);
    59 
    60             T* object_;                     //!< The object
    61             ObjectListElement* next_;       //!< The next element in the list
    62             ObjectListElement* prev_;       //!< The previous element in the list
    63     };
    64 
    65     /**
    66         @brief Constructor: Creates the list-element with an object.
    67         @param object The object to store
    68     */
    69     template <class T>
    70     ObjectListElement<T>::ObjectListElement(T* object)
    71     {
    72         this->object_ = object;
    73         this->next_ = 0;
    74         this->prev_ = 0;
    75     }
    76 
    77 
    78     // ###############################
    7948    // ###       ObjectList        ###
    8049    // ###############################
    81     //! The ObjectList contains all objects of a given class.
     50    //! The ObjectList contains all objects of the given class.
    8251    /**
    83         The ObjectList is used by Identifiers to store all objects of a given class.
     52        Wraps the ObjectListBase of the corresponding Identifier.
    8453        Use Iterator<class> to iterate through all objects in the list.
    8554    */
     
    8857    {
    8958        public:
    90             ObjectList();
    91             ~ObjectList();
     59            /** @brief Returns an Iterator to the first element in the list. @return The Iterator */
     60            inline static Iterator<T> begin()
     61                { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->begin()); }
    9262
    93             ObjectListElement<T>* add(T* object);
     63            /** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */
     64            inline static Iterator<T> end()
     65                { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->end()); }
    9466
    95             /** @brief Returns the first element in the list. @return The first element */
    96             inline static Iterator<T> start()
    97                 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->first_); }
     67            /** @brief Returns an Iterator to the last element in the list. @return The Iterator */
     68            inline static Iterator<T> rbegin()
     69                { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->rbegin()); }
    9870
    99             /** @brief Returns the first element in the list. @return The first element */
    100             inline static Iterator<T> begin()
    101                 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->first_); }
    102 
    103             /** @brief Returns the last element in the list. @return The last element */
    104             inline static Iterator<T> end()
    105                 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->last_); }
    106 
    107             inline void registerIterator(Iterator<T>* iterator)
    108                 { this->iterators_.insert(this->iterators_.end(), (void*)iterator); }
    109             inline void unregisterIterator(Iterator<T>* iterator)
    110                 { this->iterators_.erase((void*)iterator); }
    111             void notifyIterators(ObjectListElement<T>* element);
    112 
    113             ObjectListElement<T>* first_;       //!< The first element in the list
    114             ObjectListElement<T>* last_;        //!< The last element in the list
    115 
    116         private:
    117             std::set<void*> iterators_;  //!< A list of iterators pointing on an element in this list
     71            /** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */
     72            inline static Iterator<T> rend()
     73                { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->rend()); }
    11874    };
    119 
    120     /**
    121         @brief Constructor: Sets default values.
    122     */
    123     template <class T>
    124     ObjectList<T>::ObjectList()
    125     {
    126         this->first_ = 0;
    127         this->last_ = 0;
    128     }
    129 
    130     /**
    131         @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
    132     */
    133     template <class T>
    134     ObjectList<T>::~ObjectList()
    135     {
    136         ObjectListElement<T>* temp;
    137         while (this->first_)
    138         {
    139             temp = this->first_->next_;
    140             delete this->first_;
    141             this->first_ = temp;
    142         }
    143     }
    144 
    145     /**
    146         @brief Increases all Iterators that currently point on the given element (because it gets removed).
    147         @param element The element that gets removed
    148     */
    149     template <class T>
    150     void ObjectList<T>::notifyIterators(ObjectListElement<T>* element)
    151     {
    152         for (std::set<void*>::iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
    153             if ((*(*((Iterator<T>*)(*it)))) == element->object_)
    154                 ++(*((Iterator<T>*)(*it)));
    155     }
    156 
    157     /**
    158         @brief Adds a new object to the end of the list.
    159         @param object The object to add
    160         @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object
    161     */
    162     template <class T>
    163     ObjectListElement<T>* ObjectList<T>::add(T* object)
    164     {
    165         if (!this->last_)
    166         {
    167             // If the list is empty
    168             this->last_ = new ObjectListElement<T>(object);
    169             this->first_ = this->last_; // There's only one object in the list now
    170         }
    171         else
    172         {
    173             // If the list isn't empty
    174             ObjectListElement<T>* temp = this->last_;
    175             this->last_ = new ObjectListElement<T>(object);
    176             this->last_->prev_ = temp;
    177             temp->next_ = this->last_;
    178         }
    179 
    180         return this->last_;
    181     }
    18275}
    18376
  • code/branches/core3/src/core/OrxonoxClass.cc

    r1505 r1574  
    3939{
    4040    /** @brief Constructor: Sets the default values. */
    41     OrxonoxClass::OrxonoxClass() :
    42       identifier_(0),
    43       parents_(0)
     41    OrxonoxClass::OrxonoxClass()
    4442    {
     43        this->identifier_ = 0;
     44        this->parents_ = 0;
    4545        this->metaList_ = new MetaObjectList();
    4646
  • code/branches/core3/src/network/ConnectionManager.cc

    r1534 r1574  
    6464{
    6565  //boost::thread_group network_threads;
    66  
     66
    6767  ConnectionManager::ConnectionManager():receiverThread_(0){}
    6868  boost::recursive_mutex ConnectionManager::enet_mutex_;
    69  
     69
    7070  ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
    7171    quit=false;
     
    7474    head_ = head;
    7575  }
    76  
     76
    7777  ConnectionManager::ConnectionManager(ClientInformation *head, int port){
    7878    quit=false;
     
    115115    return packet;
    116116  }*/
    117  
     117
    118118  ENetEvent *ConnectionManager::getEvent(){
    119119    if(!buffer.isEmpty())
     
    251251    }
    252252  }
    253  
     253
    254254  //### added some bugfixes here, but we cannot test them because
    255255  //### the server crashes everytime because of some gamestates
     
    333333  }
    334334
    335  
    336  
     335
     336
    337337  bool ConnectionManager::removeShip(ClientInformation *client){
    338338    int id=client->getShipID();
    339339    orxonox::Iterator<orxonox::SpaceShip> it;
    340     for(it = orxonox::ObjectList<orxonox::SpaceShip>::start(); it; ++it){
     340    for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){
    341341      if(it->objectID!=id)
    342342        continue;
     
    345345    return true;
    346346  }
    347  
     347
    348348  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    349349    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
     
    353353      return false;
    354354  }
    355  
     355
    356356  void ConnectionManager::disconnectClient(ClientInformation *client){
    357357    {
     
    362362    removeShip(client);
    363363  }
    364  
     364
    365365  bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
    366366    ENetEvent event;
     
    369369    return buffer.push(&event);
    370370  }
    371  
    372  
     371
     372
    373373
    374374}
  • code/branches/core3/src/network/GameStateClient.cc

    r1534 r1574  
    151151    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    152152    // get the start of the Synchronisable list
    153     orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     153    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin();
    154154    syncData sync;
    155155    // loop as long as we have some data ;)
     
    236236    int offset=0, size=0;
    237237    // get total size of gamestate
    238     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     238    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    239239      if(!it->getBacksync())
    240240        continue;
     
    253253    memsize=size;
    254254    // go through all Synchronisables
    255     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     255    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    256256      if(!it->getBacksync())
    257257        continue;
  • code/branches/core3/src/network/GameStateManager.cc

    r1534 r1574  
    7070    return;
    7171  }
    72  
     72
    7373  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
    7474    if(!gs)
     
    8383    return;
    8484  }
    85  
     85
    8686  void GameStateManager::processGameStates(){
    8787    std::map<int, GameStateCompressed*>::iterator it;
     
    9393    gameStateQueue.clear();
    9494  }
    95  
    96  
     95
     96
    9797  /**
    9898   * this function is used to keep the memory usage low
    9999   * it tries to delete all the unused gamestates
    100    * 
    101    * 
     100   *
     101   *
    102102   */
    103103  void GameStateManager::cleanup(){
     
    155155    }
    156156  }
    157  
     157
    158158  bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){
    159159    GameState *ugs = decompress(gs);
     
    190190    int offset=0, size=0;
    191191    // get total size of gamestate
    192     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     192    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    193193      size+=it->getSize(); // size of the actual data of the synchronisable
    194194      size+=3*sizeof(int); // size of datasize, classID and objectID
     
    204204    memsize=size;
    205205    // go through all Synchronisables
    206     for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
     206    for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){
    207207      //get size of the synchronisable
    208208      tempsize=it->getSize();
     
    246246    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    247247    // get the start of the Synchronisable list
    248     orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
     248    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin();
    249249    syncData sync;
    250250    /*ClientInformation *client = head_->findClient(clientID);
     
    308308    return true;
    309309  }
    310  
    311  
     310
     311
    312312  //##### ADDED FOR TESTING PURPOSE #####
    313313  GameStateCompressed* GameStateManager::testCompress( GameState* g ) {
     
    405405    switch ( retval ) {
    406406      case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break;
    407       case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 
     407      case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl;
    408408      return NULL;
    409409      case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
     
    426426    return compressedGamestate;
    427427  }
    428  
     428
    429429  GameState *GameStateManager::decompress(GameStateCompressed *a) {
    430430    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     
    464464    return gamestate;
    465465  }
    466  
     466
    467467
    468468  void GameStateManager::ackGameState(int clientID, int gamestateID) {
     
    471471      return;
    472472    int curid = temp->getGamestateID();
    473    
     473
    474474    if(gamestateID == GAMESTATEID_INITIAL){
    475475      temp->setGameStateID(GAMESTATEID_INITIAL);
     
    481481    }
    482482    if(curid > gamestateID)
    483       // the network packets got messed up 
     483      // the network packets got messed up
    484484      return;
    485485    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
     
    512512    return true;
    513513  }
    514  
     514
    515515  bool GameStateManager::checkAccess(int clientID, int objectID){
    516516    // currently we only check, wheter the object is the clients spaceship
     
    518518    return true; // TODO: change this
    519519  }
    520  
     520
    521521  void GameStateManager::removeClient(ClientInformation* client){
    522522    if(!client)
  • code/branches/core3/src/network/Server.cc

    r1556 r1574  
    5757  #define MAX_FAILURES 20;
    5858  #define NETWORK_FREQUENCY 30
    59  
     59
    6060  Server *Server::instance_=0;
    61  
     61
    6262  Server *Server::createSingleton(){
    6363    if(!instance_)
     
    8080    return instance_;
    8181  }
    82  
     82
    8383  Server *Server::getSingleton(){
    8484    return instance_;
    8585  }
    86  
    87  
     86
     87
    8888  /**
    8989  * Constructor for default values (bindaddress is set to ENET_HOST_ANY
     
    9797    gamestates = new GameStateManager(clients);
    9898  }
    99  
     99
    100100  Server::Server(int port){
    101101    timeSinceLastUpdate_=0;
     
    217217        if(clients->findClient(&event->peer->address)){
    218218          clientID = clients->findClient(&event->peer->address)->getID();
    219           if( !elaborate(event->packet, clientID) ) 
     219          if( !elaborate(event->packet, clientID) )
    220220            COUT(3) << "Server: could not elaborate" << std::endl;
    221221        }
     
    276276        continue;
    277277      if ( !(connection->addPacket(packet, cid)) ){
    278         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 
     278        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
    279279        temp->addFailure();
    280280        /*if(temp->getFailures() > 0 )
     
    302302    delete data;
    303303  }
    304  
     304
    305305  bool Server::processConnectRequest( connectRequest *con, int clientID ){
    306306    //(COUT(3) << "processing connectRequest " << std::endl;
     
    310310    return true;
    311311  }
    312  
     312
    313313  void Server::processGamestate( GameStateCompressed *data, int clientID){
    314314    COUT(4) << "processing partial gamestate from client " << clientID << std::endl;
     
    319319        clients->findClient(clientID)->resetFailures();*/
    320320  }
    321  
     321
    322322  void Server::processChat( chat *data, int clientId){
    323323    char *message = new char [strlen(data->message)+10+1];
     
    329329    delete data;
    330330  }
    331  
     331
    332332  bool Server::addClient(ENetEvent *event){
    333333    ClientInformation *temp = clients->insertBack(new ClientInformation);
     
    346346    return createClient(temp->getID());
    347347  }
    348  
     348
    349349  bool Server::createClient(int clientID){
    350350    ClientInformation *temp = clients->findClient(clientID);
     
    366366    return true;
    367367  }
    368  
     368
    369369  bool Server::createShip(ClientInformation *client){
    370370    if(!client)
     
    390390    no->classID = id->getNetworkID();
    391391    no->create();
    392    
     392
    393393    client->setShipID(no->objectID);
    394394    return true;
    395395  }
    396  
     396
    397397  bool Server::disconnectClient(ENetEvent *event){
    398398    COUT(4) << "removing client from list" << std::endl;
    399399    //return removeClient(head_->findClient(&(peer->address))->getID());
    400    
     400
    401401    //boost::recursive_mutex::scoped_lock lock(head_->mutex_);
    402     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     402    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::begin();
    403403    ClientInformation *client = clients->findClient(&event->peer->address);
    404404    if(!client)
     
    426426    gamestates->removeClient(client);
    427427  }
    428  
     428
    429429}
  • code/branches/core3/src/orxonox/Orxonox.cc

    r1567 r1574  
    462462      Core::tick((float)evt.timeSinceLastFrame);
    463463      // Call those objects that need the real time
    464       for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)
     464      for (Iterator<TickableReal> it = ObjectList<TickableReal>::begin(); it; ++it)
    465465        it->tick((float)evt.timeSinceLastFrame);
    466466      // Call the scene objects
    467       for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it)
     467      for (Iterator<Tickable> it = ObjectList<Tickable>::begin(); it; ++it)
    468468        it->tick((float)evt.timeSinceLastFrame * this->timefactor_);
    469469      //AudioManager::tick();
  • code/branches/core3/src/orxonox/objects/NPC.cc

    r1505 r1574  
    6161    movable_ = movable;
    6262  }
    63  
     63
    6464  void NPC::registerAllVariables(){
    6565    Model::registerAllVariables();
    6666    registerVar(&movable_, sizeof(movable_), network::DATA);
    6767  }
    68  
     68
    6969
    7070  /**
     
    117117    int numberOfNeighbour = 0;  //number of observed neighbours
    118118    float distance = 0;  // distance to the actual element
    119     for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::start(); it; ++it) {  //go through all elements
     119    for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it) {  //go through all elements
    120120      distance = getDistance(*it);  //get distance between this and actual
    121121      if ((distance > 0) && (distance < SEPERATIONDISTANCE)) {  //do only if actual is inside detectionradius
     
    144144    //float distance = 0;
    145145    //go through all elements
    146     for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) {  //just working with 3 elements at the moment
     146    for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
    147147      float distance = getDistance(*it);  //get distance between this and actual
    148148      if ((distance > 0) && (distance < ALIGNMENTDISTANCE)) {  //check if actual element is inside detectionradius
     
    164164    //float distance = 0;
    165165    //go through all elements
    166     for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it) {  //just working with 3 elements at the moment
     166    for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) {  //just working with 3 elements at the moment
    167167      float distance = getDistance(*it);  //get distance between this and actual
    168168      if ((distance > 0) && (distance < COHESIONDISTANCE)) {  //check if actual element is inside detectionradius
  • code/branches/core3/src/orxonox/objects/Projectile.cc

    r1563 r1574  
    8686
    8787        float radius;
    88         for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it)
     88        for (Iterator<Model> it = ObjectList<Model>::begin(); it; ++it)
    8989        {
    9090            if ((*it) != this->owner_)
  • code/branches/core3/src/orxonox/objects/SpaceShip.cc

    r1564 r1574  
    7272    SpaceShip *SpaceShip::getLocalShip(){
    7373      Iterator<SpaceShip> it;
    74       for(it = ObjectList<SpaceShip>::start(); it; ++it){
     74      for(it = ObjectList<SpaceShip>::begin(); it; ++it){
    7575        if( (it)->myShip_ )
    7676          return *it;
Note: See TracChangeset for help on using the changeset viewer.