@ -62,15 +62,7 @@ public final function Iter Iterate()
/**
/**
* Returns stored `AcediaObject` from the caller storage
* Returns stored `AcediaObject` from the caller storage
* (or from it's sub-storages) via given `Text` path.
* (or from it's sub-storages) via given `JSONPointer` path.
*
* Path is treated like a [JSON pointer](https://tools.ietf.org/html/rfc6901).
* If given path does not start with "/" character (like it is expected from
* a json pointer) - it will be added automatically.
* This means that "foo/bar" is treated like "/foo/bar" and
* "path" like "/path". However, empty `Text` is treated like itself (""),
* since it constitutes a valid JSON pointer (it will point at a caller
* collection itself).
*
*
* Acedia provides two collections:
* Acedia provides two collections:
* 1. `DynamicArray` is treated as a JSON array in the context of
* 1. `DynamicArray` is treated as a JSON array in the context of
@ -85,34 +77,27 @@ public final function Iter Iterate()
* integrated with this method by making it a sub-class of `Collection` and
* integrated with this method by making it a sub-class of `Collection` and
* appropriately defining `GetByText()` protected method.
* appropriately defining `GetByText()` protected method.
*
*
* Making only getter available (without setters or `Take...()` methods that
* also remove returned element) is a deliberate choice made to reduce amount
* of possible errors when working with collections.
*
* There is no requirement that all stored values must be reachable by
* There is no requirement that all stored values must be reachable by
* this method (i.e. `AssociativeArray` only lets you access values with
* this method (i.e. `AssociativeArray` only lets you access values with
* `Text` keys).
* `Text` keys).
*
*
* @param jsonPointerAsText Path, given by a JSON pointer.
* @param jsonPointer Path, given by a JSON pointer.
* @return An item `jsonPointerAsText` is referring to (according to the above
* @return An item `jsonPointerAsText` is referring to (according to the above
* stated rules). `none` if such item does not exist.
* stated rules). `none` if such item does not exist.
*/
*/
public final function AcediaObject GetItemByPointer(Text jsonPointerAsText )
public final function AcediaObject GetItemByJSON(JSON Pointer jsonPointer)
{
{
local int segmentIndex;
local int segmentIndex;
local Text nextSegment;
local Text nextSegment;
local AcediaObject result;
local AcediaObject result;
local JSONPointer pointer;
local Collection nextCollection;
local Collection nextCollection;
if (jsonPointerAsText == none) return none;
if (jsonPointer == none) return none;
if (jsonPointerAsText.IsEmpty()) return self;
if (jsonPointer.GetLength() < 1) return self;
pointer = _.json.Pointer(jsonPointerAsText);
if (jsonPointerAsText.GetLength() < 1) return self;
nextCollection = self;
nextCollection = self;
while (segmentIndex < p ointer.GetLength() - 1)
while (segmentIndex < jsonP ointer.GetLength() - 1)
{
{
nextSegment = p ointer.GetComponent(segmentIndex);
nextSegment = jsonP ointer.GetComponent(segmentIndex);
nextCollection = Collection(nextCollection.GetByText(nextSegment));
nextCollection = Collection(nextCollection.GetByText(nextSegment));
_.memory.Free(nextSegment);
_.memory.Free(nextSegment);
if (nextCollection == none) {
if (nextCollection == none) {
@ -122,11 +107,59 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
}
}
if (nextCollection != none)
if (nextCollection != none)
{
{
nextSegment = p ointer.GetComponent(segmentIndex);
nextSegment = jsonP ointer.GetComponent(segmentIndex);
result = nextCollection.GetByText(nextSegment);
result = nextCollection.GetByText(nextSegment);
_.memory.Free(nextSegment);
_.memory.Free(nextSegment);
}
}
_.memory.Free(pointer);
_.memory.Free(jsonPointer);
return result;
}
/**
* Returns stored `AcediaObject` from the caller storage
* (or from it's sub-storages) via given `Text` path.
*
* Path is treated like a
* [JSON pointer](https://tools.ietf.org/html/rfc6901)
* with an additional fix applied:
* If given path does not start with "/" character (like it is expected
* from a json pointer) - it will be added automatically.
* This means that "foo/bar" is treated like "/foo/bar" and
* "path" like "/path". However, empty `Text` is treated like itself (""),
* since it constitutes a valid JSON pointer (it will point at a caller
* collection itself).
*
* Acedia provides two collections:
* 1. `DynamicArray` is treated as a JSON array in the context of
* JSON pointers and passed variable names are treated as a `Text`
* representation of it's integer indices;
* 2. `AssociativeArray` is treated as a JSON object in the context of
* JSON pointers and passed variable names are treated as it's
* `Text` keys (to refer to an element with an empty key, use "/",
* since "" is treated as a JSON pointer and refers to
* the array itself).
* It is also possible to define your own collection type that will also be
* integrated with this method by making it a sub-class of `Collection` and
* appropriately defining `GetByText()` protected method.
*
* There is no requirement that all stored values must be reachable by
* this method (i.e. `AssociativeArray` only lets you access values with
* `Text` keys).
*
* @param jsonPointer Path, given by a JSON pointer.
* @return An item `jsonPointerAsText` is referring to (according to the above
* stated rules). `none` if such item does not exist.
*/
public final function AcediaObject GetItemBy(Text jsonPointerAsText)
{
local AcediaObject result;
local JSONPointer jsonPointer;
if (jsonPointerAsText == none) return none;
if (jsonPointerAsText.IsEmpty()) return self;
jsonPointer = _.json.Pointer(jsonPointerAsText);
result = GetItemByJSON(jsonPointer);
_.memory.Free(jsonPointer);
return result;
return result;
}
}
@ -134,7 +167,7 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
* Returns a `bool` value stored (in the caller `Collection` or
* Returns a `bool` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `BoolBox` or `BoolRef`
* Referred value must be stored as `BoolBox` or `BoolRef`
* (or one of their sub-classes) for this method to work.
* (or one of their sub-classes) for this method to work.
@ -146,14 +179,14 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
* @return `bool` value, stored at `jsonPointerAsText` or `defaultValue` if it
* @return `bool` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
* is missing or has a different type.
*/
*/
public final function bool GetBoolByPointer (
public final function bool GetBoolBy(
Text jsonPointerAsText,
Text jsonPointerAsText,
optional bool defaultValue)
optional bool defaultValue)
{
{
local AcediaObject result;
local AcediaObject result;
local BoolBox asBox;
local BoolBox asBox;
local BoolRef asRef;
local BoolRef asRef;
result = GetItemByPointer (jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
if (result == none) {
return defaultValue;
return defaultValue;
}
}
@ -172,7 +205,7 @@ public final function bool GetBoolByPointer(
* Returns a `byte` value stored (in the caller `Collection` or
* Returns a `byte` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `ByteBox` or `ByteRef`
* Referred value must be stored as `ByteBox` or `ByteRef`
* (or one of their sub-classes) for this method to work.
* (or one of their sub-classes) for this method to work.
@ -184,14 +217,14 @@ public final function bool GetBoolByPointer(
* @return `byte` value, stored at `jsonPointerAsText` or `defaultValue` if it
* @return `byte` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
* is missing or has a different type.
*/
*/
public final function byte GetByteByPointer (
public final function byte GetByteBy(
Text jsonPointerAsText,
Text jsonPointerAsText,
optional byte defaultValue)
optional byte defaultValue)
{
{
local AcediaObject result;
local AcediaObject result;
local ByteBox asBox;
local ByteBox asBox;
local ByteRef asRef;
local ByteRef asRef;
result = GetItemByPointer (jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
if (result == none) {
return defaultValue;
return defaultValue;
}
}
@ -210,7 +243,7 @@ public final function byte GetByteByPointer(
* Returns a `int` value stored (in the caller `Collection` or
* Returns a `int` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `IntBox` or `IntRef`
* Referred value must be stored as `IntBox` or `IntRef`
* (or one of their sub-classes) for this method to work.
* (or one of their sub-classes) for this method to work.
@ -222,14 +255,14 @@ public final function byte GetByteByPointer(
* @return `int` value, stored at `jsonPointerAsText` or `defaultValue` if it
* @return `int` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
* is missing or has a different type.
*/
*/
public final function int GetIntByPointer (
public final function int GetIntBy(
Text jsonPointerAsText,
Text jsonPointerAsText,
optional int defaultValue)
optional int defaultValue)
{
{
local AcediaObject result;
local AcediaObject result;
local IntBox asBox;
local IntBox asBox;
local IntRef asRef;
local IntRef asRef;
result = GetItemByPointer (jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
if (result == none) {
return defaultValue;
return defaultValue;
}
}
@ -248,7 +281,7 @@ public final function int GetIntByPointer(
* Returns a `float` value stored (in the caller `Collection` or
* Returns a `float` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `FloatBox` or `FloatRef`
* Referred value must be stored as `FloatBox` or `FloatRef`
* (or one of their sub-classes) for this method to work.
* (or one of their sub-classes) for this method to work.
@ -260,14 +293,14 @@ public final function int GetIntByPointer(
* @return `float` value, stored at `jsonPointerAsText` or `defaultValue` if it
* @return `float` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
* is missing or has a different type.
*/
*/
public final function float GetFloatByPointer (
public final function float GetFloatBy(
Text jsonPointerAsText,
Text jsonPointerAsText,
optional float defaultValue)
optional float defaultValue)
{
{
local AcediaObject result;
local AcediaObject result;
local FloatBox asBox;
local FloatBox asBox;
local FloatRef asRef;
local FloatRef asRef;
result = GetItemByPointer (jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
if (result == none) {
return defaultValue;
return defaultValue;
}
}
@ -286,7 +319,7 @@ public final function float GetFloatByPointer(
* Returns a `Text` value stored (in the caller `Collection` or
* Returns a `Text` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `Text` (or one of it's sub-classes,
* Referred value must be stored as `Text` (or one of it's sub-classes,
* such as `MutableText`) for this method to work.
* such as `MutableText`) for this method to work.
@ -295,16 +328,16 @@ public final function float GetFloatByPointer(
* @return `Text` value, stored at `jsonPointerAsText` or `none` if it
* @return `Text` value, stored at `jsonPointerAsText` or `none` if it
* is missing or has a different type.
* is missing or has a different type.
*/
*/
public final function Text GetTextByPointer (Text jsonPointerAsText)
public final function Text GetTextBy(Text jsonPointerAsText)
{
{
return Text(GetItemByPointer (jsonPointerAsText));
return Text(GetItemBy(jsonPointerAsText));
}
}
/**
/**
* Returns an `AssociativeArray` value stored (in the caller `Collection` or
* Returns an `AssociativeArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `AssociativeArray`
* Referred value must be stored as `AssociativeArray`
* (or one of it's sub-classes) for this method to work.
* (or one of it's sub-classes) for this method to work.
@ -314,17 +347,17 @@ public final function Text GetTextByPointer(Text jsonPointerAsText)
* @return `AssociativeArray` value, stored at `jsonPointerAsText` or
* @return `AssociativeArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
* `none` if it is missing or has a different type.
*/
*/
public final function AssociativeArray GetAssociativeArrayByPointer (
public final function AssociativeArray GetAssociativeArrayBy(
Text jsonPointerAsText)
Text jsonPointerAsText)
{
{
return AssociativeArray(GetItemByPointer (jsonPointerAsText));
return AssociativeArray(GetItemBy(jsonPointerAsText));
}
}
/**
/**
* Returns an `DynamicArray` value stored (in the caller `Collection` or
* Returns an `DynamicArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer ()` for more information.
* See `GetItemBy()` for more information.
*
*
* Referred value must be stored as `DynamicArray`
* Referred value must be stored as `DynamicArray`
* (or one of it's sub-classes) for this method to work.
* (or one of it's sub-classes) for this method to work.
@ -334,10 +367,210 @@ public final function AssociativeArray GetAssociativeArrayByPointer(
* @return `DynamicArray` value, stored at `jsonPointerAsText` or
* @return `DynamicArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
* `none` if it is missing or has a different type.
*/
*/
public final function DynamicArray GetDynamicArrayByPointer(
public final function DynamicArray GetDynamicArrayBy(Text jsonPointerAsText)
Text jsonPointerAsText)
{
return DynamicArray(GetItemBy(jsonPointerAsText));
}
/**
* Returns a `bool` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `BoolBox` or `BoolRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `bool` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `bool` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function bool GetBoolByJSON(
JSONPointer jsonPointer,
optional bool defaultValue)
{
local AcediaObject result;
local BoolBox asBox;
local BoolRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = BoolBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = BoolRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `byte` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `ByteBox` or `ByteRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `byte` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `byte` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function byte GetByteByJSON(
JSONPointer jsonPointer,
optional byte defaultValue)
{
local AcediaObject result;
local ByteBox asBox;
local ByteRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = ByteBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = ByteRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `int` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `IntBox` or `IntRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `int` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `int` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function int GetIntByJSON(
JSONPointer jsonPointer,
optional int defaultValue)
{
local AcediaObject result;
local IntBox asBox;
local IntRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = IntBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = IntRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `float` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `FloatBox` or `FloatRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `float` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `float` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function float GetFloatByJSON(
JSONPointer jsonPointer,
optional float defaultValue)
{
local AcediaObject result;
local FloatBox asBox;
local FloatRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = FloatBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = FloatRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `Text` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `Text` (or one of it's sub-classes,
* such as `MutableText`) for this method to work.
*
* @param jsonPointer JSON path to the `Text` value.
* @return `Text` value, stored at `jsonPointerAsText` or `none` if it
* is missing or has a different type.
*/
public final function Text GetTextByJSON(JSONPointer jsonPointer)
{
return Text(GetItemByJSON(jsonPointer));
}
/**
* Returns an `AssociativeArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `AssociativeArray`
* (or one of it's sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `AssociativeArray` value.
* @return `AssociativeArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function AssociativeArray GetAssociativeArrayByJSON(
JSONPointer jsonPointer)
{
return AssociativeArray(GetItemByJSON(jsonPointer));
}
/**
* Returns an `DynamicArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `DynamicArray`
* (or one of it's sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `DynamicArray` value.
* @return `DynamicArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function DynamicArray GetDynamicArrayByJSON(
JSONPointer jsonPointer)
{
{
return DynamicArray(GetItemByPointer(jsonPointerAsText));
return DynamicArray(GetItemByJSON(jsonPointer ));
}
}
defaultproperties
defaultproperties