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

#include <Pair.h>

Inheritance diagram for active::serialise::Pair:
Inheritance graph
[legend]
Collaboration diagram for active::serialise::Pair:
Collaboration graph
[legend]

Public Types

enum  FieldIndex { key , value }
 The indices of the default package items.
 
- 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

 Pair (Cargo::Unique key, Cargo::Unique value, utility::String::Option name=std::nullopt)
 
 Pair (const Pair &source)=delete
 No copy constructor.
 
virtual ~Pair ()=default
 Destructor.
 
CargogetKey () const
 
CargogetValue () const
 
virtual bool fillInventory (Inventory &inventory) const
 
virtual const Inventory::ItemkeyItem () const
 
virtual const Inventory::ItemvalueItem () const
 
virtual Cargo::Unique getCargo (const Inventory::Item &item) const
 
virtual void setDefault ()
 
virtual bool validate ()
 
auto releaseKey ()
 
auto releaseData ()
 
- Public Member Functions inherited from active::serialise::Package
bool isRoot () const
 
virtual bool isAttributeFirst () const
 
virtual bool insert (Cargo::Unique &&cargo, const Inventory::Item &item)
 
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 ()
 

Static Public Attributes

static Inventory::Item keyEntry = Inventory::Item{ fieldID[key], key, attribute, true, &typeid(Pair)}
 The default inventory item for the pair key.
 
static Inventory::Item valueEntry = Inventory::Item{ fieldID[value], value, attribute, true, &typeid(Pair)}
 The default inventory item for the pair value.
 

Detailed Description

A serialisable pair, e.g. key and value

Use this class as a simple wrapper for serialisable data that should be stored in pairs, e.g. dictionary items. The wrapper acts as an enclosing package for the key and value. Both the key and value can define an inventory or inventory items, but this wrapper will provide defaults if these are undefined.

Constructor & Destructor Documentation

◆ Pair()

Pair::Pair ( Cargo::Unique key,
Cargo::Unique value,
utility::String::Option name = std::nullopt )

Constructor

Parameters
keyThe pair key
valueThe pair value
nameOptional name for the key/value pair

Member Function Documentation

◆ fillInventory()

bool Pair::fillInventory ( Inventory & inventory) const
virtual

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()

Cargo::Unique Pair::getCargo ( const Inventory::Item & item) const
virtual

Get the specified cargo

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

Implements active::serialise::Cargo.

◆ getKey()

Cargo * active::serialise::Pair::getKey ( ) const
inline

Get the pair key

Returns
The pair key (this package retains ownership)

◆ getValue()

Cargo * active::serialise::Pair::getValue ( ) const
inline

Get the pair value

Returns
The pair value (this package retains ownership)

◆ keyItem()

virtual const Inventory::Item & active::serialise::Pair::keyItem ( ) const
inlinevirtual

Get the default inventory item for the key

Returns
The default key item
Here is the caller graph for this function:

◆ releaseData()

auto active::serialise::Pair::releaseData ( )
inline

Release the pair value

Returns
The pair value (caller takes ownership - the value held by this package is reset to nullptr)

◆ releaseKey()

auto active::serialise::Pair::releaseKey ( )
inline

Release the pair key

Returns
The pair key (caller takes ownership - the key held by this package is reset to nullptr)

◆ setDefault()

void Pair::setDefault ( )
virtual

Set to the default package content

Reimplemented from active::serialise::Package.

◆ validate()

bool Pair::validate ( )
virtual

Validate the cargo data

Returns
True if the data has been validated

Reimplemented from active::serialise::Cargo.

◆ valueItem()

virtual const Inventory::Item & active::serialise::Pair::valueItem ( ) const
inlinevirtual

Get the default inventory item for the value

Returns
The default value item
Here is the caller graph for this function:

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