Added ACRE2's hash and hash lists.

This commit is contained in:
Nou 2015-01-14 13:29:52 -08:00
parent 5c039a4ffd
commit d281caffbe
13 changed files with 247 additions and 1 deletions

View File

@ -149,6 +149,18 @@ PREP(localEvent);
PREP(removeEventHandler);
PREP(removeAlLEventHandlers);
// hashes
PREP(hashCreate);
PREP(hashSet);
PREP(hashGet);
PREP(hashHasKey);
PREP(hashRem);
PREP(hashListCreateList);
PREP(hashListCreateHash);
PREP(hashListSelect);
PREP(hashListSet);
PREP(hashListPush);
// Loop to update the ACE_player variable
ACE_player = player;
@ -164,3 +176,8 @@ if (hasInterface) then {
};
}] call BIS_fnc_addStackedEventHandler;
};

View File

@ -0,0 +1,5 @@
//fnc_hashCreate.sqf
#include "script_component.hpp"
// diag_log text format["%1 HASH CREATE"];
[[],[]]

View File

@ -0,0 +1,26 @@
//fnc_hashGet.sqf
#include "script_component.hpp"
private ["_hash", "_key", "_val", "_index"];
// diag_log text format["%1 HASH GET: %2", diag_tickTime, _this];
_hash = _this select 0;
_key = _this select 1;
ERRORDATA(2);
_val = nil;
try {
if(VALIDHASH(_hash)) then {
_index = (_hash select 0) find _key;
if(_index != -1) then {
_val = (_hash select 1) select _index;
if(IS_STRING(_val) && {_val == "ACREHASHREMOVEDONOTUSETHISVAL"}) then {
_val = nil;
};
};
} else {
ERROR("Input hash is not valid");
};
} catch {
HANDLECATCH;
};
_val

View File

@ -0,0 +1,23 @@
//fnc_hashHasKey.sqf
#include "script_component.hpp"
private ["_hash", "_key", "_val", "_index"];
// diag_log text format["%1 HASH HAS KEY: %2", diag_tickTime, _this];
_hash = _this select 0;
_key = _this select 1;
ERRORDATA(2);
_val = false;
try {
if(VALIDHASH(_hash)) then {
_index = (_hash select 0) find _key;
if(_index != -1) then {
_val = true;
};
} else {
ERROR("Input hash is not valid");
};
} catch {
HANDLECATCH;
};
_val

View File

@ -0,0 +1,18 @@
//fnc_hashListCreateHash.sqf
#include "script_component.hpp"
private ["_hashList", "_hashKeys"];
_hashList = _this select 0;
ERRORDATA(1);
_hashKeys = [];
try {
if(VALIDHASH(_hashList)) then {
_hashKeys = (_hashList select 0);
} else {
ERROR("Input hashlist is not valid");
};
} catch {
HANDLECATCH;
};
[_hashKeys, []];

View File

@ -0,0 +1,7 @@
//fnc_hashListCreateList.sqf
#include "script_component.hpp"
private ["_keys"];
_keys = _this select 0;
[_keys,[]];

View File

@ -0,0 +1,17 @@
//fnc_hashListPush.sqf
#include "script_component.hpp"
private ["_hashList", "_value"];
_hashList = _this select 0;
_value = _this select 1;
ERRORDATA(2);
try {
if(VALIDHASH(_hashList)) then {
[_hashList, (count (_hashList select 1)), _value] call FUNC(hashListSet);
} else {
ERROR("Input hashlist in push not valid");
};
} catch {
HANDLECATCH;
};

View File

@ -0,0 +1,27 @@
//fnc_hashListSelect.sqf
#include "script_component.hpp"
private ["_hashList", "_index", "_hash", "_keys", "_hashes", "_values"];
_hashList = _this select 0;
_index = _this select 1;
ERRORDATA(2);
_hash = nil;
try {
if(VALIDHASH(_hashList)) then {
_keys = _hashList select 0;
_hashes = _hashList select 1;
if(_index < (count _hashes)) then {
_values = _hashes select _index;
_hash = [_keys, _values, 1];
} else {
ERROR("Index of hashlist is out of range");
};
} else {
ERROR("Input hashlist is not valid");
};
} catch {
HANDLECATCH;
};
_hash;

View File

