iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::bb::StaticString< N > Class Template Reference

#include <static_string.hpp>

Classes

class  ConstAccessorCodeUnits
 This class provides the interface for accessing individual code units of the string. More...
 
class  UncheckedAccessor
 
class  UncheckedAccessorCodeUnits
 
class  UncheckedConstAccessor
 

Public Types

using ValueType = char
 
using CodeUnitValueType = char
 
using CodePointValueType = char32_t
 
using SizeType = size_t
 
using DifferenceType = ptrdiff_t
 
using Reference = char &
 
using ConstReference = char const &
 
using Pointer = char *
 
using ConstPointer = char const *
 
using Iterator = Pointer
 
using ConstIterator = ConstPointer
 
using OptionalReference = bb::Optional< std::reference_wrapper< char > >
 
using OptionalConstReference = bb::Optional< std::reference_wrapper< char const > >
 
using OptionalCodeUnitReference = bb::Optional< std::reference_wrapper< CodeUnitValueType > >
 
using OptionalConstCodeUnitReference = bb::Optional< std::reference_wrapper< CodeUnitValueType const > >
 

Public Member Functions

constexpr StaticString () noexcept=default
 
constexpr StaticString (StaticString const &) noexcept=default
 
constexpr StaticString (StaticString &&) noexcept=default
 
template<uint64_t M, std::enable_if_t<(N > M), bool > = true>
constexpr StaticString (StaticString< M > const &rhs)
 
IOX2_CONSTEXPR_DTOR ~StaticString ()=default
 
constexpr auto operator= (StaticString const &) noexcept -> StaticString &=default
 
constexpr auto operator= (StaticString &&) noexcept -> StaticString &=default
 
template<uint64_t M, std::enable_if_t<(N > M), bool > = true>
constexpr auto operator= (StaticString< M > const &rhs) noexcept -> StaticString &
 
constexpr auto try_push_back (CodeUnitValueType character) noexcept -> bool
 
constexpr auto try_pop_back () noexcept -> bool
 
constexpr auto try_append (SizeType count, CodeUnitValueType character) noexcept -> bool
 
constexpr auto try_append_utf8_null_terminated_unchecked (char const *utf8_str) -> bool
 
constexpr auto size () const noexcept -> SizeType
 
constexpr auto empty () const -> bool
 
auto unchecked_code_units () -> UncheckedAccessorCodeUnits
 Unchecked mutable access to the string contents on a per-code-unit basis.
 
auto code_units () const -> ConstAccessorCodeUnits
 Immutable access to the string contents on a per-code-unit basis.
 
auto unchecked_access () -> UncheckedAccessor
 Unchecked mutable access to the string contents.
 
auto unchecked_access () const -> UncheckedConstAccessor
 Unchecked immutable access to the string contents.
 
constexpr auto static_memory_layout_metrics () noexcept
 

Static Public Member Functions

template<uint64_t M, std::enable_if_t<(N >=(M - 1)), bool > = true>
static auto from_utf8 (char const (&utf8_str)[M]) noexcept -> bb::Optional< StaticString >
 
static auto from_utf8_null_terminated_unchecked (char const *utf8_str) -> bb::Optional< StaticString >
 
template<uint64_t M, std::enable_if_t<(N >=(M - 1)), bool > = true>
static auto from_utf8_unchecked (char const (&utf8_str)[M]) noexcept -> StaticString
 
static auto from_utf8_null_terminated_unchecked_truncated (char const *utf8_str, SizeType count) -> StaticString
 
static constexpr auto capacity () noexcept -> SizeType
 

Friends

template<uint64_t >
class StaticString
 
auto operator== (StaticString const &lhs, StaticString const &rhs) -> bool
 
auto operator!= (StaticString const &lhs, StaticString const &rhs) -> bool
 
auto operator< (StaticString const &lhs, StaticString const &rhs) -> bool
 
auto operator<= (StaticString const &lhs, StaticString const &rhs) -> bool
 
auto operator> (StaticString const &lhs, StaticString const &rhs) -> bool
 
auto operator>= (StaticString const &lhs, StaticString const &rhs) -> bool
 

Detailed Description

