Tech/LxEngine/lxvar

The class is intended as a simple, convenient class for dealing with arbitrary JSON-like data with reasonable efficiency. In addition to supporting the majority of standard Javascript 'var' functionality, the class also supports various features to aid in intermixing with native C++ types as well as persisting, validating, and responding to value changes.

Primitive types
Support for basic types: bool, int, float, double, and std::string.

1 Implicit conversion is usually frowned upon as a C++ coding technique, as it "hides" what is happening from the reader; however, for a convenience class like lxvar, implicit conversions were deemed a good fit.

Map Specializations
In addition to a standard map implementation, other specialized map implementations are available. These provide the same map interface but also provide additional functionality:



orderedmap
The orderermap implementation behaves like a standard map with one exception: the iteration order is equivalent to the insertion order of the keys. If a value is overwritten for a key, the key retains its original order.

The ordermap requires slightly more memory and is slightly less efficient than a standard map.

Objects
The and  functions can be used to store native C++ types in an lxvar.

query( string path ) -> lxvar
Searches the lxvar for a given property (using JSON syntax) and returns the value of that property. If that property, or any part of the property path, does not exist, then undefined is returned.


 * Using this method alone, there is no way to distinguish between a property that exists and is set to undefined and a property that does not exist and thus returns undefined.

query( string path, type default_value ) -> lxvar
The same as the alternate version of but returns the provided default if the property does not exist or is of an incompatible type.