[Orxonox-commit 5814] r10474 - in code/branches/core7/src: libraries/network libraries/network/packet orxonox/gamestates

landauf at orxonox.net landauf at orxonox.net
Mon May 25 14:14:16 CEST 2015


Author: landauf
Date: 2015-05-25 14:14:16 +0200 (Mon, 25 May 2015)
New Revision: 10474

Modified:
   code/branches/core7/src/libraries/network/FunctionCall.cc
   code/branches/core7/src/libraries/network/NetworkFunction.cc
   code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
   code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
   code/branches/core7/src/libraries/network/NetworkFunctionManager.h
   code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
   code/branches/core7/src/orxonox/gamestates/GSRoot.cc
Log:
made NetworkFunctionManager a singleton, no static functions anymore (except for getInstance)

Modified: code/branches/core7/src/libraries/network/FunctionCall.cc
===================================================================
--- code/branches/core7/src/libraries/network/FunctionCall.cc	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/FunctionCall.cc	2015-05-25 12:14:16 UTC (rev 10474)
@@ -46,7 +46,7 @@
 
 
 bool FunctionCall::execute(){
-  NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
+  NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getInstance().getFunction( this->functionID_ ));
   assert( this->nrOfArguments_==this->arguments_.size() );
   switch(this->nrOfArguments_)
   {

Modified: code/branches/core7/src/libraries/network/NetworkFunction.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunction.cc	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/NetworkFunction.cc	2015-05-25 12:14:16 UTC (rev 10474)
@@ -37,15 +37,15 @@
         this->networkID_ = networkID++;
 
         this->name_ = name;
-        NetworkFunctionManager::getNameMap()[name] = this;
-        NetworkFunctionManager::getFunctorMap()[p] = this;
-        NetworkFunctionManager::getIdMap()[this->getNetworkID()] = this;
+        NetworkFunctionManager::getInstance().getNameMap()[name] = this;
+        NetworkFunctionManager::getInstance().getFunctorMap()[p] = this;
+        NetworkFunctionManager::getInstance().getIdMap()[this->getNetworkID()] = this;
     }
 
     void NetworkFunctionBase::setNetworkID(uint32_t id)
     {
-        NetworkFunctionManager::getIdMap().erase(this->networkID_);  // remove old id
+        NetworkFunctionManager::getInstance().getIdMap().erase(this->networkID_);  // remove old id
         this->networkID_ = id;
-        NetworkFunctionManager::getIdMap()[this->networkID_] = this; // add new id
+        NetworkFunctionManager::getInstance().getIdMap()[this->networkID_] = this; // add new id
     }
 }

Modified: code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/NetworkFunctionIncludes.h	2015-05-25 12:14:16 UTC (rev 10474)
@@ -50,7 +50,7 @@
         { \
             NetworkFunctionPointer p1; \
             copyPtr( functionPointer, p1 ); \
-            FunctionCallManager::addCall(NetworkFunctionManager::getFunction(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
+            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), OBJECTID_UNKNOWN, __VA_ARGS__); \
         }
 
     // call it with class, function, objectID, clientID, args
