dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
StringParam Struct Referencefinal

A non-owning string parameter: a pointer to characters and their count. More...

#include <StringParam.hpp>

Public Member Functions

constexpr StringParam () noexcept
 Creates an empty string.
template<std::size_t N>
constexpr StringParam (const char(&arr)[N]) noexcept
 Creates a string from a char array (a literal or a buffer): the characters up to the first NUL within the array, or the whole array when it has no NUL.
template<typename P>
requires StringParamPointer<P>
constexpr StringParam (P &&str) noexcept
 Creates a string from a pointer to NUL-terminated characters.
 StringParam (const std::string &str) noexcept
 Creates a string from a std::string, the whole of it.
constexpr StringParam (std::string_view sv) noexcept
 Creates a string from a std::string_view, the whole of it.
template<typename R>
requires StringParamRange<R>
constexpr StringParam (R &&range) noexcept
 Creates a string from a contiguous range of char, the whole of it.
constexpr const char * data () const noexcept
constexpr std::size_t size () const noexcept
constexpr bool empty () const noexcept
constexpr std::string_view view () const noexcept

Detailed Description

A non-owning string parameter: a pointer to characters and their count.

It is a parameter only: it must not be stored, returned or kept after the call it is passed to, because it does not own the characters. A temporary (a std::string, a std::vector<char>) lives until the end of the full expression of the call, which is enough for a parameter.

The name dxfcpp::StringParam is part of the API: it is spelled in the signatures of the functions that take a string, including the virtual functions that users override.

Accepted: a literal, a char array, const char * and char *, std::string, std::string_view, and contiguous ranges of char (std::vector<char>, std::array<char, N>, std::span<const char>, std::span<char>). Not accepted: numbers, bool, std::optional, wide and UTF-8 strings, ranges of other types, and types that only convert to std::string by their own operator.

Rules of the length:

  • A char array (a literal, a buffer) ends at the first NUL within the array, or at the array's end when there is none: char buf[8] = "ab" is "ab", char full[3] = {'a', 'b', 'c'} is "abc" (nothing is read past the array).
  • A std::array<char, N> is a range, not a C array: it keeps its trailing NULs.
  • A null pointer is an empty string.
  • A std::string, a std::string_view and a range keep their whole size, including embedded NULs; the type never truncates. The boundary with the dxFeed Graal SDK reads the characters up to the first NUL.

Encoding: a string that goes to the dxFeed Graal SDK must be valid UTF-8. A byte that cannot start a sequence, a truncated sequence, an overlong form, an encoded surrogate or a value above U+10FFFF make the function throw InvalidArgumentException, for example DXEndpoint::connect(address): invalid UTF-8 at byte 12: 0xC3 0x28: the function and its parameter, the offset of the first invalid byte from 0 and the bytes of the invalid sequence. For a user name, a password or a token, the message has no bytes. The string fields of events are checked when the events are published, not by their setters, and the message names the event type and the field (TimeAndSale::exchangeSaleConditions: invalid UTF-8 at byte 1: 0xFF); symbols are checked when they are added to a subscription (StringSymbol(symbol): ...).

Passing a bare nullptr to a function that has another overload with a smart pointer parameter is ambiguous (for example Schedule::getInstance): write static_cast<const char *>(nullptr).

data() is not guaranteed to be NUL-terminated. There is no implicit conversion to std::string or std::string_view; use view().

Constructor & Destructor Documentation

◆ StringParam() [1/5]

template<std::size_t N>
StringParam::StringParam ( const char(&) arr[N])
inlineconstexprnoexcept

Creates a string from a char array (a literal or a buffer): the characters up to the first NUL within the array, or the whole array when it has no NUL.

Template Parameters
NThe array size
Parameters
arrThe array

◆ StringParam() [2/5]

template<typename P>
requires StringParamPointer<P>
StringParam::StringParam ( P && str)
inlineconstexprnoexcept

Creates a string from a pointer to NUL-terminated characters.

A null pointer is an empty string.

Template Parameters
Pconst char *, char * or std::nullptr_t
Parameters
strThe pointer

◆ StringParam() [3/5]

StringParam::StringParam ( const std::string & str)
inlinenoexcept

Creates a string from a std::string, the whole of it.

Parameters
strThe string

◆ StringParam() [4/5]

StringParam::StringParam ( std::string_view sv)
inlineconstexprnoexcept

Creates a string from a std::string_view, the whole of it.

Parameters
svThe view

◆ StringParam() [5/5]

template<typename R>
requires StringParamRange<R>
StringParam::StringParam ( R && range)
inlineconstexprnoexcept

Creates a string from a contiguous range of char, the whole of it.

Template Parameters
RThe range type
Parameters
rangeThe range

Member Function Documentation

◆ data()

const char * StringParam::data ( ) const
inlineconstexprnoexcept
Returns
The characters; never null, not guaranteed to be NUL-terminated.

◆ empty()

bool StringParam::empty ( ) const
inlineconstexprnoexcept
Returns
true if there are no characters.

◆ size()

std::size_t StringParam::size ( ) const
inlineconstexprnoexcept
Returns
The number of characters.

◆ view()

std::string_view StringParam::view ( ) const
inlineconstexprnoexcept
Returns
A view of the characters.