[10468] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "NetworkFunctionManager.h" |
---|
| 30 | #include "NetworkFunction.h" |
---|
| 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
[10542] | 34 | NetworkFunctionManager* NetworkFunctionManager::singletonPtr_s = 0; |
---|
[10468] | 35 | |
---|
[10475] | 36 | void NetworkFunctionManager::registerFunction(NetworkFunctionBase* function) |
---|
[10468] | 37 | { |
---|
[10475] | 38 | this->functions_.insert(function); |
---|
| 39 | this->nameMap_[function->getName()] = function; |
---|
| 40 | this->idMap_[function->getNetworkID()] = function; |
---|
| 41 | this->functorMap_[function->getPointer()] = function; |
---|
[10468] | 42 | } |
---|
| 43 | |
---|
[10475] | 44 | void NetworkFunctionManager::unregisterFunction(NetworkFunctionBase* function) |
---|
| 45 | { |
---|
| 46 | this->functions_.erase(function); |
---|
| 47 | this->nameMap_.erase(function->getName()); |
---|
| 48 | this->idMap_.erase(function->getNetworkID()); |
---|
| 49 | this->functorMap_.erase(function->getPointer()); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByName(const std::string& name) |
---|
[10468] | 53 | { |
---|
[10475] | 54 | std::map<std::string, NetworkFunctionBase*>::iterator it = nameMap_.find(name); |
---|
| 55 | assert(it != nameMap_.end()); |
---|
| 56 | return it->second; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByFunctionPointer(const NetworkFunctionPointer& p) |
---|
| 60 | { |
---|
[10471] | 61 | std::map<NetworkFunctionPointer, NetworkFunctionBase*>::iterator it = functorMap_.find(p); |
---|
| 62 | assert(it != functorMap_.end()); |
---|
| 63 | return it->second; |
---|
| 64 | } |
---|
| 65 | |
---|
[10475] | 66 | NetworkFunctionBase* NetworkFunctionManager::getFunctionByNetworkId(uint32_t id) |
---|
[10471] | 67 | { |
---|
| 68 | std::map<uint32_t, NetworkFunctionBase*>::iterator it = idMap_.find(id); |
---|
| 69 | assert(it != idMap_.end()); |
---|
[10565] | 70 | if(it != idMap_.end()) |
---|
| 71 | return it->second; |
---|
| 72 | else |
---|
| 73 | return NULL; |
---|
[10471] | 74 | } |
---|
[10565] | 75 | |
---|
| 76 | /** |
---|
| 77 | @brief Cleans the NetworkID map (needed on clients for correct initialization) |
---|
| 78 | */ |
---|
| 79 | void NetworkFunctionManager::clearNetworkIDs() |
---|
| 80 | { |
---|
| 81 | this->idMap_.clear(); |
---|
| 82 | } |
---|
[10468] | 83 | } |
---|