Two new managed type, making data objects prototyping and serialization/deserialization to modern formats simple and easy.
Variant is managed type (like string or array), so it not need to be manually allocated or destroyed.
Also, Variant allow using properties and methods even if they not defined for this type. And allow in runtime detect type of data contained in variant.
https://github.com/serbod/NovaLib/blob/master/VarDicts.pasVariant Dictionary - contain name-value pairs, behave like object in JavaScript. Can store any Variant as value, even another Dictionary.
Auto-sorted by names, binary search used to get value by name
Usage:
var MyDict: Variant;
MyDict := VarDictCreate();
MyDict.Field1 := 1;
MyDict.Field2 := 'test';
WriteLn(MyDict); // {Field1:1,Field2:"test"}
Methods:
GetCount() - get stored items count
GetValue(Index) - get item value for given Index (0..GetCount()-1)
GetName(Index) - get item name for given Index (0..GetCount()-1)
GetNameIndex(Name) - get index of item Name, or <0 if Name not found
SetValue(Name, Value) - set value for Name
https://github.com/serbod/NovaLib/blob/master/VarLists.pasVariant List - dynamic array of any Variant types
Usage:
var MyList: Variant;
MyList := VarListCreate;
MyList.AddValue(1);
MyList.AddValue('test');
WriteLn(MyList.GetValue(0), MyList.GetValue(1));
Methods:
SetCapacity(MaxCount) - allocate memory for list values
AddValue(Value) - add value to end of list. Capacity increased if needed
GetCount() - get stored items count
GetValue(Index) - get item value for given index (0..GetCount()-1)
SetValue(Index, Value) - set item value for given index (0..GetCount()-1)
Variant <-> JSON serialization
https://github.com/serbod/NovaLib/blob/master/JsonUnit.pasVariant <-> Bencode serialization
https://github.com/serbod/NovaLib/blob/master/BencodeUnit.pas