Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

made NetworkFunctionManager a singleton, no static functions anymore (except for getInstance)

Location:
code/branches/core7/src/libraries/network
Files:
6 edited

Legend:

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

    r10473 r10474  
    4747
    4848bool FunctionCall::execute(){
    49   NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
     49  NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunction( this->functionID_ ));
    5050  assert( this->nrOfArguments_==this->arguments_.size() );
    5151  switch(this->nrOfArguments_)
  • code/branches/core7/src/libraries/network/NetworkFunction.cc

    r10471 r10474  
    3838
    3939        this->name_ = name;
    40         NetworkFunctionManager::getNameMap()[name] = this;
    41         NetworkFunctionManager::getFunctorMap()[p] = this;
    42         NetworkFunctionManager::getIdMap()[this->getNetworkID()] = this;
     40        NetworkFunctionManager::getInstance().getNameMap()[name] = this;
     41        NetworkFunctionManager::getInstance().getFunctorMap()[p] = this;
     42        NetworkFunctionManager::getInstance().getIdMap()[this->getNetworkID()] = this;
    4343    }
    4444
    4545    void NetworkFunctionBase::setNetworkID(uint32_t id)
    4646    {
    47         NetworkFunctionManager::getIdMap().erase(this->networkID_);  // remove old id
     47        NetworkFunctionManager::getInstance().getIdMap().erase(this->networkID_);  // remove old id
    4848        this->networkID_ = id;
    49         NetworkFunctionManager::getIdMap()[this->networkID_] = this; // add new id
     49        NetworkFunctionManager::getInstance().getIdMap()[this->networkID_] = this; // add new id
    5050    }
    5151}
  • code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h

    r10473 r10474  
    5151            NetworkFunctionPointer p1; \
    5252            copyPtr( functionPointer, p1 ); \
    53             FunctionCallManager::addCall(NetworkFunctionManager::getFunction(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
     53            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
    5454        }
    5555
     
    5959            NetworkFunctionPointer p1; \
    6060            copyPtr( &class::function, p1 ); \
    61             FunctionCallManager::addCall(NetworkFunctionManager::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
     61            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
    6262        }
    6363
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.cc

    r10471 r10474  
    3232namespace orxonox
    3333{
    34     std::map<NetworkFunctionPointer, NetworkFunctionBase*> NetworkFunctionManager::functorMap_;
    35     std::map<uint32_t, NetworkFunctionBase*> NetworkFunctionManager::idMap_;
    36 
    3734    /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance()
    3835    {
     
    4138    }
    4239
    43     /*static*/void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
     40    void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
    4441    {
    45         std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
     42        std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
    4643        assert( map.find(name)!=map.end() );
    4744        map[name]->setNetworkID(id);
    4845    }
    4946
    50     /*static*/void NetworkFunctionManager::destroyAllNetworkFunctions()
     47    void NetworkFunctionManager::destroyAllNetworkFunctions()
    5148    {
    52         std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
     49        std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
    5350        std::map<std::string, NetworkFunctionBase*>::iterator it;
    5451        for (it = map.begin(); it != map.end(); ++it)
     
    5653    }
    5754
    58     /*static*/std::map<std::string, NetworkFunctionBase*>& NetworkFunctionManager::getNameMap()
    59     {
    60         static std::map<std::string, NetworkFunctionBase*> nameMap_;
    61         return nameMap_;
    62     }
    63 
    64     /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
     55    NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
    6556    {
    6657        std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p);
     
    6960    }
    7061
    71     /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
     62    NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
    7263    {
    7364        std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id);
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.h

    r10471 r10474  
    4242            static NetworkFunctionManager& getInstance();
    4343
    44             static void setNetworkID(const std::string& name, uint32_t id);
    45             static void destroyAllNetworkFunctions();
    46             static std::map<std::string, NetworkFunctionBase*>& getNameMap();
     44            void setNetworkID(const std::string& name, uint32_t id);
     45            void destroyAllNetworkFunctions();
    4746
    48             static inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
     47            inline std::map<std::string, NetworkFunctionBase*>& getNameMap()
     48                { return nameMap_; }
     49            inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
    4950                { return functorMap_; }
    50             static inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
     51            inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
    5152                { return idMap_; }
    5253
    53             static NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
    54             static NetworkFunctionBase* getFunction(uint32_t id);
     54            NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
     55            NetworkFunctionBase* getFunction(uint32_t id);
    5556
    5657        private:
    57             static std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
    58             static std::map<uint32_t, NetworkFunctionBase*> idMap_;
     58            std::map<std::string, NetworkFunctionBase*> nameMap_;
     59            std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
     60            std::map<uint32_t, NetworkFunctionBase*> idMap_;
    5961    };
    6062}
  • code/branches/core7/src/libraries/network/packet/FunctionIDs.cc

    r10470 r10474  
    5656
    5757  //calculate total needed size (for all strings and integers)
    58   std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
     58  std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getInstance().getNameMap();
    5959  std::map<std::string, NetworkFunctionBase*>::iterator it;
    6060  for (it = map.begin(); it != map.end(); ++it)
     
    140140    functionname = temp+2*sizeof(uint32_t);
    141141    orxout(internal_info, context::packets) << "processing functionid: " << networkID << " name: " << functionname << endl;
    142     NetworkFunctionManager::setNetworkID((const char*)functionname, networkID);
     142    NetworkFunctionManager::getInstance().setNetworkID((const char*)functionname, networkID);
    143143    temp += 2*sizeof(uint32_t) + stringsize;
    144144  }
Note: See TracChangeset for help on using the changeset viewer.