Changeset 694 for code/branches/FICN/src/orxonox/core
- Timestamp:
- Dec 27, 2007, 2:07:50 AM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/ClassFactory.h
r690 r694 73 73 { 74 74 COUT(4) << "*** Create entry for " << name << " in Factory." << std::endl; 75 ClassIdentifier<T>::createIdentifier(name);76 75 ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>); 77 76 Factory::add(name, ClassIdentifier<T>::getIdentifier()); -
code/branches/FICN/src/orxonox/core/Identifier.h
r693 r694 190 190 public: 191 191 static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass); 192 static void createIdentifier(const std::string& name);193 192 static void addObject(T* object); 194 195 /** @returns the Identifier itself (createIdentifier() has to be called first). */ 196 inline static ClassIdentifier<T>* getIdentifier() 197 { 198 static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>(); 199 200 return &theOneAndOnlyInstance; 201 } 193 static ClassIdentifier<T>* getIdentifier(); 194 void setName(const std::string& name); 202 195 203 196 private: … … 206 199 ~ClassIdentifier(); 207 200 208 //static ClassIdentifier<T>* pointer_s; //!< A pointer to the singleton-object209 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T201 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 202 bool bSetName_; //!< True if the name is set 210 203 }; 211 204 … … 218 211 { 219 212 this->objects_ = new ObjectList<T>; 213 this->bSetName_ = false; 220 214 } 221 215 … … 241 235 COUT(4) << "*** Register Class in " << name << "-Singleton." << std::endl; 242 236 243 // It's a singleton, so maybe we have to create it first244 ClassIdentifier<T>::createIdentifier(name);245 246 237 // Check if at least one object of the given type was created 247 238 if (!getIdentifier()->bCreatedOneObject_) 248 239 { 249 240 // If no: We have to store the informations and initialize the Identifier 241 getIdentifier()->setName(name); 242 250 243 COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 251 244 if (bRootClass) … … 261 254 @brief Creates the only instance of this class for the template class T. 262 255 @param name The name of the Class 263 */ 264 template <class T> 265 void ClassIdentifier<T>::createIdentifier(const std::string& name) 266 { 256 @return The Identifier itself 257 */ 258 template <class T> 259 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 260 { 261 static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>(); 267 262 static bool bIdentifierCreated = false; 268 263 269 264 if (!bIdentifierCreated) 270 265 { 271 getIdentifier()->name_ = name; 272 getIdentifier()->identifierMap_s[name] = getIdentifier(); 273 COUT(4) << "*** Create Identifier Singleton for " << name << "." << std::endl; 266 COUT(4) << "*** Create Identifier Singleton." << std::endl; 274 267 bIdentifierCreated = true; 268 } 269 270 return &theOneAndOnlyInstance; 271 } 272 273 /** 274 @brief Sets the name of the class. 275 @param name The name 276 */ 277 template <class T> 278 void ClassIdentifier<T>::setName(const std::string& name) 279 { 280 // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map 281 if (!this->bSetName_) 282 { 283 this->name_ = name; 284 this->identifierMap_s[name] = this; 285 this->bSetName_ = true; 275 286 } 276 287 }
Note: See TracChangeset
for help on using the changeset viewer.