Changeset 6160 for code/branches/presentation2/src/libraries/network
- Timestamp:
- Nov 26, 2009, 2:11:48 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/network/NetworkFunction.cc
r5929 r6160 32 32 namespace orxonox 33 33 { 34 std::map<std::string, NetworkFunctionBase*> NetworkFunctionBase::nameMap_;35 34 std::map<uint32_t, bool> NetworkFunctionBase::isStaticMap_; 36 37 std::map<NetworkFunctionPointer, NetworkFunctionStatic*> NetworkFunctionStatic::functorMap_;38 std::map<uint32_t, NetworkFunctionStatic*> NetworkFunctionStatic::idMap_;39 35 40 36 std::map<NetworkFunctionPointer, NetworkMemberFunctionBase*> NetworkMemberFunctionBase::functorMap_; … … 49 45 50 46 this->name_ = name; 51 nameMap_[name] = this;47 NetworkFunctionBase::getNameMap()[name] = this; 52 48 } 53 49 NetworkFunctionBase::~NetworkFunctionBase() … … 58 54 void NetworkFunctionBase::destroyAllNetworkFunctions() 59 55 { 56 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap(); 60 57 std::map<std::string, NetworkFunctionBase*>::iterator it; 61 for( it= NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it )58 for( it=map.begin(); it!=map.end(); ++it ) 62 59 it->second->destroy(); 60 } 61 62 63 /*static*/ std::map<std::string, NetworkFunctionBase*>& NetworkFunctionBase::getNameMap() 64 { 65 static std::map<std::string, NetworkFunctionBase*> nameMap_; 66 return nameMap_; 63 67 } 64 68 … … 70 74 71 75 this->functor_ = functor; 72 functorMap_[p] = this;73 idMap_[ this->getNetworkID() ] = this;76 NetworkFunctionStatic::getFunctorMap()[p] = this; 77 NetworkFunctionStatic::getIdMap()[ this->getNetworkID() ] = this; 74 78 } 75 79 … … 79 83 } 80 84 85 /*static*/ std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& NetworkFunctionStatic::getFunctorMap() 86 { 87 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_; 88 return functorMap_; 89 } 90 91 /*static*/ std::map<uint32_t, NetworkFunctionStatic*>& NetworkFunctionStatic::getIdMap() 92 { 93 static std::map<uint32_t, NetworkFunctionStatic*> idMap_; 94 return idMap_; 95 } 81 96 82 97 … … 86 101 RegisterObject(NetworkMemberFunctionBase); 87 102 88 functorMap_[p] = this;89 idMap_[ this->getNetworkID() ] = this;103 this->functorMap_[p] = this; 104 this->idMap_[ this->getNetworkID() ] = this; 90 105 } 91 106 -
code/branches/presentation2/src/libraries/network/NetworkFunction.h
r5781 r6160 80 80 static inline bool isStatic( uint32_t networkID ) { return isStaticMap_[networkID]; } 81 81 82 static inline void setNetworkID(const std::string& name, uint32_t id){ assert( nameMap_.find(name)!=nameMap_.end() ); nameMap_[name]->setNetworkID(id); } 82 static inline void setNetworkID(const std::string& name, uint32_t id) 83 { 84 std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionBase::getNameMap(); 85 assert( map.find(name)!=map.end() ); 86 map[name]->setNetworkID(id); 87 } 83 88 84 89 static void destroyAllNetworkFunctions(); … … 88 93 89 94 private: 90 static std::map<std::string, NetworkFunctionBase*> nameMap_;95 static std::map<std::string, NetworkFunctionBase*>& getNameMap(); 91 96 uint32_t networkID_; 92 97 std::string name_; … … 107 112 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); } 108 113 109 virtual void setNetworkID( uint32_t id ){ NetworkFunctionBase::setNetworkID( id ); idMap_[id] = this; } 110 static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id){ assert( idMap_.find(id)!=idMap_.end() ); return idMap_[id]; } 111 static NetworkFunctionStatic* getFunction( uint32_t id ){ assert( idMap_.find(id) != idMap_.end() ); return idMap_[id]; } 112 static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ){ assert( functorMap_.find(p) != functorMap_.end() ); return functorMap_[p]; } 113 114 private: 115 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*> functorMap_; 116 static std::map<uint32_t, NetworkFunctionStatic*> idMap_; 117 114 virtual void setNetworkID( uint32_t id ) 115 { NetworkFunctionBase::setNetworkID( id ); NetworkFunctionStatic::getIdMap()[id] = this; } 116 static inline NetworkFunctionStatic* getNetworkFunction( uint32_t id) 117 { assert( NetworkFunctionStatic::getIdMap().find(id)!=NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; } 118 static NetworkFunctionStatic* getFunction( uint32_t id ) 119 { assert( NetworkFunctionStatic::getIdMap().find(id) != NetworkFunctionStatic::getIdMap().end() ); return NetworkFunctionStatic::getIdMap()[id]; } 120 static NetworkFunctionStatic* getFunction( const NetworkFunctionPointer& p ) 121 { assert( NetworkFunctionStatic::getFunctorMap().find(p) != NetworkFunctionStatic::getFunctorMap().end() ); return NetworkFunctionStatic::getFunctorMap()[p]; } 122 123 private: 124 static std::map<NetworkFunctionPointer, NetworkFunctionStatic*>& getFunctorMap(); 125 static std::map<uint32_t, NetworkFunctionStatic*>& getIdMap(); 118 126 FunctorStatic* functor_; 119 127
Note: See TracChangeset
for help on using the changeset viewer.