sbepp
Loading...
Searching...
No Matches
sbepp.hpp File Reference

Contains various utilities and implementation details which are required for generated schema headers. More...

#include <array>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <iterator>
#include <limits>
#include <type_traits>
#include <initializer_list>

Go to the source code of this file.

Classes

class  sbepp::detail::byte_range< Byte >
 Base class for all reference semantics types. More...
 
class  sbepp::cursor< Byte >
 Represents cursor which is used in cursor-based API. Clients should not use undocumented methods. More...
 
struct  sbepp::byte_type< View >
 Trait to get view's byte type. More...
 
class  sbepp::detail::composite_base< Byte >
 Base class for composites. More...
 
class  sbepp::detail::message_base< Byte, Header >
 Base class for messages. More...
 
class  sbepp::detail::entry_base< Byte, BlockLengthType >
 Base class for group entries. More...
 
class  sbepp::detail::flat_group_base< Byte, Entry, Dimension >
 Base class for a flat group. More...
 
class  sbepp::detail::nested_group_base< Byte, Entry, Dimension >
 Base class for a nested group. More...
 
class  sbepp::detail::bitset_base< T >
 Base class for bitsets. More...
 
struct  sbepp::default_init_t
 tag for dynamic_array_ref::resize(). Used to skip value initialization. More...
 
class  sbepp::detail::static_array_ref< Byte, Value, N, Tag >
 Represents reference to fixed-size array. More...
 
class  sbepp::detail::dynamic_array_ref< Byte, Value, Length, E >
 Represents reference to dynamic arrays used for <data> elements. More...
 
struct  sbepp::nullopt_t
 Tag type used to initialize optional types with null value. More...
 
class  sbepp::detail::required_base< T, Derived >
 Base class for required types. More...
 
class  sbepp::detail::optional_base< T, Derived >
 Base class for optional types. More...
 
class  sbepp::type_traits< T >
 Provides various traits and attributes of a <type> element. More...
 
class  sbepp::schema_traits< T >
 Provides various traits/attributes of a <messageSchema> element. More...
 
class  sbepp::enum_traits< T >
 Provides various traits/attributes of an <enum> element. More...
 
class  sbepp::enum_value_traits< T >
 Provides various traits/attributes of a <validValue> element. More...
 
class  sbepp::set_traits< T >
 Provides various traits/attributes of a <set> element. More...
 
class  sbepp::set_choice_traits< T >
 Provides various traits/attributes of a <choice> element. More...
 
class  sbepp::composite_traits< T >
 Provides various traits/attributes of a <composite> element. More...
 
class  sbepp::message_traits< T >
 Provides various traits/attributes of a <message> element. More...
 
class  sbepp::field_traits< T >
 Provides various traits/attributes of a <field> element. More...
 
class  sbepp::group_traits< T >
 Provides various traits/attributes of a <group> element. More...
 
class  sbepp::data_traits< T >
 Provides various traits/attributes of a <data> element. More...
 
struct  sbepp::traits_tag< ValueType >
 Maps representation type to its tag. More...
 
class  sbepp::char_t
 Built-in char required type. More...
 
class  sbepp::char_opt_t
 Built-in char optional type. More...
 
class  sbepp::int8_t
 Built-in int8 required type. More...
 
class  sbepp::int8_opt_t
 Built-in int8 optional type. More...
 
class  sbepp::uint8_t
 Built-in uint8 required type. More...
 
class  sbepp::uint8_opt_t
 Built-in uint8 optional type. More...
 
class  sbepp::int16_t
 Built-in int16 required type. More...
 
class  sbepp::int16_opt_t
 Built-in int16 optional type. More...
 
class  sbepp::uint16_t
 Built-in uint16 required type. More...
 
class  sbepp::uint16_opt_t
 Built-in uint16 optional type. More...
 
class  sbepp::int32_t
 Built-in int32 required type. More...
 
class  sbepp::int32_opt_t
 Built-in int32 optional type. More...
 
class  sbepp::uint32_t
 Built-in uint32 required type. More...
 
class  sbepp::uint32_opt_t
 Built-in uint32 optional type. More...
 
class  sbepp::int64_t
 Built-in int64 required type. More...
 
class  sbepp::int64_opt_t
 Built-in int64 optional type. More...
 
class  sbepp::uint64_t
 Built-in uint64 required type. More...
 
class  sbepp::uint64_opt_t
 Built-in uint64 optional type. More...
 
class  sbepp::float_t
 Built-in float required type. More...
 
class  sbepp::float_opt_t
 Built-in float optional type. More...
 
class  sbepp::double_t
 Built-in double required type. More...
 
class  sbepp::double_opt_t
 Built-in double optional type. More...
 
