Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 13, 2009, 5:05:17 PM (15 years ago)
Author:
dafrick
Message:

Hopefully merged trunk successfully into pickup branch.

Location:
code/branches/pickup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup

  • code/branches/pickup/src/libraries/core/Identifier.cc

    r5781 r5935  
    3939#include "ConfigValueContainer.h"
    4040#include "ConsoleCommand.h"
    41 #include "Factory.h"
     41#include "ClassFactory.h"
    4242#include "XMLPort.h"
    4343
     
    6161        this->bSetName_ = false;
    6262        this->factory_ = 0;
    63         this->bLoadable_ = true;
     63        this->bLoadable_ = false;
    6464
    6565        this->bHasConfigValues_ = false;
    6666        this->bHasConsoleCommands_ = false;
    6767
    68         this->children_ = new std::set<const Identifier*>();
    69         this->directChildren_ = new std::set<const Identifier*>();
    70 
    7168        // Default network ID is the class ID
    7269        this->networkID_ = this->classID_;
     
    7875    Identifier::~Identifier()
    7976    {
    80         delete this->children_;
    81         delete this->directChildren_;
    8277        delete this->objects_;
    8378
     
    118113            // There is already an entry: return it and delete the proposal
    119114            delete proposal;
    120             return (*it).second;
     115            return it->second;
    121116        }
    122117        else
     
    165160            {
    166161                // Tell the parent we're one of it's children
    167                 (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);
     162                (*it)->children_.insert((*it)->children_.end(), this);
    168163
    169164                // Erase all parents of our parent from our direct-parent-list
     
    187182            {
    188183                // Tell the parent we're one of it's direct children
    189                 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     184                (*it)->directChildren_.insert((*it)->directChildren_.end(), this);
    190185
    191186                // Create the super-function dependencies
     
    196191
    197192    /**
     193        @brief Creates the class-hierarchy by creating and destroying one object of each type.
     194    */
     195    void Identifier::createClassHierarchy()
     196    {
     197        COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl;
     198        Identifier::startCreatingHierarchy();
     199        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it)
     200        {
     201            // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards.
     202            if (it->second->hasFactory())
     203            {
     204                BaseObject* temp = it->second->fabricate(0);
     205                temp->destroy();
     206            }
     207        }
     208        Identifier::stopCreatingHierarchy();
     209        COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl;
     210    }
     211
     212    /**
    198213        @brief Destroys all Identifiers. Called when exiting the program.
    199214    */
     
    214229            this->name_ = name;
    215230            this->bSetName_ = true;
    216             Identifier::getIdentifierMapIntern()[name] = this;
    217             Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this;
     231            Identifier::getStringIdentifierMapIntern()[name] = this;
     232            Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this;
     233            Identifier::getIDIdentifierMapIntern()[this->networkID_] = this;
    218234        }
    219235    }
     
    235251            COUT(1) << "Aborting..." << std::endl;
    236252            abort();
    237             return NULL;
    238         }
    239     }
    240 
    241     /**
    242         @brief Sets the network ID to a new value and changes the entry in the Factory.
     253            return 0;
     254        }
     255    }
     256
     257    /**
     258        @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map.
    243259        @param id The new network ID
    244260    */
    245261    void Identifier::setNetworkID(uint32_t id)
    246262    {
    247         Factory::changeNetworkID(this, this->networkID_, id);
     263//        Identifier::getIDIdentifierMapIntern().erase(this->networkID_);
     264        Identifier::getIDIdentifierMapIntern()[id] = this;
    248265        this->networkID_ = id;
    249266    }
     
    291308    bool Identifier::isParentOf(const Identifier* identifier) const
    292309    {
    293         return (this->children_->find(identifier) != this->children_->end());
     310        return (this->children_.find(identifier) != this->children_.end());
    294311    }
    295312
     
    300317    bool Identifier::isDirectParentOf(const Identifier* identifier) const
    301318    {
    302         return (this->directChildren_->find(identifier) != this->directChildren_->end());
    303     }
    304 
    305     /**
    306         @brief Returns the map that stores all Identifiers.
     319        return (this->directChildren_.find(identifier) != this->directChildren_.end());
     320    }
     321
     322    /**
     323        @brief Returns the map that stores all Identifiers with their names.
    307324        @return The map
    308325    */
    309     std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern()
     326    std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern()
    310327    {
    311328        static std::map<std::string, Identifier*> identifierMap;
     
    314331
    315332    /**
    316         @brief Returns the map that stores all Identifiers.
     333        @brief Returns the map that stores all Identifiers with their names in lowercase.
    317334        @return The map
    318335    */
    319     std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern()
     336    std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern()
    320337    {
    321338        static std::map<std::string, Identifier*> lowercaseIdentifierMap;
    322339        return lowercaseIdentifierMap;
     340    }
     341
     342    /**
     343        @brief Returns the map that stores all Identifiers with their network IDs.
     344        @return The map
     345    */
     346    std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern()
     347    {
     348        static std::map<uint32_t, Identifier*> identifierMap;
     349        return identifierMap;
     350    }
     351
     352    /**
     353        @brief Returns the Identifier with a given name.
     354        @param name The name of the wanted Identifier
     355        @return The Identifier
     356    */
     357    Identifier* Identifier::getIdentifierByString(const std::string& name)
     358    {
     359        std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name);
     360        if (it != Identifier::getStringIdentifierMapIntern().end())
     361            return it->second;
     362        else
     363            return 0;
     364    }
     365
     366    /**
     367        @brief Returns the Identifier with a given name in lowercase.
     368        @param name The name of the wanted Identifier
     369        @return The Identifier
     370    */
     371    Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name)
     372    {
     373        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name);
     374        if (it != Identifier::getLowercaseStringIdentifierMapIntern().end())
     375            return it->second;
     376        else
     377            return 0;
     378    }
     379
     380    /**
     381        @brief Returns the Identifier with a given network ID.
     382        @param id The network ID of the wanted Identifier
     383        @return The Identifier
     384    */
     385    Identifier* Identifier::getIdentifierByID(const uint32_t id)
     386    {
     387        std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id);
     388        if (it != Identifier::getIDIdentifierMapIntern().end())
     389            return it->second;
     390        else
     391            return 0;
     392    }
     393
     394    /**
     395        @brief Cleans the NetworkID map (needed on clients for correct initialization)
     396    */
     397    void Identifier::clearNetworkIDs()
     398    {
     399        Identifier::getIDIdentifierMapIntern().clear();
    323400    }
    324401
     
    351428        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname);
    352429        if (it != configValues_.end())
    353             return ((*it).second);
     430            return it->second;
    354431        else
    355432            return 0;
     
    365442        std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
    366443        if (it != configValues_LC_.end())
    367             return ((*it).second);
     444            return it->second;
    368445        else
    369446            return 0;
     
    404481        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);
    405482        if (it != this->consoleCommands_.end())
    406             return (*it).second;
     483            return it->second;
    407484        else
    408485            return 0;
     
    418495        std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name);
    419496        if (it != this->consoleCommands_LC_.end())
    420             return (*it).second;
     497            return it->second;
    421498        else
    422499            return 0;
     
    432509        std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname);
    433510        if (it != this->xmlportParamContainers_.end())
    434             return ((*it).second);
     511            return it->second;
    435512        else
    436513            return 0;
     
    463540        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname);
    464541        if (it != this->xmlportObjectContainers_.end())
    465             return ((*it).second);
     542            return it->second;
    466543        else
    467544            return 0;
     
    483560
    484561        this->xmlportObjectContainers_[sectionname] = container;
    485     }
    486 
    487     /**
    488         @brief Returns a XMLPortEventContainer that attaches an event to this class.
    489         @param sectionname The name of the section that contains the event
    490         @return The container
    491     */
    492     XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname)
    493     {
    494         std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);
    495         if (it != this->xmlportEventContainers_.end())
    496             return ((*it).second);
    497         else
    498             return 0;
    499     }
    500 
    501     /**
    502         @brief Adds a new XMLPortEventContainer that attaches an event to this class.
    503         @param sectionname The name of the section that contains the event
    504         @param container The container
    505     */
    506     void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container)
    507     {
    508         std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);
    509         if (it != this->xmlportEventContainers_.end())
    510         {
    511             COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl;
    512             delete (it->second);
    513         }
    514 
    515         this->xmlportEventContainers_[eventname] = container;
    516562    }
    517563
     
    525571    {
    526572        for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it)
    527             out << (*it)->getName() << " ";
     573        {
     574            if (it != list.begin())
     575                out << " ";
     576            out << (*it)->getName();
     577        }
    528578
    529579        return out;
Note: See TracChangeset for help on using the changeset viewer.