@@ -58,7 +58,7 @@
         { \
             NetworkFunctionPointer p1; \
             copyPtr( &class::function, p1 ); \
-            FunctionCallManager::addCall(NetworkFunctionManager::getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
+            FunctionCallManager::addCall(NetworkFunctionManager::getInstance().getFunction(p1)->getNetworkID(), objectID, __VA_ARGS__); \
         }
 
     template<class T> inline void* registerStaticNetworkFunctionFct( T ptr, const std::string& name )

Modified: code/branches/core7/src/libraries/network/NetworkFunctionManager.cc
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.cc	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.cc	2015-05-25 12:14:16 UTC (rev 10474)
@@ -31,44 +31,35 @@
 
 namespace orxonox
 {
-    std::map<NetworkFunctionPointer, NetworkFunctionBase*> NetworkFunctionManager::functorMap_;
-    std::map<uint32_t, NetworkFunctionBase*> NetworkFunctionManager::idMap_;
-
     /* static */NetworkFunctionManager& NetworkFunctionManager::getInstance()
     {
         static NetworkFunctionManager instance;
         return instance;
     }
 
-    /*static*/void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
+    void NetworkFunctionManager::setNetworkID(const std::string& name, uint32_t id)
     {
-        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
+        std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
         assert( map.find(name)!=map.end() );
         map[name]->setNetworkID(id);
     }
 
-    /*static*/void NetworkFunctionManager::destroyAllNetworkFunctions()
+    void NetworkFunctionManager::destroyAllNetworkFunctions()
     {
-        std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
+        std::map<std::string, NetworkFunctionBase*>& map = this->nameMap_;
         std::map<std::string, NetworkFunctionBase*>::iterator it;
         for (it = map.begin(); it != map.end(); ++it)
             delete it->second;
     }
 
-    /*static*/std::map<std::string, NetworkFunctionBase*>& NetworkFunctionManager::getNameMap()
+    NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
     {
-        static std::map<std::string, NetworkFunctionBase*> nameMap_;
-        return nameMap_;
-    }
-
-    /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(const NetworkFunctionPointer& p)
-    {
         std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p);
         assert(it != functorMap_.end());
         return it->second;
     }
 
-    /*static*/NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
+    NetworkFunctionBase* NetworkFunctionManager::getFunction(uint32_t id)
     {
         std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id);
         assert(it != idMap_.end());

Modified: code/branches/core7/src/libraries/network/NetworkFunctionManager.h
===================================================================
--- code/branches/core7/src/libraries/network/NetworkFunctionManager.h	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/NetworkFunctionManager.h	2015-05-25 12:14:16 UTC (rev 10474)
@@ -41,21 +41,23 @@
         public:
             static NetworkFunctionManager& getInstance();
 
-            static void setNetworkID(const std::string& name, uint32_t id);
-            static void destroyAllNetworkFunctions();
-            static std::map<std::string, NetworkFunctionBase*>& getNameMap();
+            void setNetworkID(const std::string& name, uint32_t id);
+            void destroyAllNetworkFunctions();
 
-            static inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
+            inline std::map<std::string, NetworkFunctionBase*>& getNameMap()
+                { return nameMap_; }
+            inline std::map<NetworkFunctionPointer, NetworkFunctionBase*>& getFunctorMap()
                 { return functorMap_; }
-            static inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
+            inline std::map<uint32_t, NetworkFunctionBase*>& getIdMap()
                 { return idMap_; }
 
-            static NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
-            static NetworkFunctionBase* getFunction(uint32_t id);
+            NetworkFunctionBase* getFunction(const NetworkFunctionPointer& p);
+            NetworkFunctionBase* getFunction(uint32_t id);
 
         private:
-            static std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
-            static std::map<uint32_t, NetworkFunctionBase*> idMap_;
+            std::map<std::string, NetworkFunctionBase*> nameMap_;
+            std::map<NetworkFunctionPointer, NetworkFunctionBase*> functorMap_;
+            std::map<uint32_t, NetworkFunctionBase*> idMap_;
     };
 }
 

Modified: code/branches/core7/src/libraries/network/packet/FunctionIDs.cc
===================================================================
--- code/branches/core7/src/libraries/network/packet/FunctionIDs.cc	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/libraries/network/packet/FunctionIDs.cc	2015-05-25 12:14:16 UTC (rev 10474)
@@ -55,7 +55,7 @@
   std::queue<std::pair<uint32_t, std::string> > tempQueue;
 
   //calculate total needed size (for all strings and integers)
-  std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getNameMap();
+  std::map<std::string, NetworkFunctionBase*>& map = NetworkFunctionManager::getInstance().getNameMap();
   std::map<std::string, NetworkFunctionBase*>::iterator it;
   for (it = map.begin(); it != map.end(); ++it)
   {
@@ -139,7 +139,7 @@
     stringsize = *(uint32_t*)(temp+sizeof(uint32_t));
     functionname = temp+2*sizeof(uint32_t);
     orxout(internal_info, context::packets) << "processing functionid: " << networkID << " name: " << functionname << endl;
-    NetworkFunctionManager::setNetworkID((const char*)functionname, networkID);
+    NetworkFunctionManager::getInstance().setNetworkID((const char*)functionname, networkID);
     temp += 2*sizeof(uint32_t) + stringsize;
   }
   delete this;

Modified: code/branches/core7/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/core7/src/orxonox/gamestates/GSRoot.cc	2015-05-25 12:04:43 UTC (rev 10473)
+++ code/branches/core7/src/orxonox/gamestates/GSRoot.cc	2015-05-25 12:14:16 UTC (rev 10474)
@@ -68,7 +68,7 @@
 
     GSRoot::~GSRoot()
     {
-        NetworkFunctionManager::destroyAllNetworkFunctions();
+        NetworkFunctionManager::getInstance().destroyAllNetworkFunctions();
     }
 
     void GSRoot::printObjects()




More information about the Orxonox-commit mailing list