struct  sbepp::unknown_enum_value_tag
 Tag for unknown enum values. More...
 
struct  sbepp::is_enum< T, typename >
 Checks if T is an enumeration. More...
 
struct  sbepp::size_bytes_checked_result
 Result type of size_bytes_checked More...
 

Namespaces

namespace  sbepp
 The main sbepp namespace.
 
namespace  sbepp::detail
 Namespace for various implementation details. Should not be used directly.
 
namespace  sbepp::cursor_ops
 Contains cursor wrappers which allow more precise control over its position.
 

Concepts

concept  sbepp::array_type
 Concept for sbepp::is_array_type<T>::value
 
concept  sbepp::required_type
 Concept for sbepp::is_required_type<T>::value
 
concept  sbepp::optional_type
 Concept for sbepp::is_optional_type<T>::value
 
concept  sbepp::non_array_type
 Concept for sbepp::is_non_array_type<T>::value
 
concept  sbepp::type
 Concept for sbepp::is_type<T>::value
 
concept  sbepp::enumeration
 Concept for sbepp::is_enum<T>::value
 
concept  sbepp::set
 Concept for sbepp::is_set<T>::value
 
concept  sbepp::composite
 Concept for sbepp::is_composite<T>::value
 
concept  sbepp::message
 Concept for sbepp::is_message<T>::value
 
concept  sbepp::flat_group
 Concept for sbepp::is_flat_group<T>::value
 
concept  sbepp::nested_group
 Concept for sbepp::is_nested_group<T>::value
 
concept  sbepp::group
 Concept for sbepp::is_group<T>::value
 
concept  sbepp::data
 Concept for sbepp::is_data<T>::value
 

Macros

#define SBEPP_HAS_THREE_WAY_COMPARISON   0
 1 if compiler supports three-way comparison, 0 otherwise
 
#define SBEPP_HAS_ENDIAN   0
 1 if compiler supports concepts, 0 otherwise
 
#define SBEPP_HAS_BITCAST   0
 1 if compiler supports std::bitcast, 0 otherwise
 
#define SBEPP_HAS_BYTESWAP   0
 1 if compiler supports std::byteswap, 0 otherwise
 
#define SBEPP_HAS_CONSTEXPR_ALGORITHMS   0
 1 if compiler supports constexpr std algorithms, 0 otherwise
 
#define SBEPP_HAS_CONSTEXPR_ACCESSORS   0
 1 if constexpr accessors are supported, 0 otherwise
 
#define SBEPP_HAS_RANGES   0
 1 if compiler supports ranges, 0 otherwise
 
#define SBEPP_HAS_IS_CONSTANT_EVALUATED   0
 1 if compiler supports std::is_constant_evaluated(), 0 otherwise
 
#define SBEPP_DISABLE_ASSERTS
 When defined, unconditionally disables assertions and size checks.
 
#define SBEPP_ASSERT_HANDLER
 When defined, uses client-defined sbepp::assertion_failed as an assertion handler. Whether assertions are enabled is controlled by NDEBUG
 
#define SBEPP_ENABLE_ASSERTS_WITH_HANDLER
 When defined, unconditionally enables assertions. Requires sbepp::assertion_failed to be defined by the client.
 
#define SBEPP_BYTE_ORDER
 Must be defined to either little or big when native endianness cannot be detected automatically.
 

Typedefs

using sbepp::length_t = std::uint64_t
 Represents type_traits::length() value type.
 
using sbepp::offset_t = std::uint64_t
 Represents offset trait value type, e.g. type_traits::offset()
 
using sbepp::version_t = std::uint64_t
 Represents version trait value type, e.g. type_traits::since_version()
 
using sbepp::schema_id_t = std::uint32_t
 Represents schema_traits::id() value type.
 
using sbepp::message_id_t = std::uint32_t
 Represents message_traits::id() value type.
 
using sbepp::block_length_t = std::uint64_t
 Represents block_length trait value type, e.g. message_traits::block_length()
 
using sbepp::member_id_t = std::uint16_t
 Represents id trait value type, e.g. field_traits::id()
 
using sbepp::choice_index_t = std::uint8_t
 Represents set_choice_traits::index() value type.
 
template<typename View >
using sbepp::byte_type_t = typename byte_type<View>::type
 Shortcut for byte_type<T>::type
 
template<typename ValueType >
using sbepp::traits_tag_t = typename traits_tag<ValueType>::type
 Shorthand for sbepp::traits_tag<T>::type
 
template<typename T >
using sbepp::is_array_type = typename detail::is_array_type_impl<T>::type
 Checks is T is an array type.
 
template<typename T >
using sbepp::is_required_type = detail::is_base_of_tmp<detail::required_base, T>
 Checks if T is a non-array required type.
 
