Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 10, 2008, 12:27:30 AM (16 years ago)
Author:
landauf
Message:

std::set instead of std::list for Identifier-lists (parents, children, …) for faster accessing by key ( std::set::find(xyz) )

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/Identifier.h

    r871 r876  
    5252#define _Identifier_H__
    5353
    54 #include <list>
     54#include <set>
    5555#include <map>
    5656#include <string>
     
    115115
    116116            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    117             inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
     117            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
    118118            /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
    119             inline std::list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
     119            inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
    120120            /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
    121             inline std::list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
     121            inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
    122122
    123123            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    124             inline const std::list<const Identifier*>& getChildren() const { return (*this->children_); }
     124            inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }
    125125            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
    126             inline std::list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
     126            inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
    127127            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
    128             inline std::list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
     128            inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
    129129
    130130            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
    131             inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
     131            inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
    132132            /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
    133             inline std::list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
     133            inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
    134134            /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
    135             inline std::list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
     135            inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
    136136
    137137            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
    138             inline const std::list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
     138            inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
    139139            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
    140             inline std::list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
     140            inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
    141141            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
    142             inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
     142            inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
    143143
    144144            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
     
    159159            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
    160160            virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    161 
    162             static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
    163161
    164162        private:
     
    166164            Identifier(const Identifier& identifier) {} // don't copy
    167165            virtual ~Identifier();
    168             void initialize(std::list<const Identifier*>* parents);
     166            void initialize(std::set<const Identifier*>* parents);
    169167
    170168            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    171             inline std::list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     169            inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
    172170            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
    173             inline std::list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
     171            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    174172
    175173            /**
     
    191189            }
    192190
    193             std::list<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
    194             std::list<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
    195 
    196             std::list<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
    197             std::list<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
     191            std::set<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
     192            std::set<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
     193
     194            std::set<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
     195            std::set<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
    198196
    199197            std::string name_;                                          //!< The name of the class the Identifier belongs to
     
    206204    };
    207205
    208     std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);
     206    std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list);
    209207
    210208
     
    231229
    232230        public:
    233             ClassIdentifier<T>* registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass);
     231            ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass);
    234232            void addObject(T* object);
    235233            void removeObjects() const;
     
    273271    */
    274272    template <class T>
    275     ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass)
     273    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass)
    276274    {
    277275        COUT(5) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;
Note: See TracChangeset for help on using the changeset viewer.