Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1583


Ignore:
Timestamp:
Jun 10, 2008, 3:01:24 AM (16 years ago)
Author:
landauf
Message:

changed Identifier initialization

Location:
code/branches/core3/src/core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/core/ClassFactory.h

    r1543 r1583  
    7474    {
    7575        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    76         ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>);
     76        ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
    7777        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    7878
  • code/branches/core3/src/core/ConsoleCommand.h

    r1549 r1583  
    4242
    4343#define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
    44     orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
     44    orxonox::ConsoleCommand& fakevariable = orxonox::ClassIdentifier<classname>::getIdentifier(#classname)->addConsoleCommand(command, bCreateShortcut)
    4545
    4646
  • code/branches/core3/src/core/CoreIncludes.h

    r1543 r1583  
    5555*/
    5656#define InternRegisterObject(ClassName, bRootClass) \
    57     this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier()->registerClass(this->getParents(), #ClassName, bRootClass)); \
    58     if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
    59         this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
    60     orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this); \
     57    this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)); \
    6158    if (orxonox::Identifier::isCreatingHierarchy()) \
    62       return
     59    { \
     60        if (this->getParents()) \
     61        { \
     62            orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeClassHierarchy(this->getParents(), bRootClass); \
     63            this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
     64        } \
     65        this->setConfigValues(); \
     66        return; \
     67    } \
     68    orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this)
    6369
    6470/**
  • code/branches/core3/src/core/IRC.cc

    r1505 r1583  
    4242    SetConsoleCommand(IRC, msg,  false).setAccessLevel(AccessLevel::User);
    4343    SetConsoleCommand(IRC, nick, false).setAccessLevel(AccessLevel::User);
    44 
    45     IRC* instance_irc = &IRC::getInstance();
    4644
    4745    IRC::IRC()
  • code/branches/core3/src/core/Identifier.cc

    r1574 r1583  
    5858
    5959        this->bCreatedOneObject_ = false;
     60        this->bSetName_ = false;
    6061        this->factory_ = 0;
    6162
     
    8687        @return The identifier (unique instance)
    8788    */
    88     Identifier *Identifier::getIdentifier(std::string &name, Identifier *proposal)
     89    Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    8990    {
    9091        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    9192        std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name);
    92         if (it == identifiers.end())
    93         {
    94             // there isn't an entry yet, put the proposal in it
     93
     94        if (it != identifiers.end())
     95        {
     96            // There is already an entry: return it and delete the proposal
     97            delete proposal;
     98            return (*it).second;
     99        }
     100        else
     101        {
     102            // There is no entry: put the proposal into the map and return it
    95103            identifiers[name] = proposal;
    96         }
    97         else
    98         {
    99             // this happens when a template exists twice --> delete the proposal
    100             delete proposal;
    101         }
    102         return identifiers[name];
     104            return proposal;
     105        }
    103106    }
    104107
     
    149152
    150153    /**
     154        @brief Sets the name of the class.
     155        @param name The name
     156    */
     157    void Identifier::setName(const std::string& name)
     158    {
     159        if (!this->bSetName_)
     160        {
     161            this->name_ = name;
     162            this->bSetName_ = true;
     163            Identifier::getIdentifierMapIntern()[name] = this;
     164            Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
     165        }
     166    }
     167
     168    /**
    151169        @brief Creates an object of the type the Identifier belongs to.
    152170        @return The new object
  • code/branches/core3/src/core/Identifier.h

    r1574 r1583  
    8787    {
    8888        template <class T>
    89         friend class ClassIdentifier;
    90 
    91         template <class T>
    9289        friend class SubclassIdentifier;
    9390
     
    114111            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
    115112            inline const std::string& getName() const { return this->name_; }
     113            void setName(const std::string& name);
    116114
    117115            virtual void updateConfigValues() const = 0;
     
    220218
    221219        protected:
     220            Identifier();
     221            Identifier(const Identifier& identifier); // don't copy
     222            virtual ~Identifier();
     223
     224            void initialize(std::set<const Identifier*>* parents);
     225            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
     226
    222227            /** @brief Returns the map that stores all Identifiers. @return The map */
    223228            static std::map<std::string, Identifier*>& getIdentifierMapIntern();
     
    225230            static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern();
    226231
     232            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     233
    227234        private:
    228             Identifier();
    229             Identifier(const Identifier& identifier); // don't copy
    230             virtual ~Identifier();
    231             void initialize(std::set<const Identifier*>* parents);
    232 
    233235            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
    234236            inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
     
    254256            }
    255257
    256             static Identifier* getIdentifier(std::string &name, Identifier *proposal);
    257 
    258258            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
    259259            std::set<const Identifier*>* children_;                        //!< The children of the class the Identifier belongs to
     
    262262            std::set<const Identifier*>* directChildren_;                  //!< The direct children of the class the Identifier belongs to
    263263
     264            bool bSetName_;                                                //!< True if the name is set
    264265            std::string name_;                                             //!< The name of the class the Identifier belongs to
    265 
    266266            ObjectListBase* objects_;                                      //!< The list of all objects of this class
    267267            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)
    269268            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)
    270269            unsigned int classID_;                                         //!< The network ID to identify a class through the network
     
    298297    {
    299298        public:
    300             ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass);
    301             void setName(const std::string& name);
     299            static ClassIdentifier<T> *getIdentifier();
     300            static ClassIdentifier<T> *getIdentifier(const std::string& name);
     301            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     302            static bool isFirstCall();
    302303
    303304            void updateConfigValues() const;
     
    309310            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
    310311
    311             static ClassIdentifier<T> *getIdentifier();
    312 
    313312        private:
    314             ClassIdentifier();
     313            ClassIdentifier() {}
    315314            ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    316315            ~ClassIdentifier() {}                                       // don't delete
    317316
    318             bool bSetName_;                                                                             //!< True if the name is set
    319317            std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;              //!< All loadable parameters
    320318            std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;   //!< All attachable objects
     
    327325
    328326    /**
    329         @brief Constructor: Creates the ObjectList.
    330     */
    331     template <class T>
    332     ClassIdentifier<T>::ClassIdentifier()
    333     {
    334         this->bSetName_ = false;
    335     }
    336 
    337     /**
    338327        @brief Registers a class, which means that the name and the parents get stored.
    339328        @param parents A list, containing the Identifiers of all parents of the class
    340         @param name A string, containing exactly the name of the class
    341329        @param bRootClass True if the class is either an Interface or the BaseObject itself
    342         @return The ClassIdentifier itself
    343     */
    344     template <class T>
    345     ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass)
    346     {
    347         this->setName(name);
    348 
     330    */
     331    template <class T>
     332    void ClassIdentifier<T>::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
     333    {
    349334        // Check if at least one object of the given type was created
    350335        if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    351336        {
    352337            // If no: We have to store the informations and initialize the Identifier
    353             COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
     338            COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
    354339            if (bRootClass)
    355                 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.
     340                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.
    356341            else
    357342                this->initialize(parents);
    358343        }
    359 
    360         return this;
    361     }
    362 
    363     /**
    364         @brief Creates the only instance of this class for the template class T and retrieves a unique Identifier for the given name.
     344    }
     345
     346    /**
     347        @brief Returns true if the function gets called the first time, false otherwise.
     348        @return True if this function got called the first time.
     349    */
     350    template <class T>
     351    bool ClassIdentifier<T>::isFirstCall()
     352    {
     353        static bool bFirstCall = true;
     354
     355        if (bFirstCall)
     356        {
     357            bFirstCall = false;
     358            return true;
     359        }
     360        else
     361        {
     362            return false;
     363        }
     364    }
     365
     366    /**
     367        @brief Returns the only instance of this class.
    365368        @return The unique Identifier
    366369    */
     
    369372    {
    370373        // check if the static field has already been filled
    371         if (ClassIdentifier<T>::classIdentifier_s == 0)
     374        if (ClassIdentifier<T>::isFirstCall())
    372375        {
    373376            // Get the name of the class
     
    375378
    376379            // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
    377             ClassIdentifier<T> *proposal = new ClassIdentifier<T>();
     380            ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    378381
    379382            // Get the entry from the map
    380             ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifier(name, proposal);
     383            ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
     384
     385            if (ClassIdentifier<T>::classIdentifier_s == proposal)
     386            {
     387                COUT(4) << "*** Identifier: Requested Identifier for " << name << " was not yet existing and got created." << std::endl;
     388            }
     389            else
     390            {
     391                COUT(4) << "*** Identifier: Requested Identifier for " << name << " was already existing and got assigned." << std::endl;
     392            }
    381393        }
    382394
     
    386398
    387399    /**
    388         @brief Sets the name of the class.
    389         @param name The name
    390     */
    391     template <class T>
    392     void ClassIdentifier<T>::setName(const std::string& name)
    393     {
    394         if (!this->bSetName_)
    395         {
    396             this->name_ = name;
    397             this->bSetName_ = true;
    398             Identifier::getIdentifierMapIntern()[name] = this;
    399             Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
    400         }
     400        @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
     401        @param name The name of this Identifier
     402        @return The Identifier
     403    */
     404    template <class T>
     405    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
     406    {
     407        ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
     408        identifier->setName(name);
     409        return identifier;
    401410    }
    402411
     
    407416    void ClassIdentifier<T>::updateConfigValues() const
    408417    {
    409         for (Iterator<T> it = this->objects_->begin(); it; ++it)
     418        for (Iterator<T> it = this->getObjects()->begin(); it; ++it)
    410419            (*it)->setConfigValues();
    411420    }
  • code/branches/core3/src/core/TclThreadManager.cc

    r1505 r1583  
    5858    SetConsoleCommand(TclThreadManager, flush,   false).setArgumentCompleter(0, autocompletion::tclthreads());
    5959
    60     TclThreadManager* instance_tclthreadmanager = &TclThreadManager::getInstance();
    61 
    6260    TclThreadManager::TclThreadManager()
    6361    {
Note: See TracChangeset for help on using the changeset viewer.