template<typename T >
using sbepp::is_optional_type = detail::is_base_of_tmp<detail::optional_base, T>
 Checks if T is a non-array optional type.
 
template<typename T >
using sbepp::is_non_array_type
 Checks if T is a non-array type.
 
template<typename T >
using sbepp::is_type
 Checks if T is a type of any kind.
 
template<typename T >
using sbepp::is_set = detail::is_base_of_tmp<detail::bitset_base, T>
 Checks if T is a set.
 
template<typename T >
using sbepp::is_composite = detail::is_base_of_tmp<detail::composite_base, T>
 Checks if T is a composite.
 
template<typename T >
using sbepp::is_message = detail::is_base_of_tmp<detail::message_base, T>
 Checks if T is a message.
 
template<typename T >
using sbepp::is_flat_group = detail::is_base_of_tmp<detail::flat_group_base, T>
 Checks if T is a flat group.
 
template<typename T >
using sbepp::is_nested_group = detail::is_base_of_tmp<detail::nested_group_base, T>
 Checks if T is a nested group.
 
template<typename T >
using sbepp::is_group
 Checks if T is a group of any kind.
 
template<typename T >
using sbepp::is_group_entry = detail::is_base_of_tmp<detail::entry_base, T>
 Checks if T is a group entry.
 
template<typename T >
using sbepp::is_data = typename detail::is_data_impl<T>::type
 Checks if T is a data.
 

Enumerations

enum class  sbepp::field_presence { sbepp::required , sbepp::optional , sbepp::constant }
 Represents presence trait value type, e.g. type_traits::presence() More...
 
enum class  sbepp::endian { sbepp::little , sbepp::big , sbepp::native }
 Represents schema_traits::byte_order() value type. When SBEPP_HAS_ENDIAN is 1, it's just an alias to std::endian. Requires SBEPP_BYTE_ORDER to be defined if endianness is not detected automatically. More...
 
enum class  sbepp::eos_null { sbepp::none , sbepp::single , sbepp::all }
 Represents number of null bytes that can be added after the end-of-string by detail::static_array_ref::assign_string() More...
 

Functions

void sbepp::assertion_failed (char const *expr, char const *function, char const *file, long line)
 When SBEPP_ASSERT_HANDLER or SBEPP_ENABLE_ASSERTS_WITH_HANDLER is defined, this function is called for failed assertions. Must be defined by the client.
 
template<typename T >
constexpr std::size_t sbepp::size_bytes (T v) noexcept
 Returns the size of the underlying data represented by message/group/entry/data/composite view, including headers.
 
template<typename T , typename Byte >
constexpr std::size_t sbepp::size_bytes (T v, cursor< Byte > c) noexcept
 Similar to sbepp::size_bytes but has constant complexity because it expects c to be set at the end of v. Useful to read the whole message and then get its size in constant time. Not applicable to composites.
 
template<typename T >
constexpr auto sbepp::get_header (T v) noexcept -> decltype(v(detail::get_header_tag{}))
 Returns the header of a message/group.
 
template<typename T >
constexpr auto sbepp::addressof (T v) noexcept -> decltype(v(detail::addressof_tag{}))
 Returns pointer to the underlying data referenced by a view.
 
template<typename Byte >
constexpr detail::init_cursor_wrapper< Byte > sbepp::cursor_ops::init (cursor< Byte > &c) noexcept
 Returns a wrapper which will initialize the cursor when it's used and advance after the usage.
 
template<typename Byte >
constexpr detail::dont_move_cursor_wrapper< Byte > sbepp::cursor_ops::dont_move (cursor< Byte > &c) noexcept
 Returns a wrapper which doesn't advance the cursor when it's used.
 
template<typename Byte >
constexpr detail::init_dont_move_cursor_wrapper< Byte > sbepp::cursor_ops::init_dont_move (cursor< Byte > &c) noexcept
 Returns a wrapper which initializes the cursor but doesn't move it. Behaves like a combination of init() and dont_move().
 
template<typename Byte >
constexpr detail::skip_cursor_wrapper< Byte > sbepp::cursor_ops::skip (cursor< Byte > &c) noexcept
 Returns a wrapper which moves the cursor to the end of field/group/data without returning the accessed value.
 
template<typename Enum >
constexpr std::underlying_type< Enum >::type sbepp::to_underlying (Enum e) noexcept
 Converts an enumeration to its underlying type. Equivalent to C++23 std::to_underlying()
 
template<typename View >
constexpr cursor< byte_type_t< View > > sbepp::init_cursor (View view) noexcept
 Initializes cursor from a message/group view with the same byte type.
 