template<uint64_t N>
class iox2::bb::StaticString< N >

A UTF-8 string with fixed static capacity and contiguous inplace storage. The string class uses Unicode (ISO/IEC 10646) terminology throughout its interface. In particular:

  • A code point is the numerical index assigned to a character in the Unicode standard.
  • A code unit is the basic component of a character encoding system. For UTF-8, the code unit has a size of 8-bits For example, the code point U+0041 represents the letter 'A' and can be encoded in a single 8-bit code unit in UTF-8. The code point U+1F4A9 requires four 8-bit code units in the UTF-8 encoding.
Attention
The NUL code point (U+0000) is not allowed anywhere in the string.
Note
Currently only Unicode code points less than 128 (U+0080) are supported. This restricts the valid contents of a string to those UTF8 strings that are also valid 7-bit ASCII strings. Full Unicode support will get added later.
Template Parameters
NMaximum number of UTF-8 code units that the string can store, excluding the terminating NUL character.

Definition at line 80 of file static_string.hpp.

Member Typedef Documentation

◆ CodePointValueType

template<uint64_t N>
using iox2::bb::StaticString< N >::CodePointValueType = char32_t

Definition at line 84 of file static_string.hpp.

◆ CodeUnitValueType

template<uint64_t N>
using iox2::bb::StaticString< N >::CodeUnitValueType = char

Definition at line 83 of file static_string.hpp.

◆ ConstIterator

template<uint64_t N>
using iox2::bb::StaticString< N >::ConstIterator = ConstPointer

Definition at line 92 of file static_string.hpp.

◆ ConstPointer

template<uint64_t N>
using iox2::bb::StaticString< N >::ConstPointer = char const*

Definition at line 90 of file static_string.hpp.

◆ ConstReference

template<uint64_t N>
using iox2::bb::StaticString< N >::ConstReference = char const&

Definition at line 88 of file static_string.hpp.

◆ DifferenceType

template<uint64_t N>
using iox2::bb::StaticString< N >::DifferenceType = ptrdiff_t

Definition at line 86 of file static_string.hpp.

◆ Iterator

template<uint64_t N>
using iox2::bb::StaticString< N >::Iterator = Pointer

Definition at line 91 of file static_string.hpp.

◆ OptionalCodeUnitReference

template<uint64_t N>
using iox2::bb::StaticString< N >::OptionalCodeUnitReference = bb::Optional<std::reference_wrapper<CodeUnitValueType> >

Definition at line 95 of file static_string.hpp.

◆ OptionalConstCodeUnitReference

template<uint64_t N>
using iox2::bb::StaticString< N >::OptionalConstCodeUnitReference = bb::Optional<std::reference_wrapper<CodeUnitValueType const> >

Definition at line 96 of file static_string.hpp.

◆ OptionalConstReference

template<uint64_t N>
using iox2::bb::StaticString< N >::OptionalConstReference = bb::Optional<std::reference_wrapper<char const> >

Definition at line 94 of file static_string.hpp.

◆ OptionalReference

template<uint64_t N>
using iox2::bb::StaticString< N >::OptionalReference = bb::Optional<std::reference_wrapper<char> >

Definition at line 93 of file static_string.hpp.

◆ Pointer

template<uint64_t N>
using iox2::bb::StaticString< N >::Pointer = char*

Definition at line 89 of file static_string.hpp.

◆ Reference

template<uint64_t N>
using iox2::bb::StaticString< N >::Reference = char&

Definition at line 87 of file static_string.hpp.

◆ SizeType

template<uint64_t N>
using iox2::bb::StaticString< N >::SizeType = size_t

Definition at line 85 of file static_string.hpp.

◆ ValueType

template<uint64_t N>
using iox2::bb::StaticString< N >::ValueType = char

Definition at line 82 of file static_string.hpp.

Constructor & Destructor Documentation

◆ StaticString() [1/4]

template<uint64_t N>
constexpr iox2::bb::StaticString< N >::StaticString ( )
constexprdefaultnoexcept

◆ StaticString() [2/4]

template<uint64_t N>
constexpr iox2::bb::StaticString< N >::StaticString ( StaticString< N > const &  )
constexprdefaultnoexcept

