Changeset 10471 for code/branches/core7/src
- Timestamp:
- May 25, 2015, 1:37:50 PM (10 years ago)
- Location:
- code/branches/core7/src/libraries/network
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/network/FunctionCall.cc
r7503 r10471 32 32 #include "util/MultiType.h" 33 33 #include "NetworkFunction.h" 34 #include "NetworkFunctionManager.h" 34 35 35 36 namespace orxonox { … … 48 49 if( this->bIsStatic_ ) 49 50 { 50 NetworkFunctionStatic *fct = NetworkFunctionStatic::getFunction( this->functionID_);51 NetworkFunctionStatic *fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ )); 51 52 assert( this->nrOfArguments_==this->arguments_.size() ); 52 53 switch(this->nrOfArguments_) … … 76 77 else // not a static function, so also handle with the objectID 77 78 { 78 NetworkMemberFunctionBase *fct = NetworkMemberFunctionBase::getFunction( this->functionID_);79 NetworkMemberFunctionBase *fct = static_cast<NetworkMemberFunctionBase*>(NetworkFunctionManager::getFunction( this->functionID_ )); 79 80 switch(this->nrOfArguments_) 80 81 { -
code/branches/core7/src/libraries/network/NetworkFunction.cc
r10470 r10471 32 32 namespace orxonox 33 33 { 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++; 36 38 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 } 41 44 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 } 83 51 } -
code/branches/core7/src/libraries/network/NetworkFunction.h
r10470 r10471 69 69 class _NetworkExport NetworkFunctionBase { 70 70 public: 71 NetworkFunctionBase(const std::string& name );72 virtual ~NetworkFunctionBase() ;73 74 v irtual 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); 75 75 inline uint32_t getNetworkID() const { return this->networkID_; } 76 76 inline const std::string& getName() const { return name_; } … … 85 85 class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase { 86 86 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 { } 88 91 89 92 inline void call(){ (*this->functor_)(); } … … 94 97 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); } 95 98 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 103 99 private: 104 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap();105 static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap();106 100 FunctorStaticPtr functor_; 107 101 … … 111 105 class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase { 112 106 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 { } 119 110 120 111 // … … 125 116 virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0; 126 117 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_;131 118 }; 132 119 … … 134 121 template <class T> class NetworkMemberFunction: public NetworkMemberFunctionBase { 135 122 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 { } 137 127 138 128 inline bool call(uint32_t objectID) … … 200 190 FunctorMemberPtr<T> functor_; 201 191 }; 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 }207 192 208 193 template<class T> inline void copyPtr( T ptr, NetworkFunctionPointer& destptr) -
code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
r10465 r10471 36 36 37 37 #include "NetworkFunction.h" 38 #include "NetworkFunctionManager.h" 38 39 39 40 namespace orxonox … … 50 51 NetworkFunctionPointer p1; \ 51 52 copyPtr( functionPointer, p1 ); \ 52 FunctionCallManager::addCallStatic(NetworkFunction Static::getFunction(p1)->getNetworkID(), __VA_ARGS__); \53 FunctionCallManager::addCallStatic(NetworkFunctionManager::getFunction(p1)->getNetworkID(), __VA_ARGS__); \ 53 54 } 54 55 … … 58 59 NetworkFunctionPointer p1; \ 59 60 copyPtr( &class::function, p1 ); \ 60 FunctionCallManager::addCallMember(Network MemberFunctionBase::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \61 FunctionCallManager::addCallMember(NetworkFunctionManager::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \ 61 62 } 62 63 -
code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
r10469 r10471 32 32 namespace orxonox 33 33 { 34 std::map<NetworkFunctionPointer, NetworkFunctionBase*> NetworkFunctionManager::functorMap_; 35 std::map<uint32_t, NetworkFunctionBase*> NetworkFunctionManager::idMap_; 36 34 37 /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance() 35 38 { … … 58 61 return nameMap_; 59 62 } 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 } 60 77 } -
code/branches/core7/src/libraries/network/NetworkFunctionManager.h
r10469 r10471 45 45 static void destroyAllNetworkFunctions(); 46 46 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_; 47 59 }; 48 60 }
Note: See TracChangeset
for help on using the changeset viewer.