ActiveLib
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
active::serialise::doc::Object Class Reference

#include <Object.h>

Inheritance diagram for active::serialise::doc::Object:
Inheritance graph
[legend]
Collaboration diagram for active::serialise::doc::Object:
Collaboration graph
[legend]

Public Types

using Unique = std::unique_ptr<Object>
 Unique pointer.
 
using Shared = std::shared_ptr<Object>
 Shared pointer.
 
using Option = std::optional<Object>
 Optional.
 
using base = std::vector<Object>
 Base container - supports an document object hierarchy.
 
using Values = std::vector<setting::ValueSetting>
 Values container - holds all single-value variables from the original class.
 
- Public Types inherited from active::serialise::Package
using Unique = std::unique_ptr<Package>
 Unique pointer.
 
using Shared = std::shared_ptr<Package>
 Shared pointer.
 
- Public Types inherited from active::serialise::Cargo
using Unique = std::unique_ptr<Cargo>
 Unique pointer.
 
using Shared = std::shared_ptr<Cargo>
 Shared pointer.
 
using size_type = std::string::size_type
 Class size type.
 
using sizeOption = std::optional<size_type>
 Optional size type (used to indicate an unspecified or non-existant position)
 

Public Member Functions

 Object ()
 
 Object (const utility::String &type, utility::String::Option objTag=std::nullopt)
 
 Object (const Object &source)=default
 Use the default copy.
 
 Object (Object &&source) noexcept=default
 Use the default rvalue copy.
 
Objectoperator= (Object &&source)=default
 Use default assignment.
 
Objectoperator<< (Object &object)
 
Objectoperator<< (Object &&object)
 
Objectoperator<< (setting::ValueSetting &&value)
 
const Objectobject (const utility::String &tag) const
 
template<typename T >
std::unique_ptr< T > object (const utility::String &tag=utility::String{}) const
 
const setting::ValueSetting::Option value (const utility::String &name) const
 
virtual bool fillInventory (serialise::Inventory &inventory) const override
 
virtual serialise::Cargo::Unique getCargo (const serialise::Inventory::Item &item) const override
 
const ObjectusingHandler (std::shared_ptr< Handler > handler) const
 
virtual void setDefault () override
 
virtual bool validate () override
 
virtual bool insert (Cargo::Unique &&cargo, const serialise::Inventory::Item &item) override
 
ObjectwithType (const utility::String &newType)
 
ObjectwithTag (const utility::String &newTag)
 
- Public Member Functions inherited from active::serialise::Package
bool isRoot () const
 
virtual bool isAttributeFirst () const
 
virtual bool read (const utility::String &source)
 
void setRoot (bool state)
 
virtual bool finaliseAttributes ()
 
- Public Member Functions inherited from active::serialise::Cargo
 Cargo ()
 
 Cargo (const Cargo &source)
 
virtual ~Cargo ()=default
 
virtual void clear ()
 

Public Attributes

utility::String docType
 The document object type - can be used to reconstruct the original object.
 
utility::String tag
 A serialisation tag (identifying the object role)
 
std::vector< Objectobjects
 Child objects of this object.
 
Values values
 Child values of this object, i.e. single-value variables in the original object.
 

Static Public Attributes

static utility::String defaultTag = "obj"
 The Object tag.
 

Detailed Description

A class to represent an object in a persisted document model (via serialisation)

This class forms the basis for a simple document storage model, e.g. a single Object can represent an entire document. Supporting transformations to/from doc::Object provides an easy way to (de)serialise domain-specific content without writing any code directly related to serialisation. This simple document model can be sent to/retrieved from JSON or XML

Refer to the Handler class for more information about defining domain-specific classes that can be deserialised from JSON/XML

Constructor & Destructor Documentation

◆ Object() [1/2]

active::serialise::doc::Object::Object ( )
inline

Default constructor

◆ Object() [2/2]

Object::Object ( const utility::String & type,
utility::String::Option objTag = std::nullopt )

Constructor

Parameters
typeThe document object type - used to reconstruct the original object. NB: Can use type_info.name, but isn't consistent
objTagAn optional serialisation tag (differentiating the object role when there are many of the same type for different purposes)

Member Function Documentation

◆ fillInventory()

bool Object::fillInventory ( serialise::Inventory & inventory) const
overridevirtual

Fill an inventory with the package items

Parameters
inventoryThe inventory to receive the package items
Returns
True if the package has added items to the inventory

Implements active::serialise::Cargo.

Here is the call graph for this function:

◆ getCargo()

active::serialise::Cargo::Unique Object::getCargo ( const serialise::Inventory::Item & item) const
overridevirtual

Get the specified cargo

Parameters
itemThe inventory item to retrieve
Returns
The requested cargo (nullptr on failure)

Implements active::serialise::Cargo.

◆ insert()

bool Object::insert ( Cargo::Unique && cargo,
const serialise::Inventory::Item & item )
overridevirtual

Insert specified cargo into the reconstruct objects - used for cargo with many instances sharing the same ID (e.g. from an array/map)

Parameters
cargoThe cargo to insert
itemThe inventory item linked with the cargo
Returns
True if the cargo was accepted (false will trigger an import failure - simply discard if this is not an error)

Reimplemented from active::serialise::Package.

Here is the call graph for this function:

◆ object() [1/2]

const Object * Object::object ( const utility::String & tag) const

Get an object by tag

Parameters
tagThe required object tag
Returns
The requested object (nullptr if not found)

◆ object() [2/2]

template<typename T >
std::unique_ptr< T > active::serialise::doc::Object::object ( const utility::String & tag = utility::String{}) const
inline

Make an object from this object

Parameters
tagThe required object tag (empty to retrieve this object as an object
Returns
An equivalent object (nullptr on failure)

◆ operator<<() [1/3]

Object & active::serialise::doc::Object::operator<< ( Object && object)
inline

Write operator

Parameters
objectA object to move to the object
Returns
A reference to this

◆ operator<<() [2/3]

Object & active::serialise::doc::Object::operator<< ( Object & object)
inline

Write operator

Parameters
objectA object to move to the object
Returns
A reference to this

◆ operator<<() [3/3]

Object & active::serialise::doc::Object::operator<< ( setting::ValueSetting && value)
inline

Write operator

Parameters
valueA value to move to the object
Returns
A reference to this
Here is the call graph for this function:

◆ setDefault()

void Object::setDefault ( )
overridevirtual

Set to the default package content

Reimplemented from active::serialise::Package.

Here is the call graph for this function:

◆ usingHandler()

const Object & Object::usingHandler ( std::shared_ptr< Handler > handler) const

Define the handler to reconstruct objects

Parameters
handlerThe handler to reconstruct objects
Returns
A reference to this

◆ validate()

bool Object::validate ( )
overridevirtual

Validate the cargo data

Returns
True if the data has been validated

Reimplemented from active::serialise::Cargo.

Here is the call graph for this function:

◆ value()

const ValueSetting::Option Object::value ( const utility::String & name) const

Get an object value by name

Parameters
nameThe value name
Returns
The requested value (nullopt on failure)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ withTag()

Object & active::serialise::doc::Object::withTag ( const utility::String & newTag)
inline

Set the object tag

Parameters
newTagThe object tag
Returns
A reference to this

◆ withType()

Object & active::serialise::doc::Object::withType ( const utility::String & newType)
inline

Set the object type

Parameters
newTypeThe document object type
Returns
A reference to this

The documentation for this class was generated from the following files: