|
本帖最后由 疯人¢衰人 于 2014-6-23 08:48 编辑
这个函数库是用来发布唯一ID的,本身不复杂,但是实际应用中可能会很有用处。
函数发布的ID不保证有序,在正确的释放ID的前提下,可以保证ID唯一。采用类似WE中Handle型变量Handle值发布的算法
以下为声明变量
- //======================================================================
- //Common Function : IndexGetSystem
- //======================================================================
- //Constant
- const string libGAWH_GV_COM_IS_NameIndexSystemFirstName = "IS:";
- const string libGAWH_GV_COM_IS_NameIndexSystemDeleteNum = ":DeleteNum:";
- const string libGAWH_GV_COM_IS_NameIndexSystemDeleteIndex = ":DeleteIndex:";
- const string libGAWH_GV_COM_IS_NameIndexSystemMaxNum = ":Max:";
- const string libGAWH_GV_COM_IS_NameIndexSystemLastIndex = ":LastIndex:";
- const string libGAWH_GV_COM_IS_NameIndexSystemUsed = ":Used:";
- //----------------------------------------------------------------------
- //Function Declaration
- //----------------------------------------------------------------------
- int libGAWH_FUNC_COM_IS_IndexSystemGetIndex(string lp_IndexName);
- void libGAWH_FUNC_COM_IS_IndexSystemFlushIndexRecord(string lp_IndexName);
- void libGAWH_FUNC_COM_IS_IndexSystemDeleteIndex(string lp_IndexName, int lp_Index);
- int libGAWH_FUNC_COM_IS_IndexSystemLastUsedIndex(string lp_IndexName);
复制代码
以下为相关函数
- //======================================================================
- //Common Function : IndexGetSystem
- //======================================================================
- //----------------------------------------------------------------------
- //Functions
- //----------------------------------------------------------------------
- int libGAWH_FUNC_COM_IS_IndexSystemGetIndex(string lp_IndexName)
- {
- int lv_DeleteNum = DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteNum);
- int lv_MaxNum = 0;
- int lv_LastIndex = 0;
-
- if (lv_DeleteNum == 0)
- {
- lv_MaxNum = DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemMaxNum);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemMaxNum, lv_MaxNum + 1);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemLastIndex, lv_MaxNum);
- DataTableSetBool(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + IntToString(lv_MaxNum) + libGAWH_GV_COM_IS_NameIndexSystemUsed, true);
- return lv_MaxNum;
- }
- else
- {
- lv_DeleteNum =lv_DeleteNum - 1;
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteNum, lv_DeleteNum);
- lv_LastIndex = DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteIndex + IntToString(lv_DeleteNum));
- DataTableSetBool(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + IntToString(lv_LastIndex) + libGAWH_GV_COM_IS_NameIndexSystemUsed, true);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemLastIndex, lv_LastIndex);
- return lv_LastIndex;
- }
- }
- void libGAWH_FUNC_COM_IS_IndexSystemFlushIndexRecord(string lp_IndexName)
- {
- int lv_I = 0;
- int lv_MaxNum = DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemMaxNum);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemMaxNum, 0);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteNum, 0);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemLastIndex, 0);
- while (lv_I < lv_MaxNum)
- {
- DataTableSetBool(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + IntToString(lv_I) + libGAWH_GV_COM_IS_NameIndexSystemUsed, false);
- lv_I += 1;
- }
- }
- void libGAWH_FUNC_COM_IS_IndexSystemDeleteIndex(string lp_IndexName, int lp_Index)
- {
- int lv_DeleteNum = DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteNum);
- bool lv_Used = DataTableGetBool(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + IntToString(lp_Index) + libGAWH_GV_COM_IS_NameIndexSystemUsed);
- if (lv_Used)
- {
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteNum, lv_DeleteNum + 1);
- DataTableSetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemDeleteIndex + IntToString(lv_DeleteNum), lp_Index);
- DataTableSetBool(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + IntToString(lp_Index) + libGAWH_GV_COM_IS_NameIndexSystemUsed, false);
- }
- else
- {
- TriggerDebugOutput(1, StringToText("\xe6\x97\xa0\xe6\xb3\x95\xe9\x87\x8a\xe6\x94\xbe\xe6\x9c\xaa\xe4\xbd\xbf\xe7\x94\xa8\xe5\xba\x8f\xe5\x8f\xb7\xef\xbc\x9a") + IntToText(lp_Index), false);
- }
- }
- int libGAWH_FUNC_COM_IS_IndexSystemLastUsedIndex(string lp_IndexName)
- {
- return DataTableGetInt(true, libGAWH_GV_COM_IS_NameIndexSystemFirstName + lp_IndexName + libGAWH_GV_COM_IS_NameIndexSystemLastIndex);
- }
复制代码
函数- int libGAWH_FUNC_COM_IS_IndexSystemGetIndex(string lp_IndexName)
复制代码 为获得ID的函数,参数string lp_IndexName为区别ID所属的识别字符,即当地图中存在多个需要获取ID的系统时,只要采用不同的string lp_IndexName即可获得相互独立的ID
函数- void libGAWH_FUNC_COM_IS_IndexSystemFlushIndexRecord(string lp_IndexName)
复制代码 用于清空某个系列的ID,即释放某个string lp_IndexName对应的ID系列,重置状态
函数- void libGAWH_FUNC_COM_IS_IndexSystemDeleteIndex(string lp_IndexName, int lp_Index)
复制代码 释放在string lp_IndexName对应的ID系列中已经使用的ID——int lp_Index,使其能够重新使用
函数- int libGAWH_FUNC_COM_IS_IndexSystemLastUsedIndex(string lp_IndexName)
复制代码 返回在string lp_IndexName对应的ID系列中,上次分发的ID,其可能已经被释放
|
|