template<typename View >
constexpr cursor< typename std::add_const< byte_type_t< View > >::type > sbepp::init_const_cursor (View view) noexcept
 Initializes cursor from a message/group view with const byte type.
 
template<typename Message >
constexpr auto sbepp::fill_message_header (Message m) noexcept -> decltype(m(detail::fill_message_header_tag{}))
 Fill message header.
 
template<typename Group , typename Size >
constexpr auto sbepp::fill_group_header (Group g, Size num_in_group) noexcept -> decltype(g(detail::fill_group_header_tag{}, num_in_group))
 Fill group header.
 
template<template< typename > class View, typename Byte >
constexpr View< Byte > sbepp::make_view (Byte *ptr, const std::size_t size) noexcept
 Construct view from memory buffer.
 
template<template< typename > class View, typename Byte >
constexpr View< typename std::add_const< Byte >::type > sbepp::make_const_view (Byte *ptr, const std::size_t size) noexcept
 Construct read-only view from memory buffer.
 
template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit (View view, Cursor &c, Visitor &&visitor={})
 Visit a view using given cursor.
 
template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit (View view, Visitor &&visitor={})
 Visits a view.
 
template<typename Visitor , typename Set >
constexpr Visitor && sbepp::visit (Set s, Visitor &&visitor={})
 Visits set choices.
 
template<typename Visitor , typename Enum >
constexpr Visitor && sbepp::visit (Enum e, Visitor &&visitor={})
 Visits enum value.
 
template<typename Visitor , typename View , typename Cursor , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit_children (View view, Cursor &c, Visitor &&visitor={})
 Visit view's children using provided cursor.
 
template<typename Visitor , typename View , typename = detail::enable_if_t<detail::is_visitable_view<View>::value>>
constexpr Visitor && sbepp::visit_children (View view, Visitor &&visitor={})
 Visit view's children.
 
template<typename E , typename = detail::enable_if_t<is_enum<E>::value>>
constexpr const char * sbepp::enum_to_string (const E e) noexcept
 Converts enum to string.
 
template<typename Set , typename Visitor >
constexpr auto sbepp::visit_set (const Set s, Visitor &&visitor) noexcept -> decltype(s(detail::visit_set_tag{}, std::forward< Visitor >(visitor)))
 Visits set choices in order of their declaration.
 
template<typename View >
constexpr size_bytes_checked_result sbepp::size_bytes_checked (View view, std::size_t size) noexcept
 Calculate view size with additional safety checks.
 

Variables

constexpr default_init_t sbepp::default_init {}
 helper to pass default_init_t to dynamic_array_ref::resize().
 
constexpr nullopt_t sbepp::nullopt {0}
 Helper constant used to initialize optional types with null value.
 
template<typename T >
constexpr auto sbepp::is_array_type_v = is_array_type<T>::value
 Shorthand for sbepp::is_array_type<T>::value
 
template<typename T >
constexpr auto sbepp::is_required_type_v = is_required_type<T>::value
 Shorthand for sbepp::is_required_type<T>::value
 
template<typename T >
constexpr auto sbepp::is_optional_type_v = is_optional_type<T>::value
 Shorthand for sbepp::is_optional_type<T>::value
 
template<typename T >
constexpr auto sbepp::is_non_array_type_v = is_non_array_type<T>::value
 Shorthand for sbepp::is_non_array_type<T>::value
 
template<typename T >
constexpr auto sbepp::is_type_v = is_type<T>::value
 Shorthand for sbepp::is_type<T>::value
 
template<typename T >
constexpr auto sbepp::is_enum_v = is_enum<T>::value
 Shorthand for sbepp::is_enum<T>::value
 
template<typename T >
constexpr auto sbepp::is_set_v = is_set<T>::value
 Shorthand for sbepp::is_set<T>::value
 
template<typename T >
constexpr auto sbepp::is_composite_v = is_composite<T>::value
 Shorthand for sbepp::is_composite<T>::value
 
template<typename T >
constexpr auto sbepp::is_message_v = is_message<T>::value
 Shorthand for sbepp::is_message<T>::value
 
template<typename T >
constexpr auto sbepp::is_flat_group_v = is_flat_group<T>::value
 Shorthand for sbepp::is_flat_group<T>::value
 
template<typename T >
constexpr auto sbepp::is_nested_group_v = is_nested_group<T>::value
 Shorthand for sbepp::is_nested_group<T>::value
 
template<typename T >
constexpr auto sbepp::is_group_v = is_group<T>::value
 Shorthand for sbepp::is_group<T>::value
 
template<typename T >
constexpr auto sbepp::is_data_v = is_data<T>::value
 Shorthand for sbepp::is_data<T>::value
 

Detailed Description

Contains various utilities and implementation details which are required for generated schema headers.