Changeset 7372 for code/branches/doc/src/libraries/core/Identifier.h
- Timestamp:
- Sep 7, 2010, 12:58:52 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/core/Identifier.h
r7363 r7372 35 35 @file 36 36 @ingroup Class Identifier 37 @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class. 38 39 The Identifier contains all needed information about the class it belongs to: 40 - the name 41 - a list with all objects 42 - parents and children 43 - the factory (if available) 44 - the networkID that can be synchronised with the server 45 - all configurable variables (if available) 46 47 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 48 isExactlyA(...), isChildOf(...) and isParentOf(...). 49 50 To create the class-hierarchy, the Identifier has some intern functions and variables. 51 52 Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier. 37 @brief Declaration of Identifier, definition of ClassIdentifier<T>. 38 39 @anchor IdentifierExample 40 41 An Identifier "identifies" the class of an object. It contains different information about 42 the class: Its name and ID, a list of all instances of this class, a factory to create new 43 instances of this class, and more. 44 45 It also contains information about the inheritance of this class: It stores a list of the 46 Identifiers of all parent-classes as well as a list of all child-classes. These relationships 47 can be tested using functions like @c isA(), @c isChildOf(), @c isParentOf(), and more. 48 49 Every Identifier is in fact a ClassIdentifier<T> (where T is the class that is identified 50 by the Identifier), Identifier is just the common base-class. 51 52 Example: 53 @code 54 MyClass* object = new MyClass(); // create an instance of MyClass 55 56 object->getIdentifier()->getName(); // returns "MyClass" 57 58 BaseObject* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 59 60 61 // iterate through all objects of type MyClass: 62 ObjectListBase* objects = object->getIdentifier()->getObjects(); // get a pointer to the object-list 63 int count; 64 for (Iterator<BaseObject> it = objects.begin(); it != objects.end(); ++it) // iterate through the objects 65 ++count; 66 COUT(0) << count << std::endl; // prints "2" because we created 2 instances of MyClass so far 67 68 69 // test the class hierarchy 70 object->getIdentifier()->isA(Class(MyClass)); // returns true 71 object->isA(Class(MyClass)); // returns true (short version) 72 73 object->isA(Class(BaseClass)); // returns true if MyClass is a child of BaseClass 74 75 Class(ChildClass)->isChildOf(object->getIdentifier()); // returns true if ChildClass is a child of MyClass 76 @endcode 53 77 */ 54 78 … … 76 100 // ### Identifier ### 77 101 // ############################### 78 //! The Identifier is used to identify the class of an object and to store information about the class. 79 /** 80 The Identifier contains all needed information about the class it belongs to: 81 - the name 82 - a list with all objects 83 - parents and children 84 - the factory (if available) 85 - the networkID that can be synchronised with the server 86 - all configurable variables (if available) 87 88 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 89 isExactlyA(...), isChildOf(...) and isParentOf(...). 90 91 You can't directly create an Identifier, it's just the base-class for ClassIdentifier. 102 /** 103 @brief The Identifier is used to identify the class of an object and to store information about the class. 104 105 Each Identifier stores information about one class. The Identifier can then be used to identify 106 this class. On the other hand it's also possible to get the corresponding Identifier of a class, 107 for example by using the macro Class(). 108 109 @see See @ref IdentifierExample "Identifier.h" for more information and some examples. 110 111 @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>. 92 112 */ 93 113 class _CoreExport Identifier 94 114 { 95 115 public: 96 / ** @brief Returns the name of the class the Identifier belongs to. @return The name */116 /// Returns the name of the class the Identifier belongs to. 97 117 inline const std::string& getName() const { return this->name_; } 98 118 void setName(const std::string& name); 99 119 100 / ** @brief Returns the network ID to identify a class through the network. @return the network ID */120 /// Returns the network ID to identify a class through the network. 101 121 inline const uint32_t getNetworkID() const { return this->networkID_; } 102 122 void setNetworkID(uint32_t id); 103 123 104 / ** @brief Returns the unique ID of the class */124 /// Returns the unique ID of the class. 105 125 FORCEINLINE unsigned int getClassID() const { return this->classID_; } 106 126 107 / ** @brief Returns the list of all existing objects of this class. @return The list */127 /// Returns the list of all existing objects of this class. 108 128 inline ObjectListBase* getObjects() const { return this->objects_; } 109 129 110 / ** @brief Sets the Factory. @param factory The factory to assign */130 /// Sets the Factory. 111 131 inline void addFactory(Factory* factory) { this->factory_ = factory; } 112 / ** @brief Returns true if the Identifier has a Factory. */132 /// Returns true if the Identifier has a Factory. 113 133 inline bool hasFactory() const { return (this->factory_ != 0); } 114 134 115 135 BaseObject* fabricate(BaseObject* creator); 116 136 117 / ** @brief Returns true if the class can be loaded through XML. */137 /// Returns true if the class can be loaded through XML. 118 138 inline bool isLoadable() const { return this->bLoadable_; } 119 / ** @brief Set the class to be loadable through XML or not. */139 /// Set the class to be loadable through XML or not. 120 140 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 121 141 … … 133 153 static void createClassHierarchy(); 134 154 135 / ** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */155 /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. 136 156 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 137 157 138 / ** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */158 /// Returns the parents of the class the Identifier belongs to. 139 159 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } 140 / ** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */160 /// Returns the begin-iterator of the parents-list. 141 161 inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); } 142 / ** @brief Returns the end-iterator of the parents-list. @return The end-iterator */162 /// Returns the end-iterator of the parents-list. 143 163 inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); } 144 164 145 / ** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */165 /// Returns the children of the class the Identifier belongs to. 146 166 inline const std::set<const Identifier*>& getChildren() const { return this->children_; } 147 / ** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */167 /// Returns the begin-iterator of the children-list. 148 168 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); } 149 / ** @brief Returns the end-iterator of the children-list. @return The end-iterator */169 /// Returns the end-iterator of the children-list. 150 170 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); } 151 171 152 / ** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */172 /// Returns the direct parents of the class the Identifier belongs to. 153 173 inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; } 154 / ** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */174 /// Returns the begin-iterator of the direct-parents-list. 155 175 inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); } 156 / ** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */176 /// Returns the end-iterator of the direct-parents-list. 157 177 inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); } 158 178 159 / ** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */179 /// Returns the direct children the class the Identifier belongs to. 160 180 inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; } 161 / ** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */181 /// Returns the begin-iterator of the direct-children-list. 162 182 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); } 163 / ** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */183 /// Returns the end-iterator of the direct-children-list. 164 184 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); } 165 185 … … 176 196 static void clearNetworkIDs(); 177 197 178 / ** @brief Returns the map that stores all Identifiers with their names. @return The map */198 /// Returns the map that stores all Identifiers with their names. 179 199 static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); } 180 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */200 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. 181 201 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); } 182 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */202 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names. 183 203 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); } 184 204 185 / ** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */205 /// Returns the map that stores all Identifiers with their names in lowercase. 186 206 static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); } 187 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */207 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. 188 208 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); } 189 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */209 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. 190 210 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); } 191 211 192 / ** @brief Returns the map that stores all Identifiers with their IDs. @return The map */212 /// Returns the map that stores all Identifiers with their IDs. 193 213 static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); } 194 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */214 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. 195 215 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); } 196 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */216 /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. 197 217 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); } 198 218 … … 203 223 virtual void updateConfigValues(bool updateChildren = true) const = 0; 204 224 205 / ** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */225 /// Returns true if this class has at least one config value. 206 226 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 207 227 … … 213 233 ///// XMLPort ///// 214 234 /////////////////// 215 / ** @brief Returns the map that stores all XMLPort params. @return The const_iterator */235 /// Returns the map that stores all XMLPort params. 216 236 inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; } 217 / ** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort params. @return The const_iterator */237 /// Returns a const_iterator to the beginning of the map that stores all XMLPort params. 218 238 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); } 219 / ** @brief Returns a const_iterator to the end of the map that stores all XMLPort params. @return The const_iterator */239 /// Returns a const_iterator to the end of the map that stores all XMLPort params. 220 240 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); } 221 241 222 / ** @brief Returns the map that stores all XMLPort objects. @return The const_iterator */242 /// Returns the map that stores all XMLPort objects. 223 243 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; } 224 / ** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort objects. @return The const_iterator */244 /// Returns a const_iterator to the beginning of the map that stores all XMLPort objects. 225 245 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); } 226 / ** @brief Returns a const_iterator to the end of the map that stores all XMLPort objects. @return The const_iterator */246 /// Returns a const_iterator to the end of the map that stores all XMLPort objects. 227 247 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 228 248 … … 244 264 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 245 265 246 / ** @brief Returns the map that stores all Identifiers with their names. @return The map */266 /// Returns the map that stores all Identifiers with their names. 247 267 static std::map<std::string, Identifier*>& getStringIdentifierMapIntern(); 248 / ** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */268 /// Returns the map that stores all Identifiers with their names in lowercase. 249 269 static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern(); 250 / ** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */270 /// Returns the map that stores all Identifiers with their network IDs. 251 271 static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern(); 252 272 253 / ** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */273 /// Returns the children of the class the Identifier belongs to. 254 274 inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; } 255 / ** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */275 /// Returns the direct children of the class the Identifier belongs to. 256 276 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; } 257 277 … … 259 279 260 280 private: 261 / ** @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. */281 /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 262 282 inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; } 263 / ** @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. */283 /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 264 284 inline static void stopCreatingHierarchy() { hierarchyCreatingCounter_s--; } 265 285 … … 297 317 // ### ClassIdentifier ### 298 318 // ############################### 299 //! The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 300 /** 301 ClassIdentifier is a Singleton, which means that only one object of a given type T exists. 319 /** 320 @brief The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 321 322 ClassIdentifier is a Singleton, which means that only one ClassIdentifier for a given type T exists. 302 323 This makes it possible to store information about a class, sharing them with all 303 324 objects of that class without defining static variables in every class. 304 325 305 326 To be really sure that not more than exactly one object exists (even with libraries), 306 ClassIdentifiers are stored in the Identifier Singleton.327 ClassIdentifiers are stored in a static map in Identifier. 307 328 */ 308 329 template <class T>
Note: See TracChangeset
for help on using the changeset viewer.