Skip to content

Commit

Permalink
add CBA_fnc_(de)serializeNamespace (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
commy2 authored Mar 2, 2017
1 parent f25d711 commit 4864914
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/hashes/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class CfgFunctions
description = "Parses a YAML file into a nested array/Hash structure.";
file = "\x\cba\addons\hashes\fnc_parseYAML.sqf";
};
PATHTO_FNC(serializeNamespace);
PATHTO_FNC(deserializeNamespace);
};
};
};
40 changes: 40 additions & 0 deletions addons/hashes/fnc_deserializeNamespace.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_deserializeNamespace
Description:
Creates namespace containing all variables stored in a CBA hash.
Parameters:
_hash - a hash <ARRAY>
_isGlobal - create a global namespace (optional, default: false) <BOOLEAN>
Returns:
_namespace - a namespace <LOCATION, OBJECT>
Examples:
(begin example)
private _hash = profileNamespace getVariable "My_serializedNamespace";
My_namespace = [_hash] call CBA_fnc_deserializeNamespace;
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(deserializeNamespace);

params [["_hash", [], [[]]], ["_isGlobal", false, [false]]];

private _namespace = _isGlobal call CBA_fnc_createNamespace;

if (_isGlobal) then {
[_hash, {
_namespace setVariable [_key, _value, true];
}] call CBA_fnc_hashEachPair;
} else {
[_hash, {
_namespace setVariable [_key, _value];
}] call CBA_fnc_hashEachPair;
};

_namespace
33 changes: 33 additions & 0 deletions addons/hashes/fnc_serializeNamespace.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_serializeNamespace
Description:
Creates CBA hash containing all variables stored in a namespace.
Parameters:
_namespace - a namespace <LOCATION, OBJECT>
Returns:
_hash - a hash <ARRAY>
Examples:
(begin example)
private _hash = _namespace call CBA_fnc_serializeNamespace;
profileNamespace setVariable ["My_serializedNamespace", _hash];
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(serializeNamespace);

params [["_namespace", locationNull, [locationNull, objNull]]];

private _hash = [] call CBA_fnc_hashCreate;

{
[_hash, _x, _namespace getVariable _x] call CBA_fnc_hashSet;
} forEach allVariables _namespace;

_hash

0 comments on commit 4864914

Please sign in to comment.