OpenAssetIO [beta]
An abstract API for generalising interactions between a host application and an asset management system

A transport-level container for data exchange between a host and a manager. More...

#include <TraitsData.hpp>

Public Types

using Ptr = TraitsDataPtr
 
using ConstPtr = TraitsDataConstPtr
 

Public Member Functions

 ~TraitsData ()
 Defaulted destructor. More...
 
trait::TraitSet traitSet () const
 Return the trait IDs held by the instance. More...
 
bool hasTrait (const trait::TraitId &traitId) const
 Return whether this instance has the given trait. More...
 
void addTrait (const trait::TraitId &traitId)
 Add the specified trait to this instance. More...
 
void addTraits (const trait::TraitSet &traitSet)
 Add the specified traits to this instance. More...
 
bool getTraitProperty (trait::property::Value *out, const trait::TraitId &traitId, const trait::property::Key &propertyKey) const
 Get the value of a given trait property, if the property has been set. More...
 
void setTraitProperty (const trait::TraitId &traitId, const trait::property::Key &propertyKey, trait::property::Value propertyValue)
 Set the value of given trait property. More...
 
trait::property::KeySet traitPropertyKeys (const trait::TraitId &traitId) const
 Returns the properties set for a given trait. More...
 
bool operator== (const TraitsData &other) const
 Compares instances based on their trait and property values. More...
 

Static Public Member Functions

static TraitsDataPtr make ()
 Construct an empty instance, with no traits. More...
 
static TraitsDataPtr make (const trait::TraitSet &traitSet)
 Construct such that this instance has the given set of traits. More...
 
static TraitsDataPtr make (const TraitsDataConstPtr &other)
 Construct such that this instance is a deep copy of the other. More...
 

Detailed Description

A transport-level container for data exchange between a host and a manager.

The Specification system combines one or more traits into a Trait Set to classify concepts within the API. Traits may define a number of simple-typed properties, allowing them to be used to exchange data between interested parties.

A key requirement of the traits system is to be fully run-time extensible. Additional specifications and traits can be defined as required by any particular API integration.

This is accomplished by breaking the system into two components:

  • A simple, generic data container that holds a trait set and its properties.
  • Custom views on this container that provide strongly-typed access.

TraitsData is the transport-layer container that holds a Trait Set, and any values set for the properties of these traits. It has no semantic understanding of the data, providing simple "by name" set/get of traits and their properties.

This allows easy serialization and exchange of this data between languages and sub-systems using the low-level introspection functionality provided by this class.

As generic access to the container's data (based on "well-known-strings") is inherently unstable. Instances of this class should generally be wrapped in one of the specialized specification or Trait derived "views" at runtime by a host or manager to ensure consistent access to the correct keys.

Trait property keys are always strings. Property values are strings, integers, floating point, or booleans. Any of a trait's properties can be legitimately left unset - it is up to the consumer (host or manager, depending on the API method) to decide how this should be handled.

Todo:
Add InfoDictionary trait property value type.
See also
trait::property
Entities, Traits and Specifications

Member Typedef Documentation

using Ptr = TraitsDataPtr

Constructor & Destructor Documentation

~TraitsData ( )

Defaulted destructor.

Member Function Documentation

void addTrait ( const trait::TraitId traitId)

Add the specified trait to this instance.

If this instance already has this trait, it is a no-op.

Parameters
traitIdID of the trait to add.
void addTraits ( const trait::TraitSet traitSet)

Add the specified traits to this instance.

If this instance already has any of the supplied traits, they are skipped.

Parameters
traitSetA trait set with the traits to add.
bool getTraitProperty ( trait::property::Value out,
const trait::TraitId traitId,
const trait::property::Key propertyKey 
) const

Get the value of a given trait property, if the property has been set.

Parameters
[out]outStorage for result, only written to if the property is set.
traitIdID of trait to query.
propertyKeyKey of trait's property to query.
Returns
true if value was found, false if it is unset.
Exceptions
<tt>std::out_of_range</tt>if this instance does not have this trait.
bool hasTrait ( const trait::TraitId traitId) const

Return whether this instance has the given trait.

Parameters
traitIdID of trait to check for.
Returns
true if trait is present, false otherwise.
static TraitsDataPtr make ( )
static

Construct an empty instance, with no traits.

static TraitsDataPtr make ( const trait::TraitSet traitSet)
static

Construct such that this instance has the given set of traits.

Parameters
traitSetThe constituent traits IDs.
static TraitsDataPtr make ( const TraitsDataConstPtr other)
static

Construct such that this instance is a deep copy of the other.

Parameters
otherThe instance to copy.
bool operator== ( const TraitsData other) const

Compares instances based on their trait and property values.

Parameters
otherThe instance to compare to.
void setTraitProperty ( const trait::TraitId traitId,
const trait::property::Key propertyKey,
trait::property::Value  propertyValue 
)

Set the value of given trait property.

If the instance does not yet have this trait, it will be added by this call.

Parameters
traitIdID of trait to update.
propertyKeyKey of property to set.
propertyValueValue to set.
trait::property::KeySet traitPropertyKeys ( const trait::TraitId traitId) const

Returns the properties set for a given trait.

If the trait has not been given to this instance, or the trait has no properties set, then it will return an empty set.

trait::TraitSet traitSet ( ) const

Return the trait IDs held by the instance.


The documentation for this class was generated from the following file:
  • /src/src/openassetio-core/include/openassetio/trait/TraitsData.hpp