Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 copied

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.