Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2015, 2:41:57 PM (9 years ago)
Author:
landauf
Message:

refactored the interface of NetworkFunctionManager: maps are better encapsulated now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.cc

    r10474 r10475  
    3838    }
    3939
    40     void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
     40    void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function)
    4141    {
    42         std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
    43         assert( map.find(name)!=map.end() );
    44         map[name]->setNetworkID(id);
     42        this->functions_.insert(function);
     43        this->nameMap_[function->getName()] = function;
     44        this->idMap_[function->getNetworkID()] = function;
     45        this->functorMap_[function->getPointer()] = function;
     46    }
     47
     48    void NetworkFunctionManager::unregisterFunction(NetworkFunctionBase* function)
     49    {
     50        this->functions_.erase(function);
     51        this->nameMap_.erase(function->getName());
     52        this->idMap_.erase(function->getNetworkID());
     53        this->functorMap_.erase(function->getPointer());
    4554    }
    4655
    4756    void NetworkFunctionManager::destroyAllNetworkFunctions()
    4857    {
    49         std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
    50         std::map<std::string, NetworkFunctionBase*>::iterator it;
    51         for (it = map.begin(); it != map.end(); ++it)
    52             delete it->second;
     58        std::set<NetworkFunctionBase*>::iterator it;
     59        for (it = this->functions_.begin(); it != this->functions_.end(); ++it)
     60            delete (*it);
    5361    }
    5462
    55     NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
     63    NetworkFunctionBase* NetworkFunctionManager::getFunctionByName(const std::string& name)
     64    {
     65        std::map<std::string, NetworkFunctionBase*>::iterator it = nameMap_.find(name);
     66        assert(it != nameMap_.end());
     67        return it->second;
     68    }
     69
     70    NetworkFunctionBase* NetworkFunctionManager::getFunctionByFunctionPointer(const NetworkFunctionPointer& p)
    5671    {
    5772        std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p);
     
    6075    }
    6176
    62     NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
     77    NetworkFunctionBase* NetworkFunctionManager::getFunctionByNetworkId(uint32_t id)
    6378    {
    6479        std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id);
Note: See TracChangeset for help on using the changeset viewer.