Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 7, 2010, 12:58:52 AM (14 years ago)
Author:
landauf
Message:

enhanced documentation of some core classes and added examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/doc/src/libraries/core/Identifier.h

    r7363 r7372  
    3535    @file
    3636    @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
    5377*/
    5478
     
    76100    // ###       Identifier        ###
    77101    // ###############################
    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>.
    92112    */
    93113    class _CoreExport Identifier
    94114    {
    95115        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.
    97117            inline const std::string& getName() const { return this->name_; }
    98118            void setName(const std::string& name);
    99119
    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.
    101121            inline const uint32_t getNetworkID() const { return this->networkID_; }
    102122            void setNetworkID(uint32_t id);
    103123
    104             /** @brief Returns the unique ID of the class */
     124            /// Returns the unique ID of the class.
    105125            FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    106126
    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.
    108128            inline ObjectListBase* getObjects() const { return this->objects_; }
    109129
    110             /** @brief Sets the Factory. @param factory The factory to assign */
     130            /// Sets the Factory.
    111131            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.
    113133            inline bool hasFactory() const { return (this->factory_ != 0); }
    114134
    115135            BaseObject* fabricate(BaseObject* creator);
    116136
    117             /** @brief Returns true if the class can be loaded through XML. */
     137            /// Returns true if the class can be loaded through XML.
    118138            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.
    120140            inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
    121141
     
    133153            static void createClassHierarchy();
    134154
    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.
    136156            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    137157
    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.
    139159            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.
    141161            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.
    143163            inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
    144164
    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.
    146166            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.
    148168            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.
    150170            inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); }
    151171
    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.
    153173            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.
    155175            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.
    157177            inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
    158178
    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.
    160180            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.
    162182            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.
    164184            inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
    165185
     
    176196            static void clearNetworkIDs();
    177197
    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.
    179199            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.
    181201            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.
    183203            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
    184204
    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.
    186206            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.
    188208            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.
    190210            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
    191211
    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.
    193213            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.
    195215            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.
    197217            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
    198218
     
    203223            virtual void updateConfigValues(bool updateChildren = true) const = 0;
    204224
    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.
    206226            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
    207227
     
    213233            ///// XMLPort /////
    214234            ///////////////////
    215             /** @brief Returns the map that stores all XMLPort params. @return The const_iterator */
     235            /// Returns the map that stores all XMLPort params.
    216236            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.
    218238            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.
    220240            inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); }
    221241
    222             /** @brief Returns the map that stores all XMLPort objects. @return The const_iterator */
     242            /// Returns the map that stores all XMLPort objects.
    223243            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.
    225245            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.
    227247            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    228248
     
    244264            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    245265
    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.
    247267            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.
    249269            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.
    251271            static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
    252272
    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.
    254274            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.
    256276            inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
    257277
     
    259279
    260280        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.
    262282            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.
    264284            inline static void stopCreatingHierarchy()  { hierarchyCreatingCounter_s--; }
    265285
     
    297317    // ###     ClassIdentifier     ###
    298318    // ###############################
    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.
    302323        This makes it possible to store information about a class, sharing them with all
    303324        objects of that class without defining static variables in every class.
    304325
    305326        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.
    307328    */
    308329    template <class T>
Note: See TracChangeset for help on using the changeset viewer.