Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.