sbepp
Loading...
Searching...
No Matches
Traits

sbepp provides a way to access nearly all information provided by XML schema and other useful properties via traits mechanism.


Tags

To access a trait you need a schema entity's tag. Tag is basically a path to an entity. The tag for a schema itself (for sbepp::schema_traits) is <schema_name>::schema. Tags for messages have form <schema_name>::schema::messages::<msg_name> and tags for types <schema_name>::schema::types::<type_name>. Here's an example:

<?xml version="1.0" encoding="UTF-8"?>
<!-- schema_name::schema -->
<sbe:messageSchema package="schema_name">
<types>
<!-- schema_name::schema::types::uint32_req -->
<type name="uint32_req" primitiveType="uint32"/>
<!-- schema_name::schema::types::numbers -->
<enum name="numbers" encodingType="uint8">
<!-- schema_name::schema::types::numbers::One -->
<validValue name="One">1</validValue>
<!-- schema_name::schema::types::numbers::Two -->
<validValue name="Two">2</validValue>
</enum>
<!-- schema_name::schema::types::options -->
<set name="options" encodingType="uint8">
<!-- schema_name::schema::types::options::A -->
<choice name="A">0</choice>
<!-- schema_name::schema::types::options::B -->
<choice name="B">2</choice>
</set>
<!-- schema_name::schema::types::groupSizeEncoding -->
<composite name="groupSizeEncoding">
<!-- schema_name::schema::types::groupSizeEncoding::blockLength -->
<type name="blockLength" primitiveType="uint16"/>
<!-- schema_name::schema::types::groupSizeEncoding::numInGroup -->
<type name="numInGroup" primitiveType="uint16"/>
</composite>
</types>
<!-- schema_name::schema::messages::msg -->
<sbe:message name="msg" id="1">
<!-- schema_name::schema::messages::msg::field -->
<field name="field" id="1" type="uint32"/>
<!-- schema_name::schema::messages::msg::group -->
<group name="group" id="2">
<!-- schema_name::schema::messages::msg::group::field -->
<field name="field" id="1" type="uint32"/>
</group>
<!-- schema_name::schema::messages::msg::data -->
<data name="data" id="3" type="varDataEncoding"/>
</sbe:message>
</sbe:messageSchema>

For built-in types like sbepp::char_t, the type itself works as a tag, e.g.

// get maxValue of a built-in required `char` type
static constexpr primitive_type max_value() noexcept
Returns maxValue. Available only if length() == 1 and presence() != field_presence::constant

Implementation-wise, each tag is an empty struct, it's possible to test tag kind using sbepp::is_message_tag and similar helpers.

See also
Tag-based accessors
sbepp::traits_tag

Using traits

Similar to std::numeric_limits, sbepp traits are accessed like trait_name<Tag>::value():

auto null_value = sbepp::type_traits<
schema_name::schema::types::optional>::null_value();
static constexpr version_t version() noexcept
Returns version attribute.
Provides various traits and attributes of a <type> element.
Definition sbepp.hpp:4043

For the list of available traits see Traits list.

Note that there's no such thing as sbepp::ref_traits because <ref> fields always refer to another type. To access their properties, use traits corresponding to the referred type (e.g. sbepp::set_traits if <ref> refers to a <set>).