Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::DataExchange Namespace Reference

Namespaces

namespace  Compression
 FILE DEPRECATED.
 
namespace  JSON
 

Classes

class  Atom
 An Atom is like a String, except that its much cheaper to copy/store/compare, and the semantics of compare are queer. More...
 
struct  AtomManager_Default
 
class  BadFormatException
 
struct  DefaultConstructForRead
 algorithm used by ObjectOrientedMapper to construct an empty object to read (before fill in fields). More...
 
struct  DefaultSerializer
 function object which serializes type T to a BLOB (or BLOB like) object More...
 
class  InternetMediaType
 
class  InternetMediaTypeNotSupportedException
 
class  InternetMediaTypeRegistry
 
class  ObjectVariantMapper
 ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transparently mapped into and out of XML, JSON, etc. More...
 
class  OptionsFile
 
struct  StructFieldMetaInfo
 
class  TypedBLOB
 TypedBLOB is a named tuple<Memory::BLOB, optional<InternetMediaType>> - with friendlier names, and serialization properties. More...
 
class  VariantValue
 Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in any weakly typed language (like JavaScript, Lisp, etc) More...
 

Concepts

concept  IDefaultConstructForRead
 IDefaultConstructForRead checks if argument T is either default_initializable, or has been specialized to allow working with ObjectVariantMapper::ToObject.
 

Enumerations

enum class  ValidationStrategy { eAssertion , eThrow }
 

Functions

template<typename RANGE_TYPE >
RANGE_TYPE CheckedConverter_Range (const typename RANGE_TYPE::value_type &s, const typename RANGE_TYPE::value_type &e)
 
template<typename RANGE_TYPE >
RANGE_TYPE::ElementType CheckedConverter_ValueInRange (typename RANGE_TYPE::ElementType val, const RANGE_TYPE &range=RANGE_TYPE::FullRange())
 

Detailed Description

Note
Code-Status: Beta

TODO:

OLD RELATED NOTE WHICH IS PARTLY DONE BUT COMPLETE: Add support for array to ResetToDefaultTypeRegistry - like we have for struct - using Sequence<> as the C++ type (maybe others too, vector, more?).

But unclear how todo ArrayOfWhat?? Maybe the CTOR takes to typeids - not sure how well that works?

    This can be moderately efficient, but it is not highly efficient. The use of function
    for the serializer/deserializers adds costs.

    When serializing / deserializing - (e.g to/from JSON or XML) - we construct DOM tree which is
    intrinsically not very cost effective. We DO have the XML sax parser (but that wont work with this).

We could restructure the API so that it was more SAX-like: instead of taking a VariantValue, it took something that virtually acted like a VariantValue (gettype, and for array and map types, iterate over the sub-parts). Similarly - on the FromObject () code - generate a stream of 'write' like calls that contained atom Variants, and start-array/end-array/start-map/end-map calls.

This might allow this code to work better with a more efficient json-reader/writer/xml/reader/writer that also used these sorts of intermediate objects.

Of course, this ALSO might be implementable without any API changes - just using a special 'rep' for VariantValue - that was smart about how to it would accessed etc. Needs some thought.

Anyhow - this is a long-term todo item, so no need to work out details now.

Note
Code-Status: Beta

Enumeration Type Documentation

◆ ValidationStrategy

Many times, in code, the caller knows the arguments are in some valid type restricted range (like if the data comes from an algorithm). Many times, the code doesn't know (like if the data comes from a file).

This enumeration/specification, allows SOME APIs to (usually by default) treat validation/constraint failures as compile time or runtime assertion failures (so not checked in release code).

And sometimes, to indicate the source of the data is untrusted, and the data must be validated (typically resulting in a DataExchange::BadFormatException being thrown).

Stroika has long had this sort of dichotomy/choice (with the aforementioned bias towards assertion checking). This just regularizes the names/types used to indicate that choice.

Often times, and API will be a const, inline, or constexpr version that only does assertions, and will have an OVERLOAD taking this parameter, which does the slower checking (one way or the other).

Enumerator
eAssertion 

For most APIs using ValidationStrategy, this will be the default.

eThrow 

Indicates the data comes from an untrusted source, should be validated, and an exception raised if its invalid.

Definition at line 32 of file ValidationStrategy.h.

Function Documentation

◆ CheckedConverter_Range()

template<typename RANGE_TYPE >
RANGE_TYPE Stroika::Foundation::DataExchange::CheckedConverter_Range ( const typename RANGE_TYPE::value_type &  s,
const typename RANGE_TYPE::value_type &  e 
)

CheckedConverter_Range takes a lower and upper bound, and creates a new RANGE_TYPE object using that lower/upper bound, after validating (similar to @CheckedConverter_ValueInRange, but not exactly the same because of 'openness')

CheckedConverter_Range also checks that the endpoints are valid with respect to the type, and that s <= e.

CheckedConverter_Range () if any values are invalid.

See also
CheckedConverter_ValueInRange

Definition at line 36 of file CheckedConverter.inl.

◆ CheckedConverter_ValueInRange()

template<typename RANGE_TYPE >
RANGE_TYPE::ElementType Stroika::Foundation::DataExchange::CheckedConverter_ValueInRange ( typename RANGE_TYPE::ElementType  val,
const RANGE_TYPE &  range = RANGE_TYPE::FullRange() 
)

CheckedConverter_ValueInRange () will throw BadFormatException{} if the argument 'val' is outside the given argument range.

The 'range' defaults to the RANGE_TYPE::FullRange ().

Note - for floating point ElementType - if the value ('val') is 'really close' to an edge - it will be pinned to the range edge, not treated as out of range.

The returned value is always at least nearly identical to the 'val' passed in, but could be slightly different due to the above floating point near-edge adjustment.