Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2015, 1:37:50 PM (10 years ago)
Author:
landauf
Message:

moved static maps from NetworkFunctionStatic and NetworkMemberFunctionBase to NetworkFunctionManager

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

Legend:

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

    r7503 r10471  
    3232#include "util/MultiType.h"
    3333#include "NetworkFunction.h"
     34#include "NetworkFunctionManager.h"
    3435
    3536namespace orxonox {
     
    4849  if( this->bIsStatic_ )
    4950  {
    50     NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( this->functionID_ );
     51    NetworkFunctionStatic *fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
    5152    assert( this->nrOfArguments_==this->arguments_.size() );
    5253    switch(this->nrOfArguments_)
     
    7677  else // not a static function, so also handle with the objectID
    7778  {
    78     NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( this->functionID_ );
     79    NetworkMemberFunctionBase *fct = static_cast<NetworkMemberFunctionBase*>(NetworkFunctionManager::getFunction( this->functionID_ ));
    7980    switch(this->nrOfArguments_)
    8081    {
  • code/branches/core7/src/libraries/network/NetworkFunction.cc

    r10470 r10471  
    3232namespace orxonox
    3333{
    34   std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_;
    35   std::map<uint32_t, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::idMap_;
     34    NetworkFunctionBase::NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
     35    {
     36        static uint32_t networkID = 0;
     37        this->networkID_ = networkID++;
    3638
    37   NetworkFunctionBase::NetworkFunctionBase(const std::string& name)
    38   {
    39     static uint32_t networkID = 0;
    40     this->networkID_ = networkID++;
     39        this->name_ = name;
     40        NetworkFunctionManager::getNameMap()[name] = this;
     41        NetworkFunctionManager::getFunctorMap()[p] = this;
     42        NetworkFunctionManager::getIdMap()[this->getNetworkID()] = this;
     43    }
    4144
    42     this->name_ = name;
    43     NetworkFunctionManager::getNameMap()[name] = this;
    44   }
    45   NetworkFunctionBase::~NetworkFunctionBase()
    46   {
    47   }
    48 
    49 
    50   NetworkFunctionStatic::NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p):
    51     NetworkFunctionBase(name)
    52   {
    53     this->functor_ = functor;
    54     NetworkFunctionStatic::getFunctorMap()[p] = this;
    55     NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this;
    56   }
    57 
    58   /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap()
    59   {
    60     static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_;
    61     return functorMap_;
    62   }
    63 
    64   /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap()
    65   {
    66     static std::map<uint32_t, NetworkFunctionStatic*> idMap_;
    67     return idMap_;
    68   }
    69 
    70 
    71   NetworkMemberFunctionBase::NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p):
    72     NetworkFunctionBase(name)
    73   {
    74     this->functorMap_[p] = this;
    75     this->idMap_[ this->getNetworkID() ] = this;
    76   }
    77 
    78   NetworkMemberFunctionBase::~NetworkMemberFunctionBase()
    79   {
    80   }
    81 
    82 
     45    void NetworkFunctionBase::setNetworkID(uint32_t id)
     46    {
     47        NetworkFunctionManager::getIdMap().erase(this->networkID_);  // remove old id
     48        this->networkID_ = id;
     49        NetworkFunctionManager::getIdMap()[this->networkID_] = this; // add new id
     50    }
    8351}
  • code/branches/core7/src/libraries/network/NetworkFunction.h

    r10470 r10471  
    6969class _NetworkExport NetworkFunctionBase {
    7070  public:
    71     NetworkFunctionBase(const std::string& name);
    72     virtual ~NetworkFunctionBase();
    73 
    74     virtual void        setNetworkID(uint32_t id)       { this->networkID_ = id; }
     71    NetworkFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
     72    virtual ~NetworkFunctionBase() {}
     73
     74    void setNetworkID(uint32_t id);
    7575    inline uint32_t     getNetworkID() const            { return this->networkID_; }
    7676    inline const std::string& getName() const           { return name_; }
     
    8585class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
    8686  public:
    87     NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p);
     87    NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p)
     88        : NetworkFunctionBase(name, p)
     89        , functor_(functor)
     90    { }
    8891
    8992    inline void call(){ (*this->functor_)(); }
     
    9497    inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
    9598
    96     virtual void setNetworkID( uint32_t id )
    97         { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; }
    98     static NetworkFunctionStatic* getFunction( uint32_t id )
    99         { assert( NetworkFunctionStatic::getIdMap().find(id) != NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; }
    100     static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p )
    101         { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; }
    102 
    10399  private:
    104     static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();
    105     static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();
    106100    FunctorStaticPtr functor_;
    107101
     
    111105class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
    112106  public:
    113     NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p);
    114     ~NetworkMemberFunctionBase();
    115 
    116     virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; }
    117     static NetworkMemberFunctionBase* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; }
    118     static NetworkMemberFunctionBase* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; }
     107    NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
     108        : NetworkFunctionBase(name, p)
     109    { }
    119110
    120111    //
     
    125116    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
    126117    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
    127 
    128   private:
    129     static std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> functorMap_;
    130     static std::map<uint32_t, NetworkMemberFunctionBase*> idMap_;
    131118};
    132119
     
    134121template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase {
    135122  public:
    136     NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p);
     123    NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p)
     124        : NetworkMemberFunctionBase(name, p)
     125        , functor_(functor)
     126    { }
    137127
    138128    inline bool call(uint32_t objectID)
     
    200190    FunctorMemberPtr<T> functor_;
    201191};
    202 
    203 template <class T> NetworkMemberFunction<T>::NetworkMemberFunction(const FunctorMemberPtr<T>& functor, const std::string& name, const NetworkFunctionPointer& p):
    204     NetworkMemberFunctionBase(name, p), functor_(functor)
    205 {
    206 }
    207192
    208193template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr)
  • code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h

    r10465 r10471  
    3636
    3737#include "NetworkFunction.h"
     38#include "NetworkFunctionManager.h"
    3839
    3940namespace orxonox
     
    5051            NetworkFunctionPointer p1; \
    5152            copyPtr( functionPointer, p1 ); \
    52             FunctionCallManager::addCallStatic(NetworkFunctionStatic::getFunction(p1)->getNetworkID(), __VA_ARGS__); \
     53            FunctionCallManager::addCallStatic(NetworkFunctionManager::getFunction(p1)->getNetworkID(), __VA_ARGS__); \
    5354        }
    5455
     
    5859            NetworkFunctionPointer p1; \
    5960            copyPtr( &class::function, p1 ); \
    60             FunctionCallManager::addCallMember(NetworkMemberFunctionBase::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
     61            FunctionCallManager::addCallMember(NetworkFunctionManager::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
    6162        }
    6263
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.cc

    r10469 r10471  
    3232namespace orxonox
    3333{
     34    std::map<NetworkFunctionPointer, NetworkFunctionBase*> NetworkFunctionManager::functorMap_;
     35    std::map<uint32_t, NetworkFunctionBase*> NetworkFunctionManager::idMap_;
     36
    3437    /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance()
    3538    {
     
    5861        return nameMap_;
    5962    }
     63
     64    /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
     65    {
     66        std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p);
     67        assert(it != functorMap_.end());
     68        return it->second;
     69    }
     70
     71    /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
     72    {
     73        std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id);
     74        assert(it != idMap_.end());
     75        return it->second;
     76    }
    6077}
  • code/branches/core7/src/libraries/network/NetworkFunctionManager.h

    r10469 r10471  
    4545            static void destroyAllNetworkFunctions();
    4646            static std::map<std::string, NetworkFunctionBase*>& getNameMap();
     47
     48            static inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
     49                { return functorMap_; }
     50            static inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
     51                { return idMap_; }
     52
     53            static NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
     54            static NetworkFunctionBase* getFunction(uint32_t id);
     55
     56        private:
     57            static std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
     58            static std::map<uint32_t, NetworkFunctionBase*> idMap_;
    4759    };
    4860}
Note: See TracChangeset for help on using the changeset viewer.