Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 12, 2007, 10:37:30 PM (17 years ago)
Author:
landauf
Message:

added files from objecthierarchy, changed includes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/orxonox/core/Identifier.h

    r384 r496  
    11/*!
    22    @file Identifier.h
    3     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes.
     3    @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
    44
    55    The Identifier contains all needed informations about the class it belongs to:
     
    77     - a list with all objects
    88     - parents and childs
    9      - the factory, if available
     9     - the factory (if available)
    1010     - the networkID that can be synchronised with the server
     11     - all configurable variables (if available)
    1112
    1213    Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    1819
    1920    SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.
    20     You can only assign Identifiers of the given class or a derivative to a SubclassIdentifier.
     21    You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.
    2122*/
    2223
     
    2526
    2627#include <iostream>
     28#include <map>
    2729
    2830#include "IdentifierList.h"
    2931#include "ObjectList.h"
    3032#include "Factory.h"
    31 
    32 #define HIERARCHY_VERBOSE false
    33 
     33#include "ConfigValueContainer.h"
     34#include "Debug.h"
    3435
    3536namespace orxonox
     
    4647         - a list with all objects
    4748         - parents and childs
    48          - the factory, if available
     49         - the factory (if available)
    4950         - the networkID that can be synchronised with the server
     51         - all configurable variables (if available)
    5052
    5153        Every object has a pointer to the Identifier of its class. This allows the use isA(...),
     
    6264        friend class SubclassIdentifier; // Forward declaration
    6365
    64         template <class T>
    65         friend class ClassFactory; // Forward declaration
     66        friend class Factory; // Forward declaration
    6667
    6768        public:
     
    8586            inline IdentifierList& getChildren() const { return *this->children_; }
    8687
    87             /** @returns true, if a branch of the class-hierarchy is getting created, causing all new objects to store their parents. */
     88            /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */
    8889            inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    8990
    90             /** @returns the NetworkID to identify a class through the network. */
     91            /** @returns the network ID to identify a class through the network. */
    9192            inline const unsigned int getNetworkID() const { return this->classID_; }
    9293
     94            /** @brief Sets the network ID to a new value. @param id The new value */
    9395            void setNetworkID(unsigned int id);
     96
     97            /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */
     98            inline ConfigValueContainer* getConfigValueContainer(const std::string& varname)
     99                { return this->configValues_[varname]; }
     100
     101            /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */
     102            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
     103                { this->configValues_[varname] = container; }
    94104
    95105        private:
     
    105115            {
    106116                hierarchyCreatingCounter_s++;
    107 #if HIERARCHY_VERBOSE
    108                 std::cout << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    109 #endif
     117                COUT(4) << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    110118            }
    111119
     
    116124            {
    117125                hierarchyCreatingCounter_s--;
    118 #if HIERARCHY_VERBOSE
    119                 std::cout << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
    120 #endif
    121             }
    122 
    123             IdentifierList parents_;                    //!< The Parents of the class the Identifier belongs to
    124             IdentifierList* children_;                  //!< The Children of the class the Identifier belongs to
    125 
    126             std::string name_;                          //!< The name of the class the Identifier belongs to
    127 
    128             BaseFactory* factory_;                      //!< The Factory, able to create new objects of the given class
    129             bool bCreatedOneObject_;                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    130             static int hierarchyCreatingCounter_s;      //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
    131             static unsigned int classIDcounter_s;       //!< The number of unique Identifiers
    132             unsigned int classID_;                      //!< The networkID to identify a class through the network
     126                COUT(4) << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << "\n";
     127            }
     128
     129            IdentifierList parents_;                                    //!< The Parents of the class the Identifier belongs to
     130            IdentifierList* children_;                                  //!< The Children of the class the Identifier belongs to
     131
     132            std::string name_;                                          //!< The name of the class the Identifier belongs to
     133
     134            BaseFactory* factory_;                                      //!< The Factory, able to create new objects of the given class (if available)
     135            bool bCreatedOneObject_;                                    //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
     136            static int hierarchyCreatingCounter_s;                      //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading)
     137            static unsigned int classIDcounter_s;                       //!< The number of existing Identifiers
     138            unsigned int classID_;                                      //!< The network ID to identify a class through the network
     139            std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
    133140    };
    134141
     
    164171
    165172    /**
    166         @brief Constructor: Create the ObjectList.
     173        @brief Constructor: Creates the ObjectList.
    167174    */
    168175    template <class T>
     
    173180
    174181    /**
    175         @brief Destructor: Delete the ObjectList, set the singleton-pointer to zero.
     182        @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero.
    176183    */
    177184    template <class T>
     
    186193        @param parents An IdentifierList, containing the Identifiers of all parents of the class
    187194        @param name A string, containing exactly the name of the class
    188         @param bRootClass True if the class is either an Interface or BaseObject itself
     195        @param bRootClass True if the class is either an Interface or the BaseObject itself
    189196        @return The ClassIdentifier itself
    190197    */
     
    192199    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass)
    193200    {
    194 #if HIERARCHY_VERBOSE
    195         std::cout << "*** Register Class in " << name << "-Singleton.\n";
    196 #endif
     201        COUT(4) << "*** Register Class in " << name << "-Singleton.\n";
    197202
    198203        // It's a singleton, so maybe we have to create it first
    199204        if (!pointer_s)
    200205        {
    201 #if HIERARCHY_VERBOSE
    202             std::cout << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";
    203 #endif
     206            COUT(4) << "*** Register Class in " << name << "-Singleton -> Create Singleton.\n";
    204207            pointer_s = new ClassIdentifier();
    205208        }
     
    210213            // If no: We have to store the informations and initialize the Identifier
    211214
    212 #if HIERARCHY_VERBOSE
    213             std::cout << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n";
    214 #endif
     215            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n";
    215216            pointer_s->name_ = name;
    216             Factory::add(name, pointer_s); // Add the Identifier to the Factory
     217//            Factory::add(name, pointer_s); // Add the Identifier to the Factory
    217218
    218219            if (bRootClass)
     
    226227
    227228    /**
    228         @returns the Identifier itself
     229        @returns the Identifier itself.
    229230    */
    230231    template <class T>
     
    233234        if (!pointer_s)
    234235        {
    235 #if HIERARCHY_VERBOSE
    236             std::cout << "*** Create Singleton.\n";
    237 #endif
     236            COUT(4) << "*** Create Singleton.\n";
    238237            pointer_s = new ClassIdentifier();
    239238        }
     
    249248    void ClassIdentifier<T>::addObject(T* object)
    250249    {
    251 #if HIERARCHY_VERBOSE
    252         std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    253 #endif
     250        COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n";
    254251        object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));
    255252    }
     
    261258    //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.
    262259    /**
    263         You can only assign Identifiers that belong to a class of at least B (or derived) to a SubclassIdentifier<T>.
     260        You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.
    264261        If you assign something else, the program aborts.
    265262        Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object.
     
    286283                if (!identifier->isA(ClassIdentifier<T>::getIdentifier()))
    287284                {
    288                     std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
    289                     std::cout << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";
    290                     std::cout << "Aborting...\n";
     285                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
     286                    COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";
     287                    COUT(1) << "Aborting...\n";
    291288                    abort();
    292289                }
     
    314311
    315312            /**
    316                 @brief Creates a new object of the type of the assigned identifier and dynamic_casts it to the minimal type given by the SubclassIdentifier.
     313                @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    317314                @return The new object
    318315            */
     
    321318                BaseObject* newObject = this->identifier_->fabricate();
    322319
    323                 // Check if the creation worked
     320                // Check if the creation was successful
    324321                if (newObject)
    325322                {
     
    332329                    if (this->identifier_)
    333330                    {
    334                         std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
    335                         std::cout << "Error: Couldn't fabricate a new Object.\n";
    336                         std::cout << "Aborting...\n";
     331                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n";
     332                        COUT(1) << "Error: Couldn't fabricate a new Object.\n";
     333                        COUT(1) << "Aborting...\n";
    337334                    }
    338335                    else
    339336                    {
    340                         std::cout << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";
    341                         std::cout << "Aborting...\n";
     337                        COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined.\n";
     338                        COUT(1) << "Aborting...\n";
    342339                    }
    343340
Note: See TracChangeset for help on using the changeset viewer.