Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1856 for code/trunk/src/core


Ignore:
Timestamp:
Sep 29, 2008, 4:15:03 AM (16 years ago)
Author:
landauf
Message:
  • some small adjustments in identifier and co.
  • renamed GetIdentifier to ClassByName and ClassByID
Location:
code/trunk/src/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/CoreIncludes.h

    r1789 r1856  
    9494
    9595/**
     96    @brief Creates the entry in the Factory.
     97    @param ClassName The name of the class
     98*/
     99#define CreateFactory(ClassName) \
     100    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
     101
     102/**
    96103    @brief Returns the Identifier of the given class.
    97104    @param ClassName The name of the class
     
    101108
    102109/**
    103     @brief Creates the entry in the Factory.
    104     @param ClassName The name of the class
     110    @brief Returns the Identifier with a given name through the factory.
     111    @param String The name of the class
    105112*/
    106 #define CreateFactory(ClassName) \
    107     bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
     113#define ClassByName(String) \
     114    orxonox::Factory::getIdentifier(String)
    108115
    109116/**
    110     @brief Returns the Identifier with either a given name or a given network ID through the factory.
    111     @param StringOrInt The name or the network ID of the class
     117    @brief Returns the Identifier with a given network ID through the factory.
     118    @param networkID The network ID of the class
    112119*/
    113 #define GetIdentifier(StringOrInt) \
    114     orxonox::Factory::getIdentifier(StringOrInt)
     120#define ClassByID(networkID) \
     121    orxonox::Factory::getIdentifier(networkID)
    115122
    116123#endif /* _CoreIncludes_H__ */
  • code/trunk/src/core/Factory.cc

    r1747 r1856  
    110110      return &theOneAndOnlyFactoryInstance;
    111111    }
    112 
    113     /**
    114         @brief Returns the begin-iterator of the factory-map.
    115         @return The begin-iterator
    116     */
    117     std::map<std::string, Identifier*>::const_iterator Factory::getFactoryBegin()
    118     {
    119         return Factory::getFactoryPointer()->identifierStringMap_.begin();
    120     }
    121 
    122     /**
    123         @brief Returns the end-iterator of the factory-map.
    124         @return The end-iterator
    125     */
    126     std::map<std::string, Identifier*>::const_iterator Factory::getFactoryEnd()
    127     {
    128         return Factory::getFactoryPointer()->identifierStringMap_.end();
    129     }
    130112}
  • code/trunk/src/core/Factory.h

    r1505 r1856  
    6666
    6767            static Factory* getFactoryPointer();    // avoid overriding order problem in the static intialisation process
    68             static std::map<std::string, Identifier*>::const_iterator getFactoryBegin();
    69             static std::map<std::string, Identifier*>::const_iterator getFactoryEnd();
     68
     69            /** @brief Returns the factory-map. */
     70            static const std::map<std::string, Identifier*>& getFacbtoryMap()
     71                { return Factory::getFactoryPointer()->identifierStringMap_; }
     72            /** @brief Returns the begin-iterator of the factory-map. */
     73            static std::map<std::string, Identifier*>::const_iterator getFactoryMapBegin()
     74                { return Factory::getFactoryPointer()->identifierStringMap_.begin(); }
     75            /** @brief Returns the end-iterator of the factory-map. */
     76            static std::map<std::string, Identifier*>::const_iterator getFactoryMapEnd()
     77                { return Factory::getFactoryPointer()->identifierStringMap_.end(); }
    7078
    7179        private:
  • code/trunk/src/core/Identifier.cc

    r1747 r1856  
    115115            identifiers[name] = proposal;
    116116            return proposal;
     117        }
     118    }
     119
     120    /**
     121        @brief Registers a class, which means that the name and the parents get stored.
     122        @param parents A list, containing the Identifiers of all parents of the class
     123        @param bRootClass True if the class is either an Interface or the BaseObject itself
     124    */
     125    void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
     126    {
     127        // Check if at least one object of the given type was created
     128        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
     129        {
     130            // If no: We have to store the informations and initialize the Identifier
     131            COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
     132            if (bRootClass)
     133                this->initialize(0); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
     134            else
     135                this->initialize(parents);
    117136        }
    118137    }
  • code/trunk/src/core/Identifier.h

    r1755 r1856  
    190190            inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); }
    191191
     192            /** @brief Returns the map that stores all XMLPort params. @return The const_iterator */
     193            inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; }
     194            /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort params. @return The const_iterator */
     195            inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); }
     196            /** @brief Returns a const_iterator to the end of the map that stores all XMLPort params. @return The const_iterator */
     197            inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); }
     198
     199            /** @brief Returns the map that stores all XMLPort objects. @return The const_iterator */
     200            inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; }
     201            /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort objects. @return The const_iterator */
     202            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); }
     203            /** @brief Returns a const_iterator to the end of the map that stores all XMLPort objects. @return The const_iterator */
     204            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    192205
    193206            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
     
    219232            ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;
    220233
     234            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     235
    221236        protected:
    222237            Identifier();
     
    224239            virtual ~Identifier();
    225240
    226             void initialize(std::set<const Identifier*>* parents);
    227241            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    228 
    229242            virtual void createSuperFunctionCaller() const = 0;
    230243
     
    239252            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    240253
    241             bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    242254            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    243255
     
    261273            }
    262274
     275            void initialize(std::set<const Identifier*>* parents);
     276
    263277            static void destroyAllIdentifiers();
    264278
     
    269283            std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
    270284
     285            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    271286            bool bSetName_;                                                //!< True if the name is set
    272287            std::string name_;                                             //!< The name of the class the Identifier belongs to
     
    311326            static ClassIdentifier<T> *getIdentifier();
    312327            static ClassIdentifier<T> *getIdentifier(const std::string& name);
    313             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     328            void addObject(T* object);
    314329            static bool isFirstCall();
    315             void addObject(T* object);
    316330
    317331            void updateConfigValues(bool updateChildren = true) const;
     
    328342            }
    329343
    330             static ClassIdentifier<T> *classIdentifier_s;
     344            static ClassIdentifier<T>* classIdentifier_s;
    331345    };
    332346
    333347    template <class T>
    334     ClassIdentifier<T> *ClassIdentifier<T>::classIdentifier_s = 0;
    335 
    336     /**
    337         @brief Registers a class, which means that the name and the parents get stored.
    338         @param parents A list, containing the Identifiers of all parents of the class
    339         @param bRootClass True if the class is either an Interface or the BaseObject itself
    340     */
    341     template <class T>
    342     void ClassIdentifier<T>::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
    343     {
    344         // Check if at least one object of the given type was created
    345         if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    346         {
    347             // If no: We have to store the informations and initialize the Identifier
    348             COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
    349             if (bRootClass)
    350                 this->initialize(0); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
    351             else
    352                 this->initialize(parents);
    353         }
    354     }
     348    ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s;
    355349
    356350    /**
     
    476470            SubclassIdentifier(Identifier* identifier)
    477471            {
    478                 this->identifier_ = identifier;
     472                this->operator=(identifier);
    479473            }
    480474
     
    500494            /**
    501495                @brief Overloading of the * operator: returns the assigned identifier.
    502                 @return The assigned identifier
    503             */
    504             Identifier* operator*()
     496            */
     497            inline Identifier* operator*()
    505498            {
    506499                return this->identifier_;
     
    509502            /**
    510503                @brief Overloading of the -> operator: returns the assigned identifier.
    511                 @return The assigned identifier
    512             */
    513             Identifier* operator->() const
     504            */
     505            inline Identifier* operator->() const
     506            {
     507                return this->identifier_;
     508            }
     509
     510            /**
     511                @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.
     512            */
     513            inline operator Identifier*() const
    514514            {
    515515                return this->identifier_;
     
    527527                if (newObject)
    528528                {
    529                     // Do a dynamic_cast, because an object of type T is much better than of type BaseObject
    530                     return (T*)(newObject);
     529                    return dynamic_cast<T*>(newObject);
    531530                }
    532531                else
     
    552551
    553552            /** @brief Returns the assigned identifier. @return The identifier */
    554             inline const Identifier* getIdentifier() const
     553            inline Identifier* getIdentifier() const
    555554                { return this->identifier_; }
    556555
    557             /** @brief Returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */
    558             inline bool isA(const Identifier* identifier) const
    559                 { return this->identifier_->isA(identifier); }
    560 
    561             /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
    562             inline bool isExactlyA(const Identifier* identifier) const
    563                 { return this->identifier_->isExactlyA(identifier); }
    564 
    565             /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
    566             inline bool isChildOf(const Identifier* identifier) const
    567                 { return this->identifier_->isChildOf(identifier); }
    568 
    569             /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */
    570             inline bool isDirectChildOf(const Identifier* identifier) const
    571                 { return this->identifier_->isDirectChildOf(identifier); }
    572 
    573             /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
    574             inline bool isParentOf(const Identifier* identifier) const
    575                 { return this->identifier_->isParentOf(identifier); }
    576 
    577             /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */
    578             inline bool isDirectParentOf(const Identifier* identifier) const
    579                 { return this->identifier_->isDirectParentOf(identifier); }
     556//            /** @brief Returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */
     557//            inline bool isA(const Identifier* identifier) const
     558//                { return this->identifier_->isA(identifier); }
     559//
     560//            /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
     561//            inline bool isExactlyA(const Identifier* identifier) const
     562//                { return this->identifier_->isExactlyA(identifier); }
     563//
     564//            /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
     565//            inline bool isChildOf(const Identifier* identifier) const
     566//                { return this->identifier_->isChildOf(identifier); }
     567//
     568//            /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */
     569//            inline bool isDirectChildOf(const Identifier* identifier) const
     570//                { return this->identifier_->isDirectChildOf(identifier); }
     571//
     572//            /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
     573//            inline bool isParentOf(const Identifier* identifier) const
     574//                { return this->identifier_->isParentOf(identifier); }
     575//
     576//            /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */
     577//            inline bool isDirectParentOf(const Identifier* identifier) const
     578//                { return this->identifier_->isDirectParentOf(identifier); }
    580579
    581580        private:
  • code/trunk/src/core/XMLPort.h

    r1854 r1856  
    468468                            for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
    469469                            {
    470                                 Identifier* identifier = GetIdentifier(child->Value());
     470                                Identifier* identifier = ClassByName(child->Value());
    471471                                if (identifier)
    472472                                {
Note: See TracChangeset for help on using the changeset viewer.