Changeset 362
- Timestamp:
- Nov 30, 2007, 1:12:53 AM (17 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/Factory.cc
r258 r362 11 11 pointer_s = new Factory; 12 12 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]; 14 22 } 15 23 … … 19 27 pointer_s = new Factory; 20 28 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; 22 37 } 23 38 } -
code/branches/objecthierarchy/src/orxonox/core/Factory.h
r258 r362 17 17 public: 18 18 static Identifier* getIdentifier(const std::string& name); 19 static Identifier* getIdentifier(const unsigned int id); 19 20 static void add(const std::string& name, Identifier* identifier); 21 static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID); 20 22 21 23 private: … … 25 27 26 28 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_; 28 31 }; 29 32 -
code/branches/objecthierarchy/src/orxonox/core/Identifier.cc
r258 r362 7 7 // ############################### 8 8 int Identifier::hierarchyCreatingCounter_s = 0; 9 unsigned int Identifier::classIDcounter_s = 0; 9 10 10 11 Identifier::Identifier() … … 14 15 15 16 this->children_ = new IdentifierList; 17 this->classID_ = Identifier::classIDcounter_s++; 16 18 } 17 19 … … 57 59 } 58 60 61 void Identifier::setNetworkID(unsigned int id) 62 { 63 Factory::changeNetworkID(this, this->classID_, id); 64 this->classID_ = id; 65 } 66 59 67 bool Identifier::isA(const Identifier* identifier) const 60 68 { -
code/branches/objecthierarchy/src/orxonox/core/Identifier.h
r258 r362 43 43 44 44 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); 45 48 46 49 private: … … 74 77 bool bCreatedOneObject_; 75 78 static int hierarchyCreatingCounter_s; 79 static unsigned int classIDcounter_s; 80 unsigned int classID_; 76 81 }; 77 82 -
code/branches/objecthierarchy/src/orxonox/core/IdentifierIncludes.h
r258 r362 41 41 bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create() 42 42 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 148 148 test4 = new A3(); 149 149 */ 150 /* 150 151 151 std::cout << "Test 5\n"; 152 152 A1* test5_01 = new A1(); … … 193 193 194 194 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"; 197 197 } 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 199 221 /* 200 222 std::cout << "\n"; … … 452 474 delete test9_06; 453 475 */ 454 476 /* 455 477 std::cout << "Test 10\n"; 456 478 Identifier* test10_01 = Class(A1B2); … … 582 604 583 605 std::cout << "13\n"; 584 606 */ 585 607 } 586 608
Note: See TracChangeset
for help on using the changeset viewer.