Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "RPCMap.h"
00009 #include <string.h>
00010
00011 RPCMap::RPCMap()
00012 {
00013 }
00014 RPCMap::~RPCMap()
00015 {
00016 Clear();
00017 }
00018 void RPCMap::Clear(void)
00019 {
00020 unsigned i;
00021 RPCNode *node;
00022 for (i=0; i < rpcSet.Size(); i++)
00023 {
00024 node=rpcSet[i];
00025 if (node)
00026 {
00027 rakFree_Ex(node->uniqueIdentifier, __FILE__, __LINE__ );
00028 RakNet::OP_DELETE(node, __FILE__, __LINE__);
00029 }
00030 }
00031 rpcSet.Clear(false, __FILE__, __LINE__);
00032 }
00033 RPCNode *RPCMap::GetNodeFromIndex(RPCIndex index)
00034 {
00035 if ((unsigned)index < rpcSet.Size())
00036 return rpcSet[(unsigned)index];
00037 return 0;
00038 }
00039 RPCNode *RPCMap::GetNodeFromFunctionName(const char *uniqueIdentifier)
00040 {
00041 unsigned index;
00042 index=(unsigned)GetIndexFromFunctionName(uniqueIdentifier);
00043 if ((RPCIndex)index!=UNDEFINED_RPC_INDEX)
00044 return rpcSet[index];
00045 return 0;
00046 }
00047 RPCIndex RPCMap::GetIndexFromFunctionName(const char *uniqueIdentifier)
00048 {
00049 unsigned index;
00050 for (index=0; index < rpcSet.Size(); index++)
00051 if (rpcSet[index] && strcmp(rpcSet[index]->uniqueIdentifier, uniqueIdentifier)==0)
00052 return (RPCIndex) index;
00053 return UNDEFINED_RPC_INDEX;
00054 }
00055
00056
00057 void RPCMap::AddIdentifierWithFunction(const char *uniqueIdentifier, void *functionPointer, bool isPointerToMember)
00058 {
00059 #ifdef _DEBUG
00060 RakAssert((int) rpcSet.Size()+1 < MAX_RPC_MAP_SIZE);
00061 RakAssert(uniqueIdentifier && uniqueIdentifier[0]);
00062 RakAssert(functionPointer);
00063 #endif
00064
00065 unsigned index, existingNodeIndex;
00066 RPCNode *node;
00067
00068 existingNodeIndex=GetIndexFromFunctionName(uniqueIdentifier);
00069 if ((RPCIndex)existingNodeIndex!=UNDEFINED_RPC_INDEX)
00070 {
00071
00072
00073 #ifdef _DEBUG
00074
00075 #endif
00076 return;
00077 }
00078
00079 node = RakNet::OP_NEW<RPCNode>( __FILE__, __LINE__ );
00080 node->uniqueIdentifier = (char*) rakMalloc_Ex( strlen(uniqueIdentifier)+1, __FILE__, __LINE__ );
00081 strcpy(node->uniqueIdentifier, uniqueIdentifier);
00082 node->functionPointer=functionPointer;
00083 node->isPointerToMember=isPointerToMember;
00084
00085
00086 for (index=0; index < rpcSet.Size(); index++)
00087 {
00088 if (rpcSet[index]==0)
00089 {
00090 rpcSet.Replace(node, 0, index, __FILE__,__LINE__);
00091 return;
00092 }
00093 }
00094
00095 rpcSet.Insert(node, __FILE__, __LINE__);
00096
00097 }
00098 void RPCMap::AddIdentifierAtIndex(const char *uniqueIdentifier, RPCIndex insertionIndex)
00099 {
00100 #ifdef _DEBUG
00101 RakAssert(uniqueIdentifier && uniqueIdentifier[0]);
00102 #endif
00103
00104 unsigned existingNodeIndex;
00105 RPCNode *node, *oldNode;
00106
00107 existingNodeIndex=GetIndexFromFunctionName(uniqueIdentifier);
00108
00109 if (existingNodeIndex==insertionIndex)
00110 return;
00111
00112 if ((RPCIndex)existingNodeIndex!=UNDEFINED_RPC_INDEX)
00113 {
00114
00115 oldNode=rpcSet[existingNodeIndex];
00116 rpcSet[existingNodeIndex]=0;
00117 rakFree_Ex(oldNode->uniqueIdentifier, __FILE__, __LINE__ );
00118 RakNet::OP_DELETE(oldNode, __FILE__, __LINE__);
00119 }
00120
00121 node = RakNet::OP_NEW<RPCNode>( __FILE__, __LINE__ );
00122 node->uniqueIdentifier = (char*) rakMalloc_Ex( strlen(uniqueIdentifier)+1, __FILE__, __LINE__ );
00123 strcpy(node->uniqueIdentifier, uniqueIdentifier);
00124 node->functionPointer=0;
00125
00126
00127 if (insertionIndex < rpcSet.Size())
00128 {
00129
00130 oldNode=rpcSet[insertionIndex];
00131 if (oldNode)
00132 {
00133 RakNet::OP_DELETE_ARRAY(oldNode->uniqueIdentifier, __FILE__, __LINE__);
00134 RakNet::OP_DELETE(oldNode, __FILE__, __LINE__);
00135 }
00136 rpcSet[insertionIndex]=node;
00137 }
00138 else
00139 {
00140
00141 rpcSet.Replace(node, 0, insertionIndex, __FILE__,__LINE__);
00142 }
00143 }
00144
00145 void RPCMap::RemoveNode(const char *uniqueIdentifier)
00146 {
00147 unsigned index;
00148 index=GetIndexFromFunctionName(uniqueIdentifier);
00149 #ifdef _DEBUG
00150 RakAssert((int) index!=UNDEFINED_RPC_INDEX);
00151 #endif
00152 RPCNode *node;
00153 node = rpcSet[index];
00154 rakFree_Ex(node->uniqueIdentifier, __FILE__, __LINE__ );
00155 RakNet::OP_DELETE(node, __FILE__, __LINE__);
00156 rpcSet[index]=0;
00157 }
00158