@ -0,0 +1,24 @@
//fnc_hashListSet.sqf
#include "script_component.hpp"
private ["_hashList", "_index", "_value", "_vals"];
_hashList = _this select 0;
_index = _this select 1;
_value = _this select 2;
ERRORDATA(3);
try {
if(VALIDHASH(_hashList)) then {
if(VALIDHASH(_value)) then {
_vals = _value select 1;
(_hashList select 1) set[_index, _vals];
} else {
ERROR("Set hash in hashlist is not valid");
};
} else {
ERROR("Input hashlist is not valid");
};
} catch {
HANDLECATCH;
};

View File

@ -0,0 +1,30 @@
//fnc_hashRem.sqf
#include "script_component.hpp"
private ["_hash", "_key", "_val", "_index"];
_hash = _this select 0;
_key = _this select 1;
ERRORDATA(2);
_val = nil;
try {
if(VALIDHASH(_hash)) then {
_index = (_hash select 0) find _key;
if(_index != -1) then {
(_hash select 1) set[_index, "ACREHASHREMOVEDONOTUSETHISVAL"];
// is this hash is not part of a hash list?
// if it is we need to leave the keys intact.
if((count _hash) == 2) then {
// if this is a standalone hash then we can clean it up
(_hash select 0) set[_index, "ACREHASHREMOVEDONOTUSETHISVAL"];
_hash set[0, ((_hash select 0) - ["ACREHASHREMOVEDONOTUSETHISVAL"])];
_hash set[1, ((_hash select 1) - ["ACREHASHREMOVEDONOTUSETHISVAL"])];
};
};
} else {
ERROR("Input hash is not valid");
};
} catch {
HANDLECATCH;
};
true

View File

@ -0,0 +1,27 @@
//fnc_hashSet.sqf
#include "script_component.hpp"
private ["_hash", "_key", "_val", "_index"];
// diag_log text format["%1 HASH SET: %2", diag_tickTime, _this];
_hash = _this select 0;
_key = _this select 1;
_val = _this select 2;
ERRORDATA(3);
try {
if(VALIDHASH(_hash)) then {
_index = (_hash select 0) find _key;
if(_index == -1) then {
_index = (_hash select 0) find "ACREHASHREMOVEDONOTUSETHISVAL";
if(_index == -1) then {
_index = (count (_hash select 0));
};
(_hash select 0) set[_index, _key];
};
(_hash select 1) set[_index, _val];
} else {
ERROR("Input hash is not valid");
};
} catch {
HANDLECATCH;
};

View File

@ -1 +1,13 @@
#include "\z\ace\addons\common\script_component.hpp"
#include "\z\ace\addons\common\script_component.hpp"
#define VALIDHASH(hash) (IS_ARRAY(hash) && {(count hash) >= 2} && {IS_ARRAY(hash select 0)} && {IS_ARRAY(hash select 1)})
#define ERROR(msg) throw msg + format[" @ %1:%2", _callFrom, _lineNo]
#define HANDLECATCH diag_log text _exception; assert(exception=="")
#define ERRORDATA(c) private ["_callFrom", "_lineNo"];\
_callFrom = "";\
_lineNo = -1;\
if((count _this) > c) then {\
_callFrom = _this select c;\
_lineNo = _this select c+1;\
};

View File

@ -225,3 +225,16 @@
#define EFUNC(var1,var2) TRIPLES(DOUBLES(PREFIX,var1),fnc,var2)
#endif
#define HASH_CREATE ([] call EFUNC(common,hashCreate))
#define HASH_SET(hash, key, val) ([hash, key, val, __FILE__, __LINE__] call EFUNC(common,hashSet))
#define HASH_GET(hash, key) ([hash, key, __FILE__, __LINE__] call EFUNC(common,hashGet))
#define HASH_REM(hash, key) ([hash, key, __FILE__, __LINE__] call EFUNC(common,hashRem))
#define HASH_HASKEY(hash, key) ([hash, key, __FILE__, __LINE__] call EFUNC(common,hashHasKey))
#define HASHLIST_CREATELIST(keys) ([keys] call EFUNC(common,hashListCreateList))
#define HASHLIST_CREATEHASH(hashList) ([hashList] call EFUNC(common,hashListCreateHash))
#define HASHLIST_SELECT(hashList, index) ([hashList, index, __FILE__, __LINE__] call EFUNC(common,hashListSelect))
#define HASHLIST_SET(hashList, index, value) ([hashList, index, value, __FILE__, __LINE__] call EFUNC(common,hashListSet))
#define HASHLIST_PUSH(hashList, value) ([hashList, value, __FILE__, __LINE__] call EFUNC(common,hashListPush))