Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1856 for code


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
Files:
10 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                                {
  • code/trunk/src/network/ConnectionManager.cc

    r1842 r1856  
    345345    std::string classname;
    346346    orxonox::Identifier *id;
    347     std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin();
    348     while(it != orxonox::Factory::getFactoryEnd()){
     347    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryMapBegin();
     348    while(it != orxonox::Factory::getFactoryMapEnd()){
    349349      id = (*it).second;
    350350      if(id == NULL)
  • code/trunk/src/network/Server.cc

    r1785 r1856  
    340340    if(!client)
    341341      return false;
    342     orxonox::Identifier* id = GetIdentifier("SpaceShip");
     342    orxonox::Identifier* id = ClassByName("SpaceShip");
    343343    if(!id){
    344344      COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
  • code/trunk/src/network/Synchronisable.cc

    r1837 r1856  
    8383  }
    8484
    85  
     85
    8686  void Synchronisable::setClient(bool b){
    8787    if(b) // client
     
    9090      state_=0x1;
    9191  }
    92  
     92
    9393  bool Synchronisable::fabricate(unsigned char*& mem, int mode)
    9494  {
     
    9797    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
    9898    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
    99    
     99
    100100    if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything
    101101      mem+=3*sizeof(unsigned int);
    102102      return true;
    103103    }
    104    
    105     orxonox::Identifier* id = GetIdentifier(classID);
     104
     105    orxonox::Identifier* id = ClassByID(classID);
    106106    if(!id){
    107107      COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
     
    149149    syncList->push_back(temp);
    150150  }
    151  
     151
    152152  /**
    153153   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
     
    171171    unsigned int size;
    172172    size=getSize2(id, mode);
    173    
     173
    174174    // start copy header
    175175    memcpy(mem, &size, sizeof(unsigned int));
     
    181181    tempsize+=12;
    182182    // end copy header
    183    
     183
    184184    //if this tick is we dont synchronise, then abort now
    185185    if(!isMyTick(id))
    186186      return true;
    187    
     187
    188188    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
    189189    // copy to location
     
    215215  }
    216216
    217  
     217
    218218  /**
    219219   * This function takes a syncData struct and takes it to update the variables
     
    230230      return false;
    231231    }
    232    
     232
    233233    // start extract header
    234234    unsigned int objectID, classID, size;
     
    245245      return true;
    246246      //assert(0);
    247    
     247
    248248    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
    249249    for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){
     
    317317    return sizeof(synchronisableHeader) + getSize( id, mode );
    318318  }
    319  
    320   /**
    321    * 
    322    * @param id 
    323    * @return 
     319
     320  /**
     321   *
     322   * @param id
     323   * @return
    324324   */
    325325  bool Synchronisable::isMyTick(unsigned int id){
     
    327327    return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0);
    328328  }
    329  
     329
    330330  bool Synchronisable::isMyData(unsigned char* mem)
    331331  {
     
    337337    classID = *(int *)mem;
    338338    mem+=sizeof(classID);
    339    
     339
    340340    assert(classID == this->classID);
    341341    return (objectID == this->objectID);
    342342  }
    343  
     343
    344344  void Synchronisable::setObjectMode(int mode){
    345345    assert(mode==0x1 || mode==0x2 || mode==0x3);
  • code/trunk/src/network/packet/ClassID.cc

    r1837 r1856  
    4242#define _CLASSNAMELENGTH      _CLASSID + sizeof(unsigned int)
    4343#define _CLASSNAME            _CLASSNAMELENGTH + sizeof(classNameLength_)
    44  
     44
    4545  ClassID::ClassID( unsigned int classID, std::string className )
    4646 : Packet()
     
    7373bool ClassID::process(){
    7474  COUT(3) << "processing classid: " << getClassID() << " name: " << (const char*)(data_+_CLASSNAME) << std::endl;
    75   orxonox::Identifier *id=GetIdentifier( std::string((const char*)(data_+_CLASSNAME) ));
     75  orxonox::Identifier *id=ClassByID( std::string((const char*)(data_+_CLASSNAME) ));
    7676  if(id==NULL)
    7777    return false;
Note: See TracChangeset for help on using the changeset viewer.