Changeset 1856 for code/trunk
- Timestamp:
- Sep 29, 2008, 4:15:03 AM (16 years ago)
- Location:
- code/trunk/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/CoreIncludes.h
r1789 r1856 94 94 95 95 /** 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 /** 96 103 @brief Returns the Identifier of the given class. 97 104 @param ClassName The name of the class … … 101 108 102 109 /** 103 @brief Creates the entry in the Factory.104 @param ClassNameThe name of the class110 @brief Returns the Identifier with a given name through the factory. 111 @param String The name of the class 105 112 */ 106 #define C reateFactory(ClassName) \107 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)113 #define ClassByName(String) \ 114 orxonox::Factory::getIdentifier(String) 108 115 109 116 /** 110 @brief Returns the Identifier with either a given name ora given network ID through the factory.111 @param StringOrInt The name or the network ID of the class117 @brief Returns the Identifier with a given network ID through the factory. 118 @param networkID The network ID of the class 112 119 */ 113 #define GetIdentifier(StringOrInt) \114 orxonox::Factory::getIdentifier( StringOrInt)120 #define ClassByID(networkID) \ 121 orxonox::Factory::getIdentifier(networkID) 115 122 116 123 #endif /* _CoreIncludes_H__ */ -
code/trunk/src/core/Factory.cc
r1747 r1856 110 110 return &theOneAndOnlyFactoryInstance; 111 111 } 112 113 /**114 @brief Returns the begin-iterator of the factory-map.115 @return The begin-iterator116 */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-iterator125 */126 std::map<std::string, Identifier*>::const_iterator Factory::getFactoryEnd()127 {128 return Factory::getFactoryPointer()->identifierStringMap_.end();129 }130 112 } -
code/trunk/src/core/Factory.h
r1505 r1856 66 66 67 67 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(); } 70 78 71 79 private: -
code/trunk/src/core/Identifier.cc
r1747 r1856 115 115 identifiers[name] = proposal; 116 116 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); 117 136 } 118 137 } -
code/trunk/src/core/Identifier.h
r1755 r1856 190 190 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 191 191 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(); } 192 205 193 206 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ … … 219 232 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 220 233 234 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 235 221 236 protected: 222 237 Identifier(); … … 224 239 virtual ~Identifier(); 225 240 226 void initialize(std::set<const Identifier*>* parents);227 241 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 228 229 242 virtual void createSuperFunctionCaller() const = 0; 230 243 … … 239 252 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 240 253 241 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents)242 254 ObjectListBase* objects_; //!< The list of all objects of this class 243 255 … … 261 273 } 262 274 275 void initialize(std::set<const Identifier*>* parents); 276 263 277 static void destroyAllIdentifiers(); 264 278 … … 269 283 std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 270 284 285 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 271 286 bool bSetName_; //!< True if the name is set 272 287 std::string name_; //!< The name of the class the Identifier belongs to … … 311 326 static ClassIdentifier<T> *getIdentifier(); 312 327 static ClassIdentifier<T> *getIdentifier(const std::string& name); 313 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);328 void addObject(T* object); 314 329 static bool isFirstCall(); 315 void addObject(T* object);316 330 317 331 void updateConfigValues(bool updateChildren = true) const; … … 328 342 } 329 343 330 static ClassIdentifier<T> *classIdentifier_s;344 static ClassIdentifier<T>* classIdentifier_s; 331 345 }; 332 346 333 347 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; 355 349 356 350 /** … … 476 470 SubclassIdentifier(Identifier* identifier) 477 471 { 478 this-> identifier_ = identifier;472 this->operator=(identifier); 479 473 } 480 474 … … 500 494 /** 501 495 @brief Overloading of the * operator: returns the assigned identifier. 502 @return The assigned identifier 503 */ 504 Identifier* operator*() 496 */ 497 inline Identifier* operator*() 505 498 { 506 499 return this->identifier_; … … 509 502 /** 510 503 @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 514 514 { 515 515 return this->identifier_; … … 527 527 if (newObject) 528 528 { 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); 531 530 } 532 531 else … … 552 551 553 552 /** @brief Returns the assigned identifier. @return The identifier */ 554 inline constIdentifier* getIdentifier() const553 inline Identifier* getIdentifier() const 555 554 { return this->identifier_; } 556 555 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) const559 { 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) const563 { 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) const567 { 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) const571 { 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) const575 { 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) const579 { 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); } 580 579 581 580 private: -
code/trunk/src/core/XMLPort.h
r1854 r1856 468 468 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 469 469 { 470 Identifier* identifier = GetIdentifier(child->Value());470 Identifier* identifier = ClassByName(child->Value()); 471 471 if (identifier) 472 472 { -
code/trunk/src/network/ConnectionManager.cc
r1842 r1856 345 345 std::string classname; 346 346 orxonox::Identifier *id; 347 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactory Begin();348 while(it != orxonox::Factory::getFactory End()){347 std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryMapBegin(); 348 while(it != orxonox::Factory::getFactoryMapEnd()){ 349 349 id = (*it).second; 350 350 if(id == NULL) -
code/trunk/src/network/Server.cc
r1785 r1856 340 340 if(!client) 341 341 return false; 342 orxonox::Identifier* id = GetIdentifier("SpaceShip");342 orxonox::Identifier* id = ClassByName("SpaceShip"); 343 343 if(!id){ 344 344 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; -
code/trunk/src/network/Synchronisable.cc
r1837 r1856 83 83 } 84 84 85 85 86 86 void Synchronisable::setClient(bool b){ 87 87 if(b) // client … … 90 90 state_=0x1; 91 91 } 92 92 93 93 bool Synchronisable::fabricate(unsigned char*& mem, int mode) 94 94 { … … 97 97 objectID = *(unsigned int*)(mem+sizeof(unsigned int)); 98 98 classID = *(unsigned int*)(mem+2*sizeof(unsigned int)); 99 99 100 100 if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything 101 101 mem+=3*sizeof(unsigned int); 102 102 return true; 103 103 } 104 105 orxonox::Identifier* id = GetIdentifier(classID);104 105 orxonox::Identifier* id = ClassByID(classID); 106 106 if(!id){ 107 107 COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl; … … 149 149 syncList->push_back(temp); 150 150 } 151 151 152 152 /** 153 153 * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct … … 171 171 unsigned int size; 172 172 size=getSize2(id, mode); 173 173 174 174 // start copy header 175 175 memcpy(mem, &size, sizeof(unsigned int)); … … 181 181 tempsize+=12; 182 182 // end copy header 183 183 184 184 //if this tick is we dont synchronise, then abort now 185 185 if(!isMyTick(id)) 186 186 return true; 187 187 188 188 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 189 189 // copy to location … … 215 215 } 216 216 217 217 218 218 /** 219 219 * This function takes a syncData struct and takes it to update the variables … … 230 230 return false; 231 231 } 232 232 233 233 // start extract header 234 234 unsigned int objectID, classID, size; … … 245 245 return true; 246 246 //assert(0); 247 247 248 248 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl; 249 249 for(i=syncList->begin(); i!=syncList->end() && mem <= data+size; i++){ … … 317 317 return sizeof(synchronisableHeader) + getSize( id, mode ); 318 318 } 319 320 /** 321 * 322 * @param id 323 * @return 319 320 /** 321 * 322 * @param id 323 * @return 324 324 */ 325 325 bool Synchronisable::isMyTick(unsigned int id){ … … 327 327 return ( id==0 || id%objectFrequency_==objectID%objectFrequency_ ) && ((objectMode_&state_)!=0); 328 328 } 329 329 330 330 bool Synchronisable::isMyData(unsigned char* mem) 331 331 { … … 337 337 classID = *(int *)mem; 338 338 mem+=sizeof(classID); 339 339 340 340 assert(classID == this->classID); 341 341 return (objectID == this->objectID); 342 342 } 343 343 344 344 void Synchronisable::setObjectMode(int mode){ 345 345 assert(mode==0x1 || mode==0x2 || mode==0x3); -
code/trunk/src/network/packet/ClassID.cc
r1837 r1856 42 42 #define _CLASSNAMELENGTH _CLASSID + sizeof(unsigned int) 43 43 #define _CLASSNAME _CLASSNAMELENGTH + sizeof(classNameLength_) 44 44 45 45 ClassID::ClassID( unsigned int classID, std::string className ) 46 46 : Packet() … … 73 73 bool ClassID::process(){ 74 74 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) )); 76 76 if(id==NULL) 77 77 return false;
Note: See TracChangeset
for help on using the changeset viewer.