◆ StaticString() [3/4]

template<uint64_t N>
constexpr iox2::bb::StaticString< N >::StaticString ( StaticString< N > &&  )
constexprdefaultnoexcept

◆ StaticString() [4/4]

template<uint64_t N>
template<uint64_t M, std::enable_if_t<(N > M), bool > = true>
constexpr iox2::bb::StaticString< N >::StaticString ( StaticString< M > const &  rhs)
inlineconstexpr

Definition at line 421 of file static_string.hpp.

◆ ~StaticString()

template<uint64_t N>
IOX2_CONSTEXPR_DTOR iox2::bb::StaticString< N >::~StaticString ( )
default

Member Function Documentation

◆ capacity()

template<uint64_t N>
static constexpr auto iox2::bb::StaticString< N >::capacity ( ) -> SizeType
inlinestaticconstexprnoexcept

Definition at line 583 of file static_string.hpp.

◆ code_units()

template<uint64_t N>
auto iox2::bb::StaticString< N >::code_units ( ) const -> ConstAccessorCodeUnits
inline

Immutable access to the string contents on a per-code-unit basis.

Definition at line 601 of file static_string.hpp.

◆ empty()

◆ from_utf8()

template<uint64_t N>
template<uint64_t M, std::enable_if_t<(N >=(M - 1)), bool > = true>
static auto iox2::bb::StaticString< N >::from_utf8 ( char const (&)  utf8_str[M]) -> bb::Optional<StaticString>
inlinestaticnoexcept

Constructs a StaticString from a C-string literal.

Returns
Nullopt if the input string does not represent a valid UTF-8 encoding. Otherwise a StaticString that contains a copy of the input string.

Definition at line 452 of file static_string.hpp.

References iox2::bb::NULLOPT, and iox2::bb::StaticString< N >::try_push_back().

◆ from_utf8_null_terminated_unchecked()

template<uint64_t N>
static auto iox2::bb::StaticString< N >::from_utf8_null_terminated_unchecked ( char const *  utf8_str) -> bb::Optional<StaticString>
inlinestatic

Constructs a StaticString from a null terminated C-style string. This unchecked function allows for uncontrolled memory access. Users of this must ensure that the input string is properly null terminated.

Returns
Nullopt if the input string does not represent a valid UTF-8 encoding. Otherwise a StaticString that contains a copy of the input string.

Definition at line 471 of file static_string.hpp.

References iox2::bb::NULLOPT, and iox2::bb::StaticString< N >::try_push_back().

Referenced by iox2::internal::get_type_name_impl().

◆ from_utf8_null_terminated_unchecked_truncated()

template<uint64_t N>
static auto iox2::bb::StaticString< N >::from_utf8_null_terminated_unchecked_truncated ( char const *  utf8_str,
SizeType  count 
) -> StaticString
inlinestatic

Constructs a StaticString from up to count characters of a C-style string. If the capacity of the StaticString would be exceeded, the input string is truncated. This unchecked function allows for uncontrolled memory access. User of this must ensure that the input string is null-terminated if count exceeds the string length and the truncated string represents a valid UTF-8 encoding.

Definition at line 504 of file static_string.hpp.

◆ from_utf8_unchecked()

template<uint64_t N>
template<uint64_t M, std::enable_if_t<(N >=(M - 1)), bool > = true>
static auto iox2::bb::StaticString< N >::from_utf8_unchecked ( char const (&)  utf8_str[M]) -> StaticString
inlinestaticnoexcept

Constructs a StaticString from a C-string literal. Users must ensure that the input string represents a valid UTF-8 encoding.

Definition at line 487 of file static_string.hpp.

Referenced by iox2::bb::detail::is_valid_path_entry(), and iox2::bb::detail::is_valid_path_to_directory().

◆ operator=() [1/3]

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::operator= ( StaticString< N > &&  ) -> StaticString &=default
constexprdefaultnoexcept

◆ operator=() [2/3]

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::operator= ( StaticString< N > const &  ) -> StaticString &=default
constexprdefaultnoexcept

◆ operator=() [3/3]

