Changeset 693 for code/branches
- Timestamp:
- Dec 26, 2007, 11:59:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/Identifier.h
r692 r693 194 194 195 195 /** @returns the Identifier itself (createIdentifier() has to be called first). */ 196 inline static ClassIdentifier<T>* getIdentifier() { return pointer_s; } 196 inline static ClassIdentifier<T>* getIdentifier() 197 { 198 static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>(); 199 200 return &theOneAndOnlyInstance; 201 } 197 202 198 203 private: 199 ClassIdentifier( const std::string& name);204 ClassIdentifier(); 200 205 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 201 206 ~ClassIdentifier(); 202 207 203 static ClassIdentifier<T>* pointer_s; //!< A pointer to the singleton-object208 //static ClassIdentifier<T>* pointer_s; //!< A pointer to the singleton-object 204 209 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 205 210 }; 206 211 207 template <class T>208 ClassIdentifier<T>* ClassIdentifier<T>::pointer_s;209 210 212 /** 211 213 @brief Constructor: Creates the ObjectList. … … 213 215 */ 214 216 template <class T> 215 ClassIdentifier<T>::ClassIdentifier( const std::string& name)217 ClassIdentifier<T>::ClassIdentifier() 216 218 { 217 219 this->objects_ = new ObjectList<T>; 218 this->name_ = name;219 this->identifierMap_s[name] = this;220 220 } 221 221 … … 227 227 { 228 228 delete this->objects_; 229 this->pointer_s = NULL;230 229 } 231 230 … … 246 245 247 246 // Check if at least one object of the given type was created 248 if (! pointer_s->bCreatedOneObject_)247 if (!getIdentifier()->bCreatedOneObject_) 249 248 { 250 249 // If no: We have to store the informations and initialize the Identifier 251 250 COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 252 251 if (bRootClass) 253 pointer_s->initialize(NULL); // 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.252 getIdentifier()->initialize(NULL); // 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. 254 253 else 255 pointer_s->initialize(parents);254 getIdentifier()->initialize(parents); 256 255 } 257 256 258 return pointer_s;257 return getIdentifier(); 259 258 } 260 259 … … 266 265 void ClassIdentifier<T>::createIdentifier(const std::string& name) 267 266 { 268 static bool bFirstCeateIdentifierFunctionCall = true; 269 static ClassIdentifier<T> classIdentifierObject = ClassIdentifier<T>(name); 270 271 if (bFirstCeateIdentifierFunctionCall) 267 static bool bIdentifierCreated = false; 268 269 if (!bIdentifierCreated) 272 270 { 271 getIdentifier()->name_ = name; 272 getIdentifier()->identifierMap_s[name] = getIdentifier(); 273 273 COUT(4) << "*** Create Identifier Singleton for " << name << "." << std::endl; 274 pointer_s = &classIdentifierObject; 275 bFirstCeateIdentifierFunctionCall = false; 274 bIdentifierCreated = true; 276 275 } 277 276 }
Note: See TracChangeset
for help on using the changeset viewer.