Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File:
1 edited

Legend:

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

    r1024 r1052  
    5252#define _Identifier_H__
    5353
    54 #include <list>
     54#include <set>
    5555#include <map>
    5656#include <string>
     
    6262#include "Debug.h"
    6363#include "Iterator.h"
     64#include "util/String.h"
    6465
    6566namespace orxonox
     
    105106            bool isDirectParentOf(const Identifier* identifier) const;
    106107
    107             /** @brief Removes all objects of the corresponding class. */
    108             virtual void removeObjects() const = 0;
     108            virtual const ObjectList<BaseObject>* getObjectList() const = 0;
     109
     110            virtual void updateConfigValues() const = 0;
    109111
    110112            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    111113            inline const std::string& getName() const { return this->name_; }
    112114
     115
    113116            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    114             inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
     117            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
    115118            /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
    116             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(); }
    117120            /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
    118             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(); }
    119122
    120123            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    121             inline const std::list<const Identifier*>& getChildren() const { return (*this->children_); }
     124            inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }
    122125            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
    123             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(); }
    124127            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
    125             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(); }
    126129
    127130            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
    128             inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
     131            inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
    129132            /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
    130             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(); }
    131134            /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
    132             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(); }
    133136
    134137            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
    135             inline const std::list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
     138            inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
    136139            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
    137             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(); }
    138141            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
    139             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(); }
     143
     144
     145            /** @brief Returns the map that stores all Identifiers. @return The map */
     146            static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
     147            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
     148            static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
     149            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
     150            static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
     151
     152            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
     153            static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
     154            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
     155            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
     156            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
     157            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
     158
     159
     160            /** @brief Returns the map that stores all config values. @return The const_iterator */
     161            inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
     162            /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
     163            inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); }
     164            /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */
     165            inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); }
     166
     167            /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */
     168            inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; }
     169            /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */
     170            inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); }
     171            /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */
     172            inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
     173
     174
     175            /** @brief Returns the map that stores all console commands. @return The const_iterator */
     176            inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }
     177            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
     178            inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
     179            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
     180            inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
     181
     182            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
     183            inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
     184            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */
     185            inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
     186            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
     187            inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
     188
     189
     190            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
     191            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
     192            /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
     193            inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
    140194
    141195            /** @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 */
     
    148202            void setNetworkID(unsigned int id);
    149203
     204            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    150205            ConfigValueContainer* getConfigValueContainer(const std::string& varname);
    151             void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    152 
     206            ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
     207
     208            virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    153209            virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;
    154             virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    155 
     210
     211            virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    156212            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
    157             virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    158 
    159             static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
     213
     214            ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);
     215            ExecutorStatic* getConsoleCommand(const std::string& name) const;
     216            ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;
     217
     218        protected:
     219            /** @brief Returns the map that stores all Identifiers. @return The map */
     220            static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     221            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
     222            static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
    160223
    161224        private:
     
    163226            Identifier(const Identifier& identifier) {} // don't copy
    164227            virtual ~Identifier();
    165             void initialize(std::list<const Identifier*>* parents);
     228            void initialize(std::set<const Identifier*>* parents);
    166229
    167230            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    168             inline std::list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     231            inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
    169232            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
    170             inline std::list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
     233            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    171234
    172235            /**
     
    188251            }
    189252
    190             std::list<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
    191             std::list<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
    192 
    193             std::list<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
    194             std::list<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
    195 
    196             std::string name_;                                          //!< The name of the class the Identifier belongs to
    197 
    198             BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class (if available)
    199             bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    200             static int hierarchyCreatingCounter_s;                      //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
    201             unsigned int classID_;                                      //!< The network ID to identify a class through the network
    202             std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
     253            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     254            std::set<const Identifier*>* children_;                        //!< The children of the class the Identifier belongs to
     255
     256            std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
     257            std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
     258
     259            std::string name_;                                             //!< The name of the class the Identifier belongs to
     260
     261            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
     262            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     263            static int hierarchyCreatingCounter_s;                         //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
     264            unsigned int classID_;                                         //!< The network ID to identify a class through the network
     265
     266            bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
     267            std::map<std::string, ConfigValueContainer*> configValues_;    //!< A map to link the string of configurable variables with their ConfigValueContainer
     268            std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer
     269
     270            bool bHasConsoleCommands_;                                     //!< True if this class has at least one assigned console command
     271            std::map<std::string, ExecutorStatic*> consoleCommands_;       //!< All console commands of this class
     272            std::map<std::string, ExecutorStatic*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
    203273    };
    204274
    205     _CoreExport std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);
     275    _CoreExport std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list);
    206276
    207277
     
    228298
    229299        public:
    230             ClassIdentifier<T>* registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass);
     300            ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass);
    231301            void addObject(T* object);
    232             void removeObjects() const;
    233302            void setName(const std::string& name);
     303            /** @brief Returns the list of all existing objects of this class. @return The list */
    234304            inline const ObjectList<T>* getObjects() const { return this->objects_; }
     305            /** @brief Returns a list of all existing objects of this class. @return The list */
     306            inline const ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; }
     307
     308            void updateConfigValues() const;
    235309
    236310            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
     
    245319            ~ClassIdentifier() {}                                       // don't delete
    246320
    247             ObjectList<T>* objects_;    //!< The ObjectList, containing all objects of type T
    248             bool bSetName_;             //!< True if the name is set
    249             std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;
    250             std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;
     321            ObjectList<T>* objects_;                                                                    //!< The ObjectList, containing all objects of type T
     322            bool bSetName_;                                                                             //!< True if the name is set
     323            std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;              //!< All loadable parameters
     324            std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;   //!< All attachable objects
    251325    };
    252326
     
    270344    */
    271345    template <class T>
    272     ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass)
    273     {
    274         COUT(5) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;
     346    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass)
     347    {
     348        this->setName(name);
    275349
    276350        // Check if at least one object of the given type was created
    277         if (!this->bCreatedOneObject_)
     351        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    278352        {
    279353            // If no: We have to store the informations and initialize the Identifier
    280             this->setName(name);
    281 
    282354            COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
    283355            if (bRootClass)
     
    301373            this->name_ = name;
    302374            this->bSetName_ = true;
     375            Identifier::getIdentifierMapIntern()[name] = this;
     376            Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
    303377        }
    304378    }
     
    316390
    317391    /**
    318         @brief Removes all objects of the corresponding class.
    319     */
    320     template <class T>
    321     void ClassIdentifier<T>::removeObjects() const
    322     {
    323         for (Iterator<T> it = this->objects_->start(); it;)
    324             delete *(it++);
    325     }
    326 
     392        @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
     393    */
     394    template <class T>
     395    void ClassIdentifier<T>::updateConfigValues() const
     396    {
     397        for (Iterator<T> it = this->objects_->start(); it; ++it)
     398            ((T*)*it)->setConfigValues();
     399    }
     400
     401    /**
     402        @brief Returns a XMLPortParamContainer that loads a parameter of this class.
     403        @param paramname The name of the parameter
     404        @return The container
     405    */
    327406    template <class T>
    328407    XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
     
    335414    }
    336415
     416    /**
     417        @brief Adds a new XMLPortParamContainer that loads a parameter of this class.
     418        @param paramname The name of the parameter
     419        @param container The container
     420    */
    337421    template <class T>
    338422    void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
     
    341425    }
    342426
     427    /**
     428        @brief Returns a XMLPortObjectContainer that attaches an object to this class.
     429        @param sectionname The name of the section that contains the attachable objects
     430        @return The container
     431    */
    343432    template <class T>
    344433    XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
     
    351440    }
    352441
     442    /**
     443        @brief Adds a new XMLPortObjectContainer that attaches an object to this class.
     444        @param sectionname The name of the section that contains the attachable objects
     445        @param container The container
     446    */
    353447    template <class T>
    354448    void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
Note: See TracChangeset for help on using the changeset viewer.