Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9564 for code/branches


Ignore:
Timestamp:
Mar 24, 2013, 6:08:42 PM (12 years ago)
Author:
landauf
Message:

moved static functions from Identifier.cc/h to IdentifierManager.cc/h (still static though)

Location:
code/branches/core6/src/libraries
Files:
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/Core.cc

    r9563 r9564  
    198198        // creates the class hierarchy for all classes with factories
    199199        orxout(internal_info) << "creating class hierarchy" << endl;
    200         Identifier::createClassHierarchy();
     200        IdentifierManager::createClassHierarchy();
    201201
    202202        // Load OGRE excluding the renderer and the render window
     
    248248        safeObjectDelete(&configFileManager_);
    249249        ConsoleCommand::destroyAll();
    250         Identifier::destroyAllIdentifiers();
     250        IdentifierManager::destroyAllIdentifiers();
    251251        safeObjectDelete(&signalHandler_);
    252252        safeObjectDelete(&dynLibManager_);
  • code/branches/core6/src/libraries/core/CoreIncludes.h

    r9563 r9564  
    7979
    8080#include "util/Output.h"
    81 #include "class/Identifier.h"
     81#include "class/IdentifierManager.h"
    8282#include "object/ClassFactory.h"
    8383#include "object/ObjectList.h"
     
    142142    inline Identifier* ClassByString(const std::string& name)
    143143    {
    144         return Identifier::getIdentifierByString(name);
     144        return IdentifierManager::getIdentifierByString(name);
    145145    }
    146146
     
    151151    inline Identifier* ClassByLowercaseString(const std::string& name)
    152152    {
    153         return Identifier::getIdentifierByLowercaseString(name);
     153        return IdentifierManager::getIdentifierByLowercaseString(name);
    154154    }
    155155
     
    160160    inline Identifier* ClassByID(uint32_t id)
    161161    {
    162         return Identifier::getIdentifierByID(id);
     162        return IdentifierManager::getIdentifierByID(id);
    163163    }
    164164
  • code/branches/core6/src/libraries/core/Template.cc

    r9348 r9564  
    150150
    151151        // check if the template is applied on an object of the right type
    152         Identifier* identifier = Identifier::getIdentifierByString(this->getXMLElement().Value());
     152        Identifier* identifier = IdentifierManager::getIdentifierByString(this->getXMLElement().Value());
    153153        if (!object->getIdentifier()->isA(identifier))
    154154            orxout(internal_warning, context::templates) << "Template was defined for " << identifier->getName() << " but the object is of type " << object->getIdentifier()->getName() << endl;
  • code/branches/core6/src/libraries/core/XMLPort.cc

    r9556 r9564  
    5959                for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)
    6060                {
    61                     Identifier* identifier = Identifier::getIdentifierByString(child->Value());
     61                    Identifier* identifier = IdentifierManager::getIdentifierByString(child->Value());
    6262                    if (!identifier)
    6363                    {
  • code/branches/core6/src/libraries/core/class/CMakeLists.txt

    r9563 r9564  
    11ADD_SOURCE_FILES(CORE_SRC_FILES
    22  Identifier.cc
     3  IdentifierManager.cc
    34  OrxonoxClass.cc
    45)
  • code/branches/core6/src/libraries/core/class/Identifier.cc

    r9563 r9564  
    4646    // ###       Identifier        ###
    4747    // ###############################
    48     int Identifier::hierarchyCreatingCounter_s = 0;
    49     unsigned int Identifier::classIDCounter_s = 0;
    50 
    5148    /**
    5249        @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
    5350    */
    5451    Identifier::Identifier()
    55         : classID_(classIDCounter_s++)
     52        : classID_(IdentifierManager::classIDCounter_s++)
    5653    {
    5754        this->objects_ = new ObjectListBase(this);
     
    8784
    8885    /**
    89         @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
    90     */
    91     std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
    92     {
    93         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    94         return identifiers;
    95     }
    96 
    97     /**
    98         @brief Returns an identifier by name and adds it if not available
    99         @param name The name of the identifier as typeid().name() suggests
    100         @param proposal A pointer to a newly created identifier for the case of non existence in the map
    101         @return The identifier (unique instance)
    102     */
    103     Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    104     {
    105         std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
    106 
    107         if (it != getTypeIDIdentifierMap().end())
    108         {
    109             // There is already an entry: return it and delete the proposal
    110             delete proposal;
    111             return it->second;
    112         }
    113         else
    114         {
    115             // There is no entry: put the proposal into the map and return it
    116             getTypeIDIdentifierMap()[name] = proposal;
    117             return proposal;
    118         }
    119     }
    120 
    121     /**
    12286        @brief Registers a class, which means that the name and the parents get stored.
    12387        @param parents A list, containing the Identifiers of all parents of the class
     
    12791    {
    12892        // Check if at least one object of the given type was created
    129         if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
     93        if (!this->bCreatedOneObject_ && IdentifierManager::isCreatingHierarchy())
    13094        {
    13195            // If no: We have to store the information and initialize the Identifier
     
    187151
    188152    /**
    189         @brief Creates the class-hierarchy by creating and destroying one object of each type.
    190     */
    191     void Identifier::createClassHierarchy()
    192     {
    193         orxout(internal_status) << "Create class-hierarchy" << endl;
    194         Identifier::startCreatingHierarchy();
    195         for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
    196         {
    197             // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
    198             if (it->second->hasFactory())
    199             {
    200                 OrxonoxClass* temp = it->second->fabricate(0);
    201                 temp->destroy();
    202             }
    203         }
    204         Identifier::stopCreatingHierarchy();
    205         orxout(internal_status) << "Finished class-hierarchy creation" << endl;
    206     }
    207 
    208     /**
    209         @brief Destroys all Identifiers. Called when exiting the program.
    210     */
    211     void Identifier::destroyAllIdentifiers()
    212     {
    213         for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
    214             delete (it->second);
    215     }
    216 
    217     /**
    218153        @brief Sets the name of the class.
    219154    */
     
    224159            this->name_ = name;
    225160            this->bSetName_ = true;
    226             Identifier::getStringIdentifierMapIntern()[name] = this;
    227             Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
    228             Identifier::getIDIdentifierMapIntern()[this->networkID_] = this;
     161            IdentifierManager::getStringIdentifierMapIntern()[name] = this;
     162            IdentifierManager::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
     163            IdentifierManager::getIDIdentifierMapIntern()[this->networkID_] = this;
    229164        }
    230165    }
     
    256191    {
    257192//        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
    258         Identifier::getIDIdentifierMapIntern()[id] = this;
     193        IdentifierManager::getIDIdentifierMapIntern()[id] = this;
    259194        this->networkID_ = id;
    260195    }
     
    312247    {
    313248        return (this->directChildren_.find(identifier) != this->directChildren_.end());
    314     }
    315 
    316     /**
    317         @brief Returns the map that stores all Identifiers with their names.
    318         @return The map
    319     */
    320     std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
    321     {
    322         static std::map<std::string, Identifier*> identifierMap;
    323         return identifierMap;
    324     }
    325 
    326     /**
    327         @brief Returns the map that stores all Identifiers with their names in lowercase.
    328         @return The map
    329     */
    330     std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
    331     {
    332         static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    333         return lowercaseIdentifierMap;
    334     }
    335 
    336     /**
    337         @brief Returns the map that stores all Identifiers with their network IDs.
    338         @return The map
    339     */
    340     std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
    341     {
    342         static std::map<uint32_t, Identifier*> identifierMap;
    343         return identifierMap;
    344     }
    345 
    346     /**
    347         @brief Returns the Identifier with a given name.
    348         @param name The name of the wanted Identifier
    349         @return The Identifier
    350     */
    351     Identifier* Identifier::getIdentifierByString(const std::string& name)
    352     {
    353         std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
    354         if (it != Identifier::getStringIdentifierMapIntern().end())
    355             return it->second;
    356         else
    357             return 0;
    358     }
    359 
    360     /**
    361         @brief Returns the Identifier with a given name in lowercase.
    362         @param name The name of the wanted Identifier
    363         @return The Identifier
    364     */
    365     Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
    366     {
    367         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
    368         if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
    369             return it->second;
    370         else
    371             return 0;
    372     }
    373 
    374     /**
    375         @brief Returns the Identifier with a given network ID.
    376         @param id The network ID of the wanted Identifier
    377         @return The Identifier
    378     */
    379     Identifier* Identifier::getIdentifierByID(const uint32_t id)
    380     {
    381         std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id);
    382         if (it != Identifier::getIDIdentifierMapIntern().end())
    383             return it->second;
    384         else
    385             return 0;
    386     }
    387 
    388     /**
    389         @brief Cleans the NetworkID map (needed on clients for correct initialization)
    390     */
    391     void Identifier::clearNetworkIDs()
    392     {
    393         Identifier::getIDIdentifierMapIntern().clear();
    394249    }
    395250
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9563 r9564  
    9393#include "core/object/ObjectList.h"
    9494#include "core/object/ObjectListBase.h"
     95#include "IdentifierManager.h"
    9596#include "Super.h"
    9697
     
    113114    class _CoreExport Identifier
    114115    {
     116        friend class IdentifierManager;
     117
    115118        public:
    116119            /// Returns the name of the class the Identifier belongs to.
     
    151154            ////// Class Hierarchy //////
    152155            /////////////////////////////
    153             static void createClassHierarchy();
    154 
    155             /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
    156             inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    157 
    158156            /// Returns the parents of the class the Identifier belongs to.
    159157            inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
     
    183181            /// Returns the end-iterator of the direct-children-list.
    184182            inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
    185 
    186 
    187             //////////////////////////
    188             ///// Identifier Map /////
    189             //////////////////////////
    190             static void destroyAllIdentifiers();
    191 
    192             static Identifier* getIdentifierByString(const std::string& name);
    193             static Identifier* getIdentifierByLowercaseString(const std::string& name);
    194             static Identifier* getIdentifierByID(uint32_t id);
    195 
    196             static void clearNetworkIDs();
    197 
    198             /// Returns the map that stores all Identifiers with their names.
    199             static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
    200             /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names.
    201             static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
    202             /// Returns a const_iterator to the end of the map that stores all Identifiers with their names.
    203             static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
    204 
    205             /// Returns the map that stores all Identifiers with their names in lowercase.
    206             static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
    207             /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase.
    208             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
    209             /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase.
    210             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
    211 
    212             /// Returns the map that stores all Identifiers with their IDs.
    213             static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
    214             /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs.
    215             static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
    216             /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs.
    217             static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
    218183
    219184
     
    259224            virtual ~Identifier();
    260225
    261             static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    262226            virtual void createSuperFunctionCaller() const = 0;
    263227
    264228            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    265 
    266             /// Returns the map that stores all Identifiers with their names.
    267             static std::map<std::string, Identifier*>& getStringIdentifierMapIntern();
    268             /// Returns the map that stores all Identifiers with their names in lowercase.
    269             static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern();
    270             /// Returns the map that stores all Identifiers with their network IDs.
    271             static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
    272229
    273230            /// Returns the children of the class the Identifier belongs to.
     
    279236
    280237        private:
    281             /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
    282             inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; }
    283             /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
    284             inline static void stopCreatingHierarchy()  { hierarchyCreatingCounter_s--; }
    285 
    286             static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
    287 
    288238            void initialize(std::set<const Identifier*>* parents);
    289239
     
    299249            std::string name_;                                             //!< The name of the class the Identifier belongs to
    300250            Factory* factory_;                                             //!< The Factory, able to create new objects of the given class (if available)
    301             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)
    302251            uint32_t networkID_;                                           //!< The network ID to identify a class through the network
    303252            const unsigned int classID_;                                   //!< Uniquely identifies a class (might not be the same as the networkID_)
    304             static unsigned int classIDCounter_s;                          //!< Static counter for the unique classIDs
    305253
    306254            bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
     
    401349
    402350        // Get the entry from the map
    403         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
     351        ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getIdentifierSingleton(name, proposal);
    404352
    405353        if (ClassIdentifier<T>::classIdentifier_s == proposal)
     
    428376
    429377        object->identifier_ = this;
    430         if (Identifier::isCreatingHierarchy())
     378        if (IdentifierManager::isCreatingHierarchy())
    431379        {
    432380            if (bRootClass && !object->parents_)
  • code/branches/core6/src/libraries/core/class/IdentifierManager.cc

    r9563 r9564  
    3232*/
    3333
    34 #include "Identifier.h"
     34#include "IdentifierManager.h"
    3535
    3636#include <ostream>
     
    4343namespace orxonox
    4444{
    45     // ###############################
    46     // ###       Identifier        ###
    47     // ###############################
    48     int Identifier::hierarchyCreatingCounter_s = 0;
    49     unsigned int Identifier::classIDCounter_s = 0;
    50 
    51     /**
    52         @brief Constructor: No factory, no object created, new ObjectList and a unique networkID.
    53     */
    54     Identifier::Identifier()
    55         : classID_(classIDCounter_s++)
    56     {
    57         this->objects_ = new ObjectListBase(this);
    58 
    59         this->bCreatedOneObject_ = false;
    60         this->bSetName_ = false;
    61         this->factory_ = 0;
    62         this->bLoadable_ = false;
    63 
    64         this->bHasConfigValues_ = false;
    65 
    66         // Default network ID is the class ID
    67         this->networkID_ = this->classID_;
    68     }
    69 
    70     /**
    71         @brief Destructor: Deletes the list containing the children.
    72     */
    73     Identifier::~Identifier()
    74     {
    75         delete this->objects_;
    76 
    77         if (this->factory_)
    78             delete this->factory_;
    79 
    80         for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it)
    81             delete (it->second);
    82         for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it)
    83             delete (it->second);
    84         for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
    85             delete (it->second);
    86     }
     45    int IdentifierManager::hierarchyCreatingCounter_s = 0;
     46    unsigned int IdentifierManager::classIDCounter_s = 0;
    8747
    8848    /**
    8949        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
    9050    */
    91     std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
     51    std::map<std::string, Identifier*>& IdentifierManager::getTypeIDIdentifierMap()
    9252    {
    9353        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
     
    10161        @return The identifier (unique instance)
    10262    */
    103     Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
     63    Identifier* IdentifierManager::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    10464    {
    10565        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     
    12080
    12181    /**
    122         @brief Registers a class, which means that the name and the parents get stored.
    123         @param parents A list, containing the Identifiers of all parents of the class
    124         @param bRootClass True if the class is either an Interface or the BaseObject itself
    125     */
    126     void Identifier::initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass)
    127     {
    128         // Check if at least one object of the given type was created
    129         if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
    130         {
    131             // If no: We have to store the information and initialize the Identifier
    132             orxout(verbose, context::identifier) << "Register Class in ClassIdentifier<" << this->getName() << ">-Singleton -> Initialize Singleton." << endl;
    133             if (bRootClass)
    134                 this->initialize(0); // 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.
    135             else
    136                 this->initialize(parents);
    137         }
    138     }
    139 
    140     /**
    141         @brief Initializes the Identifier with a list containing all parents of the class the Identifier belongs to.
    142         @param parents A list containing all parents
    143     */
    144     void Identifier::initialize(std::set<const Identifier*>* parents)
    145     {
    146         orxout(verbose, context::identifier) << "Initialize ClassIdentifier<" << this->name_ << ">-Singleton." << endl;
    147         this->bCreatedOneObject_ = true;
    148 
    149         if (parents)
    150         {
    151             this->parents_ = (*parents);
    152             this->directParents_ = (*parents);
    153 
    154             // Iterate through all parents
    155             for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)
    156             {
    157                 // Tell the parent we're one of it's children
    158                 (*it)->children_.insert((*it)->children_.end(), this);
    159 
    160                 // Erase all parents of our parent from our direct-parent-list
    161                 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)
    162                 {
    163                     // Search for the parent's parent in our direct-parent-list
    164                     for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)
    165                     {
    166                         if ((*it1) == (*it2))
    167                         {
    168                             // We've found a non-direct parent in our list: Erase it
    169                             this->directParents_.erase(it2);
    170                             break;
    171                         }
    172                     }
    173                 }
    174             }
    175 
    176             // Now iterate through all direct parents
    177             for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)
    178             {
    179                 // Tell the parent we're one of it's direct children
    180                 (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
    181 
    182                 // Create the super-function dependencies
    183                 (*it)->createSuperFunctionCaller();
    184             }
    185         }
    186     }
    187 
    188     /**
    18982        @brief Creates the class-hierarchy by creating and destroying one object of each type.
    19083    */
    191     void Identifier::createClassHierarchy()
     84    void IdentifierManager::createClassHierarchy()
    19285    {
    19386        orxout(internal_status) << "Create class-hierarchy" << endl;
    194         Identifier::startCreatingHierarchy();
    195         for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
     87        IdentifierManager::startCreatingHierarchy();
     88        for (std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMap().begin(); it != IdentifierManager::getStringIdentifierMap().end(); ++it)
    19689        {
    19790            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     
    20295            }
    20396        }
    204         Identifier::stopCreatingHierarchy();
     97        IdentifierManager::stopCreatingHierarchy();
    20598        orxout(internal_status) << "Finished class-hierarchy creation" << endl;
    20699    }
     
    209102        @brief Destroys all Identifiers. Called when exiting the program.
    210103    */
    211     void Identifier::destroyAllIdentifiers()
     104    void IdentifierManager::destroyAllIdentifiers()
    212105    {
    213         for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
     106        for (std::map<std::string, Identifier*>::iterator it = IdentifierManager::getTypeIDIdentifierMap().begin(); it != IdentifierManager::getTypeIDIdentifierMap().end(); ++it)
    214107            delete (it->second);
    215     }
    216 
    217     /**
    218         @brief Sets the name of the class.
    219     */
    220     void Identifier::setName(const std::string& name)
    221     {
    222         if (!this->bSetName_)
    223         {
    224             this->name_ = name;
    225             this->bSetName_ = true;
    226             Identifier::getStringIdentifierMapIntern()[name] = this;
    227             Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
    228             Identifier::getIDIdentifierMapIntern()[this->networkID_] = this;
    229         }
    230     }
    231 
    232     /**
    233         @brief Creates an object of the type the Identifier belongs to.
    234         @return The new object
    235     */
    236     OrxonoxClass* Identifier::fabricate(BaseObject* creator)
    237     {
    238         if (this->factory_)
    239         {
    240             return this->factory_->fabricate(creator);
    241         }
    242         else
    243         {
    244             orxout(user_error) << "An error occurred in Identifier.cc:" << endl;
    245             orxout(user_error) << "Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << endl;
    246             orxout(user_error) << "Aborting..." << endl;
    247             abort();
    248             return 0;
    249         }
    250     }
    251 
    252     /**
    253         @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map.
    254     */
    255     void Identifier::setNetworkID(uint32_t id)
    256     {
    257 //        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
    258         Identifier::getIDIdentifierMapIntern()[id] = this;
    259         this->networkID_ = id;
    260     }
    261 
    262     /**
    263         @brief Returns true, if the Identifier is at least of the given type.
    264         @param identifier The identifier to compare with
    265     */
    266     bool Identifier::isA(const Identifier* identifier) const
    267     {
    268         return (identifier == this || (this->parents_.find(identifier) != this->parents_.end()));
    269     }
    270 
    271     /**
    272         @brief Returns true, if the Identifier is exactly of the given type.
    273         @param identifier The identifier to compare with
    274     */
    275     bool Identifier::isExactlyA(const Identifier* identifier) const
    276     {
    277         return (identifier == this);
    278     }
    279 
    280     /**
    281         @brief Returns true, if the assigned identifier is a child of the given identifier.
    282         @param identifier The identifier to compare with
    283     */
    284     bool Identifier::isChildOf(const Identifier* identifier) const
    285     {
    286         return (this->parents_.find(identifier) != this->parents_.end());
    287     }
    288 
    289     /**
    290         @brief Returns true, if the assigned identifier is a direct child of the given identifier.
    291         @param identifier The identifier to compare with
    292     */
    293     bool Identifier::isDirectChildOf(const Identifier* identifier) const
    294     {
    295         return (this->directParents_.find(identifier) != this->directParents_.end());
    296     }
    297 
    298     /**
    299         @brief Returns true, if the assigned identifier is a parent of the given identifier.
    300         @param identifier The identifier to compare with
    301     */
    302     bool Identifier::isParentOf(const Identifier* identifier) const
    303     {
    304         return (this->children_.find(identifier) != this->children_.end());
    305     }
    306 
    307     /**
    308         @brief Returns true, if the assigned identifier is a direct parent of the given identifier.
    309         @param identifier The identifier to compare with
    310     */
    311     bool Identifier::isDirectParentOf(const Identifier* identifier) const
    312     {
    313         return (this->directChildren_.find(identifier) != this->directChildren_.end());
    314108    }
    315109
     
    318112        @return The map
    319113    */
    320     std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
     114    std::map<std::string, Identifier*>& IdentifierManager::getStringIdentifierMapIntern()
    321115    {
    322116        static std::map<std::string, Identifier*> identifierMap;
     
    328122        @return The map
    329123    */
    330     std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
     124    std::map<std::string, Identifier*>& IdentifierManager::getLowercaseStringIdentifierMapIntern()
    331125    {
    332126        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
     
    338132        @return The map
    339133    */
    340     std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
     134    std::map<uint32_t, Identifier*>& IdentifierManager::getIDIdentifierMapIntern()
    341135    {
    342136        static std::map<uint32_t, Identifier*> identifierMap;
     
    349143        @return The Identifier
    350144    */
    351     Identifier* Identifier::getIdentifierByString(const std::string& name)
     145    Identifier* IdentifierManager::getIdentifierByString(const std::string& name)
    352146    {
    353         std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
    354         if (it != Identifier::getStringIdentifierMapIntern().end())
     147        std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapIntern().find(name);
     148        if (it != IdentifierManager::getStringIdentifierMapIntern().end())
    355149            return it->second;
    356150        else
     
    363157        @return The Identifier
    364158    */
    365     Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
     159    Identifier* IdentifierManager::getIdentifierByLowercaseString(const std::string& name)
    366160    {
    367         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
    368         if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
     161        std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getLowercaseStringIdentifierMapIntern().find(name);
     162        if (it != IdentifierManager::getLowercaseStringIdentifierMapIntern().end())
    369163            return it->second;
    370164        else
     
    377171        @return The Identifier
    378172    */
    379     Identifier* Identifier::getIdentifierByID(const uint32_t id)
     173    Identifier* IdentifierManager::getIdentifierByID(const uint32_t id)
    380174    {
    381         std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id);
    382         if (it != Identifier::getIDIdentifierMapIntern().end())
     175        std::map<uint32_t, Identifier*>::const_iterator it = IdentifierManager::getIDIdentifierMapIntern().find(id);
     176        if (it != IdentifierManager::getIDIdentifierMapIntern().end())
    383177            return it->second;
    384178        else
     
    389183        @brief Cleans the NetworkID map (needed on clients for correct initialization)
    390184    */
    391     void Identifier::clearNetworkIDs()
     185    void IdentifierManager::clearNetworkIDs()
    392186    {
    393         Identifier::getIDIdentifierMapIntern().clear();
    394     }
    395 
    396     /**
    397         @brief Adds the ConfigValueContainer of a variable, given by the string of its name.
    398         @param varname The name of the variablee
    399         @param container The container
    400     */
    401     void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
    402     {
    403         std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname);
    404         if (it != this->configValues_.end())
    405         {
    406             orxout(internal_warning) << "Overwriting config-value with name " << varname << " in class " << this->getName() << '.' << endl;
    407             delete (it->second);
    408         }
    409 
    410         this->bHasConfigValues_ = true;
    411         this->configValues_[varname] = container;
    412     }
    413 
    414     /**
    415         @brief Returns the ConfigValueContainer of a variable, given by the string of its name.
    416         @param varname The name of the variable
    417         @return The ConfigValueContainer
    418     */
    419     ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname)
    420     {
    421         std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
    422         if (it != configValues_.end())
    423             return it->second;
    424         else
    425             return 0;
    426     }
    427 
    428     /**
    429         @brief Returns a XMLPortParamContainer that loads a parameter of this class.
    430         @param paramname The name of the parameter
    431         @return The container
    432     */
    433     XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname)
    434     {
    435         std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname);
    436         if (it != this->xmlportParamContainers_.end())
    437             return it->second;
    438         else
    439             return 0;
    440     }
    441 
    442     /**
    443         @brief Adds a new XMLPortParamContainer that loads a parameter of this class.
    444         @param paramname The name of the parameter
    445         @param container The container
    446     */
    447     void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
    448     {
    449         std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname);
    450         if (it != this->xmlportParamContainers_.end())
    451         {
    452             orxout(internal_warning) << "Overwriting XMLPortParamContainer in class " << this->getName() << '.' << endl;
    453             delete (it->second);
    454         }
    455 
    456         this->xmlportParamContainers_[paramname] = container;
    457     }
    458 
    459     /**
    460         @brief Returns a XMLPortObjectContainer that attaches an object to this class.
    461         @param sectionname The name of the section that contains the attachable objects
    462         @return The container
    463     */
    464     XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname)
    465     {
    466         std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname);
    467         if (it != this->xmlportObjectContainers_.end())
    468             return it->second;
    469         else
    470             return 0;
    471     }
    472 
    473     /**
    474         @brief Adds a new XMLPortObjectContainer that attaches an object to this class.
    475         @param sectionname The name of the section that contains the attachable objects
    476         @param container The container
    477     */
    478     void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
    479     {
    480         std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname);
    481         if (it != this->xmlportObjectContainers_.end())
    482         {
    483             orxout(internal_warning) << "Overwriting XMLPortObjectContainer in class " << this->getName() << '.' << endl;
    484             delete (it->second);
    485         }
    486 
    487         this->xmlportObjectContainers_[sectionname] = container;
    488     }
    489 
    490     /**
    491         @brief Lists the names of all Identifiers in a std::set<const Identifier*>.
    492         @param out The outstream
    493         @param list The list (or set) of Identifiers
    494         @return The outstream
    495     */
    496     std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list)
    497     {
    498         for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    499         {
    500             if (it != list.begin())
    501                 out << ' ';
    502             out << (*it)->getName();
    503         }
    504 
    505         return out;
     187        IdentifierManager::getIDIdentifierMapIntern().clear();
    506188    }
    507189}
  • code/branches/core6/src/libraries/core/class/IdentifierManager.h

    r9563 r9564  
    2828
    2929/**
    30     @defgroup Identifier Identifier
    31     @ingroup Class
     30    @file
     31    @ingroup Class Identifier
    3232*/
    3333
    34 /**
    35     @file
    36     @ingroup Class Identifier
    37     @brief Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object.
    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     OrxonoxClass* 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<MyClass> it = objects.begin(); it != objects.end(); ++it)     // iterate through the objects
    65         ++count;
    66     orxout() << count << 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
    77 */
    78 
    79 #ifndef _Identifier_H__
    80 #define _Identifier_H__
     34#ifndef _IdentifierManager_H__
     35#define _IdentifierManager_H__
    8136
    8237#include "core/CorePrereqs.h"
    8338
    84 #include <cassert>
    8539#include <map>
    86 #include <set>
    8740#include <string>
    88 #include <typeinfo>
    89 #include <loki/TypeTraits.h>
    90 
    91 #include "util/Output.h"
    92 #include "core/object/MetaObjectList.h"
    93 #include "core/object/ObjectList.h"
    94 #include "core/object/ObjectListBase.h"
    95 #include "Super.h"
    9641
    9742namespace orxonox
    9843{
    99     // ###############################
    100     // ###       Identifier        ###
    101     // ###############################
    102     /**
    103         @brief The Identifier is used to identify the class of an object and to store information about the class.
     44    class _CoreExport IdentifierManager
     45    {
     46        friend class Identifier;
     47        template <class T> friend class ClassIdentifier;
    10448
    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>.
    112     */
    113     class _CoreExport Identifier
    114     {
    11549        public:
    116             /// Returns the name of the class the Identifier belongs to.
    117             inline const std::string& getName() const { return this->name_; }
    118             void setName(const std::string& name);
    119 
    120             /// Returns the network ID to identify a class through the network.
    121             inline uint32_t getNetworkID() const { return this->networkID_; }
    122             void setNetworkID(uint32_t id);
    123 
    124             /// Returns the unique ID of the class.
    125             ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; }
    126 
    127             /// Returns the list of all existing objects of this class.
    128             inline ObjectListBase* getObjects() const { return this->objects_; }
    129 
    130             /// Sets the Factory.
    131             inline void addFactory(Factory* factory) { this->factory_ = factory; }
    132             /// Returns true if the Identifier has a Factory.
    133             inline bool hasFactory() const { return (this->factory_ != 0); }
    134 
    135             OrxonoxClass* fabricate(BaseObject* creator);
    136 
    137             /// Returns true if the class can be loaded through XML.
    138             inline bool isLoadable() const { return this->bLoadable_; }
    139             /// Set the class to be loadable through XML or not.
    140             inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }
    141 
    142             bool isA(const Identifier* identifier) const;
    143             bool isExactlyA(const Identifier* identifier) const;
    144             bool isChildOf(const Identifier* identifier) const;
    145             bool isDirectChildOf(const Identifier* identifier) const;
    146             bool isParentOf(const Identifier* identifier) const;
    147             bool isDirectParentOf(const Identifier* identifier) const;
    148 
    149 
    15050            /////////////////////////////
    15151            ////// Class Hierarchy //////
     
    15454
    15555            /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents.
    156             inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
    157 
    158             /// Returns the parents of the class the Identifier belongs to.
    159             inline const std::set<const Identifier*>& getParents() const { return this->parents_; }
    160             /// Returns the begin-iterator of the parents-list.
    161             inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
    162             /// Returns the end-iterator of the parents-list.
    163             inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
    164 
    165             /// Returns the children of the class the Identifier belongs to.
    166             inline const std::set<const Identifier*>& getChildren() const { return this->children_; }
    167             /// Returns the begin-iterator of the children-list.
    168             inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); }
    169             /// Returns the end-iterator of the children-list.
    170             inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); }
    171 
    172             /// Returns the direct parents of the class the Identifier belongs to.
    173             inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; }
    174             /// Returns the begin-iterator of the direct-parents-list.
    175             inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
    176             /// Returns the end-iterator of the direct-parents-list.
    177             inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
    178 
    179             /// Returns the direct children the class the Identifier belongs to.
    180             inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; }
    181             /// Returns the begin-iterator of the direct-children-list.
    182             inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); }
    183             /// Returns the end-iterator of the direct-children-list.
    184             inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); }
     56            inline static bool isCreatingHierarchy()
     57                { return (hierarchyCreatingCounter_s > 0); }
    18558
    18659
     
    19770
    19871            /// Returns the map that stores all Identifiers with their names.
    199             static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); }
     72            static inline const std::map<std::string, Identifier*>& getStringIdentifierMap()
     73                { return IdentifierManager::getStringIdentifierMapIntern(); }
    20074            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names.
    201             static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); }
     75            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin()
     76                { return IdentifierManager::getStringIdentifierMap().begin(); }
    20277            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names.
    203             static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); }
     78            static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd()
     79                { return IdentifierManager::getStringIdentifierMap().end(); }
    20480
    20581            /// Returns the map that stores all Identifiers with their names in lowercase.
    206             static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); }
     82            static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap()
     83                { return IdentifierManager::getLowercaseStringIdentifierMapIntern(); }
    20784            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase.
    208             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); }
     85            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin()
     86                { return IdentifierManager::getLowercaseStringIdentifierMap().begin(); }
    20987            /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase.
    210             static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); }
     88            static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd()
     89                { return IdentifierManager::getLowercaseStringIdentifierMap().end(); }
    21190
    21291            /// Returns the map that stores all Identifiers with their IDs.
    213             static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); }
     92            static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap()
     93                { return IdentifierManager::getIDIdentifierMapIntern(); }
    21494            /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs.
    215             static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); }
     95            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin()
     96                { return IdentifierManager::getIDIdentifierMap().begin(); }
    21697            /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs.
    217             static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); }
    218 
    219 
    220             /////////////////////////
    221             ///// Config Values /////
    222             /////////////////////////
    223             virtual void updateConfigValues(bool updateChildren = true) const = 0;
    224 
    225             /// Returns true if this class has at least one config value.
    226             inline bool hasConfigValues() const { return this->bHasConfigValues_; }
    227 
    228             void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
    229             ConfigValueContainer* getConfigValueContainer(const std::string& varname);
    230 
    231 
    232             ///////////////////
    233             ///// XMLPort /////
    234             ///////////////////
    235             /// Returns the map that stores all XMLPort params.
    236             inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; }
    237             /// Returns a const_iterator to the beginning of the map that stores all XMLPort params.
    238             inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); }
    239             /// Returns a const_iterator to the end of the map that stores all XMLPort params.
    240             inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); }
    241 
    242             /// Returns the map that stores all XMLPort objects.
    243             inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; }
    244             /// Returns a const_iterator to the beginning of the map that stores all XMLPort objects.
    245             inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); }
    246             /// Returns a const_iterator to the end of the map that stores all XMLPort objects.
    247             inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    248 
    249             void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
    250             XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
    251 
    252             void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
    253             XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
    254 
     98            static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd()
     99                { return IdentifierManager::getIDIdentifierMap().end(); }
    255100
    256101        protected:
    257             Identifier();
    258             Identifier(const Identifier& identifier); // don't copy
    259             virtual ~Identifier();
    260 
    261102            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
    262             virtual void createSuperFunctionCaller() const = 0;
    263 
    264             void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    265103
    266104            /// Returns the map that stores all Identifiers with their names.
     
    271109            static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern();
    272110
    273             /// Returns the children of the class the Identifier belongs to.
    274             inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }
    275             /// Returns the direct children of the class the Identifier belongs to.
    276             inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }
    277 
    278             ObjectListBase* objects_;                                      //!< The list of all objects of this class
    279 
    280111        private:
    281112            /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents.
    282             inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; }
     113            inline static void startCreatingHierarchy()
     114                { hierarchyCreatingCounter_s++; }
    283115            /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents.
    284             inline static void stopCreatingHierarchy()  { hierarchyCreatingCounter_s--; }
     116            inline static void stopCreatingHierarchy()
     117                { hierarchyCreatingCounter_s--; }
    285118
    286119            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
    287120
    288             void initialize(std::set<const Identifier*>* parents);
    289 
    290             std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
    291             mutable std::set<const Identifier*> children_;                 //!< The children of the class the Identifier belongs to
    292 
    293             std::set<const Identifier*> directParents_;                    //!< The direct parents of the class the Identifier belongs to
    294             mutable std::set<const Identifier*> directChildren_;           //!< The direct children of the class the Identifier belongs to
    295 
    296             bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    297             bool bSetName_;                                                //!< True if the name is set
    298             bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    299             std::string name_;                                             //!< The name of the class the Identifier belongs to
    300             Factory* factory_;                                             //!< The Factory, able to create new objects of the given class (if available)
    301121            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)
    302             uint32_t networkID_;                                           //!< The network ID to identify a class through the network
    303             const unsigned int classID_;                                   //!< Uniquely identifies a class (might not be the same as the networkID_)
    304122            static unsigned int classIDCounter_s;                          //!< Static counter for the unique classIDs
    305 
    306             bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
    307             std::map<std::string, ConfigValueContainer*> configValues_;    //!< A map to link the string of configurable variables with their ConfigValueContainer
    308 
    309             std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_;     //!< All loadable parameters
    310             std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_;   //!< All attachable objects
    311123    };
    312 
    313     _CoreExport std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list);
    314 
    315 
    316     // ###############################
    317     // ###     ClassIdentifier     ###
    318     // ###############################
    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.
    323         This makes it possible to store information about a class, sharing them with all
    324         objects of that class without defining static variables in every class.
    325 
    326         To be really sure that not more than exactly one object exists (even with libraries),
    327         ClassIdentifiers are stored in a static map in Identifier.
    328     */
    329     template <class T>
    330     class ClassIdentifier : public Identifier
    331     {
    332         #ifndef DOXYGEN_SHOULD_SKIP_THIS
    333           #define SUPER_INTRUSIVE_DECLARATION_INCLUDE
    334           #include "Super.h"
    335         #endif
    336 
    337         public:
    338             static ClassIdentifier<T>* getIdentifier();
    339             static ClassIdentifier<T>* getIdentifier(const std::string& name);
    340 
    341             bool initialiseObject(T* object, const std::string& className, bool bRootClass);
    342 
    343             void updateConfigValues(bool updateChildren = true) const;
    344 
    345         private:
    346             static void initialiseIdentifier();
    347             ClassIdentifier(const ClassIdentifier<T>& identifier) {}    // don't copy
    348             ClassIdentifier()
    349             {
    350                 SuperFunctionInitialization<0, T>::initialize(this);
    351             }
    352             ~ClassIdentifier()
    353             {
    354                 SuperFunctionDestruction<0, T>::destroy(this);
    355             }
    356 
    357             static ClassIdentifier<T>* classIdentifier_s;
    358     };
    359 
    360     template <class T>
    361     ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;
    362 
    363     /**
    364         @brief Returns the only instance of this class.
    365         @return The unique Identifier
    366     */
    367     template <class T>
    368     inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
    369     {
    370         // check if the Identifier already exists
    371         if (!ClassIdentifier<T>::classIdentifier_s)
    372             ClassIdentifier<T>::initialiseIdentifier();
    373 
    374         return ClassIdentifier<T>::classIdentifier_s;
    375     }
    376 
    377     /**
    378         @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.
    379         @param name The name of this Identifier
    380         @return The Identifier
    381     */
    382     template <class T>
    383     inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)
    384     {
    385         ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();
    386         identifier->setName(name);
    387         return identifier;
    388     }
    389 
    390     /**
    391         @brief Assigns the static field for the identifier singleton.
    392     */
    393     template <class T>
    394     void ClassIdentifier<T>::initialiseIdentifier()
    395     {
    396         // Get the name of the class
    397         std::string name = typeid(T).name();
    398 
    399         // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used.
    400         ClassIdentifier<T>* proposal = new ClassIdentifier<T>();
    401 
    402         // Get the entry from the map
    403         ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)Identifier::getIdentifierSingleton(name, proposal);
    404 
    405         if (ClassIdentifier<T>::classIdentifier_s == proposal)
    406         {
    407             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl;
    408         }
    409         else
    410         {
    411             orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl;
    412         }
    413     }
    414 
    415     /**
    416         @brief Adds an object of the given type to the ObjectList.
    417         @param object The object to add
    418         @param className The name of the class T
    419         @param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass)
    420     */
    421     template <class T>
    422     bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass)
    423     {
    424         if (bRootClass)
    425             orxout(verbose, context::object_list) << "Register Root-Object: " << className << endl;
    426         else
    427             orxout(verbose, context::object_list) << "Register Object: " << className << endl;
    428 
    429         object->identifier_ = this;
    430         if (Identifier::isCreatingHierarchy())
    431         {
    432             if (bRootClass && !object->parents_)
    433                 object->parents_ = new std::set<const Identifier*>();
    434 
    435             if (object->parents_)
    436             {
    437                 this->initializeClassHierarchy(object->parents_, bRootClass);
    438                 object->parents_->insert(object->parents_->end(), this);
    439             }
    440 
    441             object->setConfigValues();
    442             return true;
    443         }
    444         else
    445         {
    446             orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;
    447             object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
    448 
    449             // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
    450             object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
    451             return false;
    452         }
    453     }
    454 
    455     /**
    456         @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function.
    457     */
    458     template <class T>
    459     void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const
    460     {
    461         if (!this->hasConfigValues())
    462             return;
    463 
    464         for (ObjectListIterator<T> it = ObjectList<T>::begin(); it; ++it)
    465             it->setConfigValues();
    466 
    467         if (updateChildren)
    468             for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it)
    469                 (*it)->updateConfigValues(false);
    470     }
    471 
    472 
    473     // ###############################
    474     // ###      orxonox_cast       ###
    475     // ###############################
    476     /**
    477     @brief
    478         Casts on object of type OrxonoxClass to any derived type that is
    479         registered in the class hierarchy.
    480     @return
    481         Returns NULL if the cast is not possible
    482     @note
    483         In case of NULL return (and using MSVC), a dynamic_cast might still be possible if
    484         a class forgot to register its objects.
    485         Also note that the function is implemented differently for GCC/MSVC.
    486     */
    487     template <class T, class U>
    488     ORX_FORCEINLINE T orxonox_cast(U* source)
    489     {
    490 #ifdef ORXONOX_COMPILER_MSVC
    491         typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
    492         if (source != NULL)
    493             return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
    494         else
    495             return NULL;
    496 #else
    497         return dynamic_cast<T>(source);
    498 #endif
    499     }
    500124}
    501125
    502 #endif /* _Identifier_H__ */
     126#endif /* _IdentifierManager_H__ */
  • code/branches/core6/src/libraries/core/config/ConfigValueContainer.h

    r9563 r9564  
    7070            inline virtual void call(void* object)
    7171            {
    72                 if (!Identifier::isCreatingHierarchy())
     72                if (!IdentifierManager::isCreatingHierarchy())
    7373                    (static_cast<T*>(object)->*this->function_)();
    7474            }
  • code/branches/core6/src/libraries/network/packet/ClassID.cc

    r8858 r9564  
    5555
    5656  //calculate total needed size (for all strings and integers)
    57   std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin();
    58   for(;it != Identifier::getStringIdentifierMapEnd();++it){
     57  std::map<std::string, Identifier*>::const_iterator it = IdentifierManager::getStringIdentifierMapBegin();
     58  for(;it != IdentifierManager::getStringIdentifierMapEnd();++it){
    5959    id = it->second;
    6060    if(id == NULL || !id->hasFactory())
     
    129129
    130130  //clear the map of network ids
    131   Identifier::clearNetworkIDs();
     131  IdentifierManager::clearNetworkIDs();
    132132
    133133  orxout(verbose, context::packets) << "=== processing classids: " << endl;
  • code/branches/core6/src/libraries/network/synchronisable/Synchronisable.cc

    r9556 r9564  
    8383  {
    8484    // delete callback function objects
    85     if(!Identifier::isCreatingHierarchy()){
     85    if(!IdentifierManager::isCreatingHierarchy()){
    8686      // remove object from the static objectMap
    8787      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
Note: See TracChangeset for help on using the changeset viewer.