Changeset 10395 for code/branches/core7/src
- Timestamp:
- Apr 25, 2015, 10:49:34 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/CoreIncludes.h
r10381 r10395 134 134 */ 135 135 #define RegisterObject(ClassName) \ 136 if (ClassIdentifier<ClassName>::getIdentifier( #ClassName)->initializeObject(this)) \136 if (ClassIdentifier<ClassName>::getIdentifier()->initializeObject(this)) \ 137 137 return; \ 138 138 else \ … … 168 168 { 169 169 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl; 170 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 171 identifier->setFactory(factory); 172 identifier->setLoadable(bLoadable); 170 Identifier* identifier = new ClassIdentifier<T>(name, factory, bLoadable); 171 IdentifierManager::getInstance().addIdentifier(identifier); 173 172 return identifier; 174 173 } -
code/branches/core7/src/libraries/core/class/Identifier.cc
r10381 r10395 50 50 @brief Constructor: No factory, no object created, new ObjectList and a unique networkID. 51 51 */ 52 Identifier::Identifier( )52 Identifier::Identifier(const std::string& name, Factory* factory, bool bLoadable) 53 53 : classID_(IdentifierManager::getInstance().getUniqueClassId()) 54 54 { 55 this->factory_ = 0; 55 this->name_ = name; 56 this->factory_ = factory; 57 this->bLoadable_ = bLoadable; 56 58 this->bInitialized_ = false; 57 this->bLoadable_ = false;58 59 this->bIsVirtualBase_ = false; 59 60 … … 78 79 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) 79 80 delete (it->second); 80 }81 82 /**83 @brief Sets the name of the class.84 */85 void Identifier::setName(const std::string& name)86 {87 if (name != this->name_)88 {89 this->name_ = name;90 IdentifierManager::getInstance().addIdentifierToLookupMaps(this);91 }92 }93 94 void Identifier::setFactory(Factory* factory)95 {96 if (this->factory_)97 delete this->factory_;98 99 this->factory_ = factory;100 81 } 101 82 … … 127 108 { 128 109 this->networkID_ = id; 129 IdentifierManager::getInstance().addIdentifier ToLookupMaps(this);110 IdentifierManager::getInstance().addIdentifier(this); 130 111 } 131 112 -
code/branches/core7/src/libraries/core/class/Identifier.h
r10381 r10395 82 82 83 83 #include "util/Output.h" 84 #include "util/OrxAssert.h" 84 85 #include "core/object/ObjectList.h" 85 86 #include "core/object/Listable.h" … … 109 110 { 110 111 public: 111 Identifier( );112 Identifier(const std::string& name, Factory* factory, bool bLoadable); 112 113 Identifier(const Identifier& identifier); // don't copy 113 114 virtual ~Identifier(); … … 115 116 /// Returns the name of the class the Identifier belongs to. 116 117 inline const std::string& getName() const { return this->name_; } 117 void setName(const std::string& name);118 118 119 119 /// Returns the name of the class as it is returned by typeid(T).name() … … 127 127 ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; } 128 128 129 /// Sets the Factory.130 void setFactory(Factory* factory);131 129 /// Returns true if the Identifier has a Factory. 132 130 inline bool hasFactory() const { return (this->factory_ != 0); } … … 136 134 /// Returns true if the class can be loaded through XML. 137 135 inline bool isLoadable() const { return this->bLoadable_; } 138 /// Set the class to be loadable through XML or not.139 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }140 136 141 137 /// Returns true if child classes should inherit virtually from this class. … … 264 260 265 261 public: 266 static ClassIdentifier<T>* getIdentifier(); 267 static ClassIdentifier<T>* getIdentifier(const std::string& name); 268 269 bool initializeObject(T* object); 270 271 void setConfigValues(T* object, Configurable*) const; 272 void setConfigValues(T* object, Identifiable*) const; 273 274 void addObjectToList(T* object, Listable*); 275 void addObjectToList(T* object, Identifiable*); 276 277 virtual void updateConfigValues(bool updateChildren = true) const; 278 279 virtual const std::string& getTypeidName() 280 { return this->typeidName_; } 281 282 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 283 { return dynamic_cast<T*>(object) != 0; } 284 285 private: 286 static void initializeIdentifier(); 287 288 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 289 ClassIdentifier() 262 ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable) 290 263 { 264 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 265 ClassIdentifier<T>::classIdentifier_s = this; 266 291 267 this->typeidName_ = typeid(T).name(); 292 268 SuperFunctionInitialization<0, T>::initialize(this); … … 297 273 } 298 274 275 bool initializeObject(T* object); 276 277 void setConfigValues(T* object, Configurable*) const; 278 void setConfigValues(T* object, Identifiable*) const; 279 280 void addObjectToList(T* object, Listable*); 281 void addObjectToList(T* object, Identifiable*); 282 283 virtual void updateConfigValues(bool updateChildren = true) const; 284 285 virtual const std::string& getTypeidName() 286 { return this->typeidName_; } 287 288 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 289 { return dynamic_cast<T*>(object) != 0; } 290 291 static ClassIdentifier<T>* getIdentifier(); 292 293 private: 294 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 295 299 296 void updateConfigValues(bool updateChildren, Listable*) const; 300 297 void updateConfigValues(bool updateChildren, Identifiable*) const; … … 312 309 */ 313 310 template <class T> 314 inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()315 { 316 // check if the Identifier already exists317 if (!ClassIdentifier<T>::classIdentifier_s)318 ClassIdentifier<T>::initializeIdentifier(); 319 311 /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 312 { 313 if (ClassIdentifier<T>::classIdentifier_s == NULL) 314 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeidName(typeid(T).name()); 315 316 OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 320 317 return ClassIdentifier<T>::classIdentifier_s; 321 }322 323 /**324 @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.325 @param name The name of this Identifier326 @return The Identifier327 */328 template <class T>329 inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)330 {331 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();332 identifier->setName(name);333 return identifier;334 }335 336 /**337 @brief Assigns the static field for the identifier singleton.338 */339 template <class T>340 /*static */ void ClassIdentifier<T>::initializeIdentifier()341 {342 // create a new identifier anyway. Will be deleted if not used.343 ClassIdentifier<T>* proposal = new ClassIdentifier<T>();344 345 // Get the entry from the map346 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal);347 348 if (ClassIdentifier<T>::classIdentifier_s == proposal)349 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;350 else351 {352 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;353 delete proposal; // delete proposal (it is not used anymore)354 }355 318 } 356 319 -
code/branches/core7/src/libraries/core/class/IdentifierManager.cc
r10372 r10395 58 58 59 59 /** 60 @brief Returns an identifier by name and adds it if not available61 @param proposal A pointer to a newly created identifier for the case of non existence in the map62 @return The identifier (unique instance)63 */64 Identifier* IdentifierManager::getGloballyUniqueIdentifier(Identifier* proposal)65 {66 const std::string& typeidName = proposal->getTypeidName();67 std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName);68 69 if (it != this->identifierByTypeidName_.end())70 {71 // There is already an entry: return it72 return it->second;73 }74 else75 {76 // There is no entry: put the proposal into the map and return it77 this->identifierByTypeidName_[typeidName] = proposal;78 return proposal;79 }80 }81 82 /**83 60 * Registers the identifier in all maps of the IdentifierManager. 84 61 */ 85 void IdentifierManager::addIdentifierToLookupMaps(Identifier* identifier) 86 { 87 const std::string& typeidName = identifier->getTypeidName(); 88 if (this->identifierByTypeidName_.find(typeidName) != this->identifierByTypeidName_.end()) 89 { 90 this->identifierByString_[identifier->getName()] = identifier; 91 this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier; 92 this->identifierByNetworkId_[identifier->getNetworkID()] = identifier; 93 } 94 else 95 orxout(internal_warning) << "Trying to add an identifier to lookup maps which is not known to IdentifierManager" << endl; 62 void IdentifierManager::addIdentifier(Identifier* identifier) 63 { 64 orxout(verbose, context::identifier) << "Adding identifier for " << identifier->getName() << " / " << identifier->getTypeidName() << endl; 65 66 this->identifierByTypeidName_[identifier->getTypeidName()] = identifier; 67 this->identifierByString_[identifier->getName()] = identifier; 68 this->identifierByLowercaseString_[getLowercase(identifier->getName())] = identifier; 69 this->identifierByNetworkId_[identifier->getNetworkID()] = identifier; 96 70 } 97 71 … … 272 246 273 247 /** 248 @brief Returns the Identifier with a given typeid-name. 249 @param name The typeid-name of the wanted Identifier 250 @return The Identifier 251 */ 252 Identifier* IdentifierManager::getIdentifierByTypeidName(const std::string& typeidName) 253 { 254 std::map<std::string, Identifier*>::const_iterator it = this->identifierByTypeidName_.find(typeidName); 255 if (it != this->identifierByTypeidName_.end()) 256 return it->second; 257 else 258 return 0; 259 } 260 261 /** 274 262 @brief Cleans the NetworkID map (needed on clients for correct initialization) 275 263 */ -
code/branches/core7/src/libraries/core/class/IdentifierManager.h
r10372 r10395 48 48 static IdentifierManager& getInstance(); 49 49 50 Identifier* getGloballyUniqueIdentifier(Identifier* proposal); 51 void addIdentifierToLookupMaps(Identifier* identifier); 50 void addIdentifier(Identifier* identifier); 52 51 53 52 unsigned int getUniqueClassId() … … 75 74 Identifier* getIdentifierByLowercaseString(const std::string& name); 76 75 Identifier* getIdentifierByID(uint32_t id); 76 Identifier* getIdentifierByTypeidName(const std::string& typeidName); 77 77 78 78 void clearNetworkIDs();
Note: See TracChangeset
for help on using the changeset viewer.