Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 9, 2008, 4:25:52 AM (16 years ago)
Author:
landauf
Message:

merged core3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/Identifier.h

    r1639 r1747  
    6262#include <stdlib.h>
    6363
    64 #include "ObjectList.h"
    65 #include "Debug.h"
     64#include "MetaObjectList.h"
    6665#include "Iterator.h"
    67 #include "MetaObjectList.h"
     66#include "Super.h"
     67#include "util/Debug.h"
    6868#include "util/String.h"
    6969
     
    9191    {
    9292        template <class T>
    93         friend class ClassIdentifier;
    94 
    95         template <class T>
    9693        friend class SubclassIdentifier;
    9794
     
    110107            bool isDirectParentOf(const Identifier* identifier) const;
    111108
    112             virtual const ObjectList<BaseObject>* getObjectList() const = 0;
    113 
    114             virtual void updateConfigValues() const = 0;
     109            /** @brief Returns the list of all existing objects of this class. @return The list */
     110            inline ObjectListBase* getObjects() const
     111                { return this->objects_; }
    115112
    116113            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    117114            inline const std::string& getName() const { return this->name_; }
    118 
     115            void setName(const std::string& name);
     116
     117            virtual void updateConfigValues(bool updateChildren = true) const = 0;
    119118
    120119            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
     
    210209            ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
    211210
    212             virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
    213             virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;
    214 
    215             virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
    216             virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
     211            void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
     212            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
     213
     214            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
     215            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    217216
    218217            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
     
    221220
    222221        protected:
     222            Identifier();
     223            Identifier(const Identifier& identifier); // don't copy
     224            virtual ~Identifier();
     225
     226            void initialize(std::set<const Identifier*>* parents);
     227            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
     228
     229            virtual void createSuperFunctionCaller() const = 0;
     230
    223231            /** @brief Returns the map that stores all Identifiers. @return The map */
    224232            static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     
    226234            static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
    227235
    228         private:
    229             Identifier();
    230             Identifier(const Identifier& identifier); // don't copy
    231             virtual ~Identifier();
    232             void initialize(std::set<const Identifier*>* parents);
    233 
    234236            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    235237            inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     
    237239            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
    238240
     241            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     242            ObjectListBase* objects_;                                      //!< The list of all objects of this class
     243
     244        private:
    239245            /**
    240246                @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
     
    255261            }
    256262
    257             static Identifier* getIdentifier(std::string &name, Identifier *proposal);
     263            static void destroyAllIdentifiers();
    258264
    259265            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     
    263269            std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
    264270
     271            bool bSetName_;                                                //!< True if the name is set
    265272            std::string name_;                                             //!< The name of the class the Identifier belongs to
    266 
    267273            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
    268             bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    269274            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)
    270275            unsigned int classID_;                                         //!< The network ID to identify a class through the network
     
    277282            std::map<std::string, ConsoleCommand*> consoleCommands_;       //!< All console commands of this class
    278283            std::map<std::string, ConsoleCommand*> consoleCommands_LC_;    //!< All console commands of this class with their names in lowercase
     284
     285            std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_;     //!< All loadable parameters
     286            std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_;   //!< All attachable objects
    279287    };
    280288
     
    297305    class ClassIdentifier : public Identifier
    298306    {
     307        #define SUPER_INTRUSIVE_DECLARATION_INCLUDE
     308        #include "Super.h"
     309
    299310        public:
    300             ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass);
     311            static ClassIdentifier<T> *getIdentifier();
     312            static ClassIdentifier<T> *getIdentifier(const std::string& name);
     313            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     314            static bool isFirstCall();
    301315            void addObject(T* object);
    302             void setName(const std::string& name);
    303             /** @brief Returns the list of all existing objects of this class. @return The list */
    304             inline ObjectList<T>* getObjects() const { return this->objects_; }
    305             /** @brief Returns a list of all existing objects of this class. @return The list */
    306             inline ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; }
    307 
    308             void updateConfigValues() const;
    309 
    310             XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
    311             void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
    312 
    313             XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    314             void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
    315 
    316             static ClassIdentifier<T> *getIdentifier();
     316
     317            void updateConfigValues(bool updateChildren = true) const;
    317318
    318319        private:
    319             ClassIdentifier();
    320320            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    321             ~ClassIdentifier() {}                                       // don't delete
    322 
    323             ObjectList<T>* objects_;                                                                    //!< The ObjectList, containing all objects of type T
    324             bool bSetName_;                                                                             //!< True if the name is set
    325             std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;              //!< All loadable parameters
    326             std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;   //!< All attachable objects
     321            ClassIdentifier()
     322            {
     323                SuperFunctionInitialization<0, T>::initialize(this);
     324            }
     325            ~ClassIdentifier()
     326            {
     327                SuperFunctionDestruction<0, T>::destroy(this);
     328            }
    327329
    328330            static ClassIdentifier<T> *classIdentifier_s;
     
    333335
    334336    /**
    335         @brief Constructor: Creates the ObjectList.
    336     */
    337     template <class T>
    338     ClassIdentifier<T>::ClassIdentifier()
    339     {
    340 //        this->objects_ = ObjectList<T>::getList();
    341         this->objects_ = new ObjectList<T>();
    342         this->bSetName_ = false;
    343     }
    344 
    345     /**
    346337        @brief Registers a class, which means that the name and the parents get stored.
    347338        @param parents A list, containing the Identifiers of all parents of the class
    348         @param name A string, containing exactly the name of the class
    349339        @param bRootClass True if the class is either an Interface or the BaseObject itself
    350         @return The ClassIdentifier itself
    351     */
    352     template <class T>
    353     ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass)
    354     {
    355         this->setName(name);
    356 
     340    */
     341    template <class T>
     342    void ClassIdentifier<T>::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
     343    {
    357344        // Check if at least one object of the given type was created
    358345        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    359346        {
    360347            // If no: We have to store the informations and initialize the Identifier
    361             COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
     348            COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
    362349            if (bRootClass)
    363                 this->initialize(NULL); // 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.
     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.
    364351            else
    365352                this->initialize(parents);
    366353        }
    367 
    368         return this;
    369354    }
    370355
    371356    /**
    372         @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier for the given name.
     357        @brief Returns true if the function gets called the first time, false otherwise.
     358        @return True if this function got called the first time.
     359    */
     360    template <class T>
     361    bool ClassIdentifier<T>::isFirstCall()
     362    {
     363        static bool bFirstCall = true;
     364
     365        if (bFirstCall)
     366        {
     367            bFirstCall = false;
     368            return true;
     369        }
     370        else
     371        {
     372            return false;
     373        }
     374    }
     375
     376    /**
     377        @brief Returns the only instance of this class.
    373378        @return The unique Identifier
    374379    */
     
    377382    {
    378383        // check if the static field has already been filled
    379         if (ClassIdentifier<T>::classIdentifier_s == 0)
     384        if (ClassIdentifier<T>::isFirstCall())
    380385        {
    381386            // Get the name of the class
     
    383388
    384389            // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
    385             ClassIdentifier<T> *proposal = new ClassIdentifier<T>();
     390            ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    386391
    387392            // Get the entry from the map
    388             ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifier(name, proposal);
     393            ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
     394
     395            if (ClassIdentifier<T>::classIdentifier_s == proposal)
     396            {
     397                COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
     398            }
     399            else
     400            {
     401                COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
     402            }
    389403        }
    390404
     
    394408
    395409    /**
    396         @brief Sets the name of the class.
    397         @param name The name
    398     */
    399     template <class T>
    400     void ClassIdentifier<T>::setName(const std::string& name)
    401     {
    402         if (!this->bSetName_)
    403         {
    404             this->name_ = name;
    405             this->bSetName_ = true;
    406             Identifier::getIdentifierMapIntern()[name] = this;
    407             Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
    408         }
     410        @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
     411        @param name The name of this Identifier
     412        @return The Identifier
     413    */
     414    template <class T>
     415    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
     416    {
     417        ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
     418        identifier->setName(name);
     419        return identifier;
    409420    }
    410421
     
    417428    {
    418429        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
    419         object->getMetaList().add(this->objects_, this->objects_->add(object));
     430        object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
    420431    }
    421432
     
    424435    */
    425436    template <class T>
    426     void ClassIdentifier<T>::updateConfigValues() const
    427     {
    428         for (Iterator<T> it = this->objects_->start(); it; ++it)
    429             ((T*)*it)->setConfigValues();
    430     }
    431 
    432     /**
    433         @brief Returns a XMLPortParamContainer that loads a parameter of this class.
    434         @param paramname The name of the parameter
    435         @return The container
    436     */
    437     template <class T>
    438     XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
    439     {
    440         typename std::map<std::string, XMLPortClassParamContainer<T>*>::const_iterator it = xmlportParamContainers_.find(paramname);
    441         if (it != xmlportParamContainers_.end())
    442             return (XMLPortParamContainer*)((*it).second);
    443         else
    444             return 0;
    445     }
    446 
    447     /**
    448         @brief Adds a new XMLPortParamContainer that loads a parameter of this class.
    449         @param paramname The name of the parameter
    450         @param container The container
    451     */
    452     template <class T>
    453     void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
    454     {
    455         this->xmlportParamContainers_[paramname] = (XMLPortClassParamContainer<T>*)container;
    456     }
    457 
    458     /**
    459         @brief Returns a XMLPortObjectContainer that attaches an object to this class.
    460         @param sectionname The name of the section that contains the attachable objects
    461         @return The container
    462     */
    463     template <class T>
    464     XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
    465     {
    466         typename std::map<std::string, XMLPortClassObjectContainer<T, class O>*>::const_iterator it = xmlportObjectContainers_.find(sectionname);
    467         if (it != xmlportObjectContainers_.end())
    468             return (XMLPortObjectContainer*)((*it).second);
    469         else
    470             return 0;
    471     }
    472 
    473     /**
    474         @brief Adds a new XMLPortObjectContainer that attaches an object to this class.
    475         @param sectionname The name of the section that contains the attachable objects
    476         @param container The container
    477     */
    478     template <class T>
    479     void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
    480     {
    481         this->xmlportObjectContainers_[sectionname] = (XMLPortClassObjectContainer<T, class O>*)container;
     437    void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
     438    {
     439        if (!this->hasConfigValues())
     440            return;
     441
     442        for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
     443            it->setConfigValues();
     444
     445        if (updateChildren)
     446            for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it)
     447                (*it)->updateConfigValues(false);
    482448    }
    483449
Note: See TracChangeset for help on using the changeset viewer.