Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 28, 2008, 10:13:58 PM (16 years ago)
Author:
landauf
Message:
  • added CommandExecutor
  • added ConsoleCommand macros
  • added getTypename to all MultiTypes
  • added 2 static maps to Identifier that contain all existing Identifiers with their names and lowercase names respectively.
  • added 2 maps to each Identifier that contain all console commands of the Identifier with their names and lowercase names respectively
  • using tolower(.) and toupper(.) instead of selfmade hacks in String.h
  • added AccessLevel enum
  • added some test-console-commands to OutputHandler, Ambient and SpaceShip
File:
1 edited

Legend:

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

    r941 r947  
    6262#include "Debug.h"
    6363#include "Iterator.h"
     64#include "util/String.h"
    6465
    6566namespace orxonox
     
    114115            inline const std::string& getName() const { return this->name_; }
    115116
     117
    116118            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
    117119            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
     
    142144            inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
    143145
     146
     147            /** @brief Returns the map that stores all Identifiers. @return The map */
     148            static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); }
     149            /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */
     150            static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); }
     151            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */
     152            static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); }
     153
     154            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
     155            static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }
     156            /** @brief Returns a const_iterator to the beginning 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 getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }
     158            /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */
     159            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); }
     160
     161
     162            /** @brief Returns the map that stores all config values. @return The const_iterator */
     163            inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
     164            /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
     165            inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); }
     166            /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */
     167            inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); }
     168
     169            /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */
     170            inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; }
     171            /** @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 */
     172            inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); }
     173            /** @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 */
     174            inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
     175
     176
     177            /** @brief Returns the map that stores all console commands. @return The const_iterator */
     178            inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; }
     179            /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */
     180            inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); }
     181            /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */
     182            inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); }
     183
     184            /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */
     185            inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; }
     186            /** @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 */
     187            inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); }
     188            /** @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 */
     189            inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
     190
     191
     192            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
     193            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
     194            /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */
     195            inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }
     196
    144197            /** @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 */
    145198            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
     
    151204            void setNetworkID(unsigned int id);
    152205
     206            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    153207            ConfigValueContainer* getConfigValueContainer(const std::string& varname);
    154             void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    155 
     208            ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
     209
     210            virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    156211            virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;
    157             virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    158 
     212
     213            virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    159214            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
    160             virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
     215
     216            ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut);
     217            ExecutorStatic* getConsoleCommand(const std::string& name) const;
     218            ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const;
     219
     220        protected:
     221            /** @brief Returns the map that stores all Identifiers. @return The map */
     222            static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     223            /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */
     224            static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
    161225
    162226        private:
     
    189253            }
    190254
    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
    196 
    197             std::string name_;                                          //!< The name of the class the Identifier belongs to
    198 
    199             BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class (if available)
    200             bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    201             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)
    202             unsigned int classID_;                                      //!< The network ID to identify a class through the network
    203             std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
     255            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     256            std::set<const Identifier*>* children_;                        //!< The children of the class the Identifier belongs to
     257
     258            std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
     259            std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
     260
     261            std::string name_;                                             //!< The name of the class the Identifier belongs to
     262
     263            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
     264            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     265            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)
     266            unsigned int classID_;                                         //!< The network ID to identify a class through the network
     267
     268            bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
     269            std::map<std::string, ConfigValueContainer*> configValues_;    //!< A map to link the string of configurable variables with their ConfigValueContainer
     270            std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer
     271
     272            bool bHasConsoleCommands_;                                     //!< True if this class has at least one assigned console command
     273            std::map<std::string, ExecutorStatic*> consoleCommands_;       //!< All console commands of this class
     274            std::map<std::string, ExecutorStatic*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
    204275    };
    205276
     
    246317            ~ClassIdentifier() {}                                       // don't delete
    247318
    248             ObjectList<T>* objects_;    //!< The ObjectList, containing all objects of type T
    249             bool bSetName_;             //!< True if the name is set
    250             std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;
    251             std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;
     319            ObjectList<T>* objects_;                                                                    //!< The ObjectList, containing all objects of type T
     320            bool bSetName_;                                                                             //!< True if the name is set
     321            std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;              //!< All loadable parameters
     322            std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;   //!< All attachable objects
    252323    };
    253324
     
    300371            this->name_ = name;
    301372            this->bSetName_ = true;
     373            Identifier::getIdentifierMapIntern()[name] = this;
     374            Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
    302375        }
    303376    }
     
    324397    }
    325398
     399    /**
     400        @brief Returns a XMLPortParamContainer that loads a parameter of this class.
     401        @param paramname The name of the parameter
     402        @return The container
     403    */
    326404    template <class T>
    327405    XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
     
    334412    }
    335413
     414    /**
     415        @brief Adds a new XMLPortParamContainer that loads a parameter of this class.
     416        @param paramname The name of the parameter
     417        @param container The container
     418    */
    336419    template <class T>
    337420    void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
     
    340423    }
    341424
     425    /**
     426        @brief Returns a XMLPortObjectContainer that attaches an object to this class.
     427        @param sectionname The name of the section that contains the attachable objects
     428        @return The container
     429    */
    342430    template <class T>
    343431    XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
     
    350438    }
    351439
     440    /**
     441        @brief Adds a new XMLPortObjectContainer that attaches an object to this class.
     442        @param sectionname The name of the section that contains the attachable objects
     443        @param container The container
     444    */
    352445    template <class T>
    353446    void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
Note: See TracChangeset for help on using the changeset viewer.