template<uint64_t N>
template<uint64_t M, std::enable_if_t<(N > M), bool > = true>
constexpr auto iox2::bb::StaticString< N >::operator= ( StaticString< M > const &  rhs) -> StaticString&
inlineconstexprnoexcept

Definition at line 436 of file static_string.hpp.

◆ size()

◆ static_memory_layout_metrics()

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::static_memory_layout_metrics ( )
inlineconstexprnoexcept

Obtains metrics about the internal memory layout of the vector. This function is intended for internal use only.

Definition at line 645 of file static_string.hpp.

◆ try_append()

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::try_append ( SizeType  count,
CodeUnitValueType  character 
) -> bool
inlineconstexprnoexcept

Attempt to append count instances of character to the back of the string.

Returns
true on success. false if the action would exceed the string's capacity or put the string content into a state that is not a valid UTF-8 encoded string.

Definition at line 551 of file static_string.hpp.

◆ try_append_utf8_null_terminated_unchecked()

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::try_append_utf8_null_terminated_unchecked ( char const *  utf8_str) -> bool
inlineconstexpr

Appends a null terminated C-style string. This unchecked function allows for uncontrolled memory access. Users of this must ensure that the input string is properly null terminated.

Returns
true on success. false if the input string does not represent a valid UTF-8 encoding.

Definition at line 569 of file static_string.hpp.

References iox2::bb::StaticString< N >::size(), and iox2::bb::StaticString< N >::try_push_back().

◆ try_pop_back()

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::try_pop_back ( ) -> bool
inlineconstexprnoexcept

Attempt to pop a single code unit from the back of the string.

Returns
true on success. false if the string is already empty or if the action would put the string content into a state that is not a valid UTF-8 encoded string.

Definition at line 537 of file static_string.hpp.

◆ try_push_back()

template<uint64_t N>
constexpr auto iox2::bb::StaticString< N >::try_push_back ( CodeUnitValueType  character) -> bool
inlineconstexprnoexcept

Attempt to append a single code unit to the back of the string.

Returns
true on success. false if the action would exceed the string's capacity or put the string content into a state that is not a valid UTF-8 encoded string.

Definition at line 520 of file static_string.hpp.

Referenced by iox2::bb::StaticString< N >::from_utf8(), iox2::bb::StaticString< N >::from_utf8_null_terminated_unchecked(), and iox2::bb::StaticString< N >::try_append_utf8_null_terminated_unchecked().

◆ unchecked_access() [1/2]

template<uint64_t N>
auto iox2::bb::StaticString< N >::unchecked_access ( ) -> UncheckedAccessor
inline

Unchecked mutable access to the string contents.

Definition at line 606 of file static_string.hpp.

◆ unchecked_access() [2/2]

template<uint64_t N>
auto iox2::bb::StaticString< N >::unchecked_access ( ) const -> UncheckedConstAccessor
inline

Unchecked immutable access to the string contents.

Definition at line 611 of file static_string.hpp.

◆ unchecked_code_units()

template<uint64_t N>
auto iox2::bb::StaticString< N >::unchecked_code_units ( ) -> UncheckedAccessorCodeUnits
inline

Unchecked mutable access to the string contents on a per-code-unit basis.

Definition at line 596 of file static_string.hpp.

Friends And Related Symbol Documentation

◆ operator!=

template<uint64_t N>
auto operator!= ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 623 of file static_string.hpp.

◆ operator<

template<uint64_t N>
auto operator< ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 627 of file static_string.hpp.

◆ operator<=

template<uint64_t N>
auto operator<= ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 631 of file static_string.hpp.

◆ operator==

template<uint64_t N>
auto operator== ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 616 of file static_string.hpp.

◆ operator>

template<uint64_t N>
auto operator> ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 635 of file static_string.hpp.

◆ operator>=

template<uint64_t N>
auto operator>= ( StaticString< N > const &  lhs,
StaticString< N > const &  rhs 
) -> bool
friend

Definition at line 639 of file static_string.hpp.

◆ StaticString

template<uint64_t N>
template<uint64_t >
friend class StaticString
friend

Definition at line 407 of file static_string.hpp.


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