Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 362


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

added NetworkID

Location:
code/branches/objecthierarchy/src/orxonox
Files:
6 edited

Legend:

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

    r258 r362  
    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/objecthierarchy/src/orxonox/core/Factory.h

    r258 r362  
    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/objecthierarchy/src/orxonox/core/Identifier.cc

    r258 r362  
    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/objecthierarchy/src/orxonox/core/Identifier.h

    r258 r362  
    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/objecthierarchy/src/orxonox/core/IdentifierIncludes.h

    r258 r362  
    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)
  • code/branches/objecthierarchy/src/orxonox/orxonox.cc

    r266 r362  
    148148        test4 = new A3();
    149149*/
    150 /*
     150
    151151        std::cout << "Test 5\n";
    152152        A1* test5_01 = new A1();
     
    193193
    194194          std::cout << "\n";
    195           std::cout << test5->getIdentifier()->getName() << ": parents:     " << test5->getIdentifier()->getParents().toString() << "\n";
    196           std::cout << test5->getIdentifier()->getName() << ": children:    " << test5->getIdentifier()->getChildren().toString() << "\n";
     195          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): parents:     " << test5->getIdentifier()->getParents().toString() << "\n";
     196          std::cout << test5->getIdentifier()->getName() << " (" << test5->getIdentifier()->getNetworkID() << "): children:    " << test5->getIdentifier()->getChildren().toString() << "\n";
    197197        }
    198 */
     198
     199        std::cout << "Class with ID 0: " << ID(0) << " " << ID(0)->getName() << "\n";
     200        std::cout << "Class with ID 1: " << ID(1) << " " << ID(1)->getName() << "\n";
     201        std::cout << "Class with ID 2: " << ID(2) << " " << ID(2)->getName() << "\n";
     202        std::cout << "Class with ID 3: " << ID(3) << " " << ID(3)->getName() << "\n";
     203        std::cout << "Class with ID 4: " << ID(4) << " " << ID(4)->getName() << "\n";
     204        std::cout << "Class with ID 100: " << ID(100) << "\n";
     205        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
     206
     207        std::cout << "\nChange ID of BaseObject to 100\n";
     208        Class(BaseObject)->setNetworkID(100);
     209        std::cout << "Class with ID 100: " << ID(100) << "\n";
     210        std::cout << "Class with ID 1: " << ID(1) << "\n";
     211        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
     212
     213        std::cout << "\nChange ID of BaseObject to 3\n";
     214        Class(BaseObject)->setNetworkID(3);
     215        std::cout << "Class with ID 100: " << ID(100) << "\n";
     216        std::cout << "Class with ID 1: " << ID(1) << "\n";
     217        std::cout << "Class with ID 3: " << ID(3) << "\n";
     218        std::cout << "ID of BaseObject: " << Class(BaseObject)->getNetworkID() << "\n";
     219        std::cout << "ID of Test1: " << Class(Test1)->getNetworkID() << "\n";
     220
    199221/*
    200222        std::cout << "\n";
     
    452474        delete test9_06;
    453475*/
    454 
     476/*
    455477        std::cout << "Test 10\n";
    456478        Identifier* test10_01 = Class(A1B2);
     
    582604
    583605        std::cout << "13\n";
    584 
     606*/
    585607      }
    586608
Note: See TracChangeset for help on using the changeset viewer.