Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 363 for code/branches/FICN


Ignore:
Timestamp:
Nov 30, 2007, 1:20:20 AM (17 years ago)
Author:
landauf
Message:

added NetworkID

small tutorial for oli and dumeni:
every Identifier generates its own NetworkID, but it can be changed:

→ (Identifier)→setNetworkID(unsigned int)

be careful: after changing the NetworkID, there are probably 2 Identifiers with the same ID, so always change ALL Identifiers before using ID(unsigned int).

get an Identifier with a specific NetworkID:

→ ID(unsigned int)

get the name:

→ ID(unsigned int)→getName()

create an object:

→ ID(unsigned int)→fabricate()

get an Identifier with a specific name:

→ ID(std::string&)

get the NetworkID:

→ ID(std::string&)→getNetworkID()

create an object:

→ ID(std::string&)→fabricate()

Location:
code/branches/FICN/src/orxonox/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/Factory.cc

    r258 r363  
    1111            pointer_s = new Factory;
    1212
    13         return pointer_s->identifierMap_[name];
     13        return pointer_s->identifierStringMap_[name];
     14    }
     15
     16    Identifier* Factory::getIdentifier(const unsigned int id)
     17    {
     18        if (!pointer_s)
     19            pointer_s = new Factory;
     20
     21        return pointer_s->identifierNetworkIDMap_[id];
    1422    }
    1523
     
    1927            pointer_s = new Factory;
    2028
    21         pointer_s->identifierMap_[name] = identifier;
     29        pointer_s->identifierStringMap_[name] = identifier;
     30        pointer_s->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier;
     31    }
     32
     33    void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
     34    {
     35        pointer_s->identifierNetworkIDMap_.erase(oldID);
     36        pointer_s->identifierNetworkIDMap_[newID] = identifier;
    2237    }
    2338}
  • code/branches/FICN/src/orxonox/core/Factory.h

    r258 r363  
    1717        public:
    1818            static Identifier* getIdentifier(const std::string& name);
     19            static Identifier* getIdentifier(const unsigned int id);
    1920            static void add(const std::string& name, Identifier* identifier);
     21            static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID);
    2022
    2123        private:
     
    2527
    2628            static Factory* pointer_s;
    27             std::map<std::string, Identifier*> identifierMap_;
     29            std::map<std::string, Identifier*> identifierStringMap_;
     30            std::map<unsigned int, Identifier*> identifierNetworkIDMap_;
    2831    };
    2932
  • code/branches/FICN/src/orxonox/core/Identifier.cc

    r258 r363  
    77    // ###############################
    88    int Identifier::hierarchyCreatingCounter_s = 0;
     9    unsigned int Identifier::classIDcounter_s = 0;
    910
    1011    Identifier::Identifier()
     
    1415
    1516        this->children_ = new IdentifierList;
     17        this->classID_ = Identifier::classIDcounter_s++;
    1618    }
    1719
     
    5759    }
    5860
     61    void Identifier::setNetworkID(unsigned int id)
     62    {
     63        Factory::changeNetworkID(this, this->classID_, id);
     64        this->classID_ = id;
     65    }
     66
    5967    bool Identifier::isA(const Identifier* identifier) const
    6068    {
  • code/branches/FICN/src/orxonox/core/Identifier.h

    r346 r363  
    88#include "Factory.h"
    99
    10 #define HIERARCHY_VERBOSE 0
     10#define HIERARCHY_VERBOSE false
    1111
    1212
     
    4343
    4444            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
     45
     46            inline const unsigned int getNetworkID() const { return this->classID_; }
     47            void setNetworkID(unsigned int id);
    4548
    4649        private:
     
    7477            bool bCreatedOneObject_;
    7578            static int hierarchyCreatingCounter_s;
     79            static unsigned int classIDcounter_s;
     80            unsigned int classID_;
    7681    };
    7782
  • code/branches/FICN/src/orxonox/core/IdentifierIncludes.h

    r258 r363  
    4141    bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create()
    4242
    43 #define ID(Name) \
    44     Factory::getIdentifier(Name)
     43#define ID(NameOrID) \
     44    Factory::getIdentifier(NameOrID)
Note: See TracChangeset for help on using the changeset viewer.