template <typename ValueType>
value class
A TOML value.
Template parameters | |
---|---|
ValueType | The value's native TOML data type. Can be one of: |
Base classes
- class node
- A TOML node.
Public types
-
using value_arg =
/* ... */
- A type alias for 'value arguments'.
- using value_type = ValueType
- The value's underlying data type.
Constructors, destructors, conversion operators
-
template <typename... Args>value(Args && ... args) explicit noexcept(…)
- Constructs a toml value.
- value(const value& other) noexcept
- Copy constructor.
-
value(const value& other,
value_
flags flags) noexcept - Copy constructor with flags override.
- value(value&& other) noexcept
- Move constructor.
-
value(value&& other,
value_
flags flags) noexcept - Move constructor with flags override.
Public functions
Equality and Comparison
-
template <typename T>auto operator!=(const value& lhs, const value<T>& rhs) → bool noexcept
- Inequality operator.
-
auto operator<(const value& lhs,
value_
arg rhs) → bool noexcept - Value less-than operator.
-
auto operator<(value_
arg lhs, const value& rhs) → bool noexcept - Value less-than operator.
-
template <typename T>auto operator<(const value& lhs, const value<T>& rhs) → bool noexcept
- Less-than operator.
-
auto operator<=(const value& lhs,
value_
arg rhs) → bool noexcept - Value less-than-or-equal-to operator.
-
auto operator<=(value_
arg lhs, const value& rhs) → bool noexcept - Value less-than-or-equal-to operator.
-
template <typename T>auto operator<=(const value& lhs, const value<T>& rhs) → bool noexcept
- Less-than-or-equal-to operator.
-
auto operator==(const value& lhs,
value_
arg rhs) → bool noexcept - Value equality operator.
-
template <typename T>auto operator==(const value& lhs, const value<T>& rhs) → bool noexcept
- Equality operator.
-
auto operator>(const value& lhs,
value_
arg rhs) → bool noexcept - Value greater-than operator.
-
auto operator>(value_
arg lhs, const value& rhs) → bool noexcept - Value greater-than operator.
-
template <typename T>auto operator>(const value& lhs, const value<T>& rhs) → bool noexcept
- Greater-than operator.
-
auto operator>=(const value& lhs,
value_
arg rhs) → bool noexcept - Value greater-than-or-equal-to operator.
-
auto operator>=(value_
arg lhs, const value& rhs) → bool noexcept - Value greater-than-or-equal-to operator.
-
template <typename T>auto operator>=(const value& lhs, const value<T>& rhs) → bool noexcept
- Greater-than-or-equal-to operator.
Metadata
-
auto flags() const → value_
flags noexcept - Returns the metadata flags associated with this value.
-
auto flags(value_
flags new_flags) → value& noexcept - Sets the metadata flags associated with this value.
-
auto source() const → const source_
region& noexcept - Returns the source region responsible for generating this node during parsing.
Node views
-
auto at_path(std::
string_view path) → node_ view<node> noexcept - Returns a view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
string_view path) const → node_ view<const node> noexcept - Returns a const view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
wstring_view path) → node_ view<node> - Returns a view of the subnode matching a fully-qualified "TOML path".
-
auto at_path(std::
wstring_view path) const → node_ view<const node> - Returns a const view of the subnode matching a fully-qualified "TOML path".
- operator node_view<const node>() const explicit noexcept
- Creates a node_
view pointing to this node (const overload). - operator node_view<node>() explicit noexcept
- Creates a node_
view pointing to this node.
Type casts
-
template <typename T>auto as() → impl::wrap_node<T>* noexcept
- Gets a pointer to the node as a more specific node type.
-
template <typename T>auto as() const → const impl::wrap_node<T>* noexcept
- Gets a pointer to the node as a more specific node type (const overload).
- auto as_array() → array* final noexcept
- Returns
nullptr
. - auto as_array() const → const array* final noexcept
- Returns
nullptr
. - auto as_boolean() → value<bool>* final noexcept
- Returns a pointer to the value if it is a value<bool>, otherwise
nullptr
. - auto as_boolean() const → const value<bool>* final noexcept
- Returns a const-qualified pointer to the value if it is a value<bool>, otherwise
nullptr
. - auto as_date() → value<date>* final noexcept
- Returns a pointer to the value if it is a value<date>, otherwise
nullptr
. - auto as_date() const → const value<date>* final noexcept
- Returns a const-qualified pointer to the value if it is a value<date>, otherwise
nullptr
. -
auto as_date_time() → value<date_
time>* final noexcept - Returns a pointer to the value if it is a value<date_time>, otherwise
nullptr
. -
auto as_date_time() const → const value<date_
time>* final noexcept - Returns a const-qualified pointer to the value if it is a value<date_time>, otherwise
nullptr
. - auto as_floating_point() → value<double>* final noexcept
- Returns a pointer to the value if it is a value<double>, otherwise
nullptr
. - auto as_floating_point() const → const value<double>* final noexcept
- Returns a const-qualified pointer to the value if it is a value<double>, otherwise
nullptr
. - auto as_integer() → value<int64_t>* final noexcept
- Returns a pointer to the value if it is a value<int64_t>, otherwise
nullptr
. - auto as_integer() const → const value<int64_t>* final noexcept
- Returns a const-qualified pointer to the value if it is a value<int64_t>, otherwise
nullptr
. -
auto as_string() → value<std::
string>* final noexcept - Returns a pointer to the value if it is a value<std::
string>, otherwise nullptr
. -
auto as_string() const → const value<std::
string>* final noexcept - Returns a const-qualified pointer to the value if it is a value<std::
string>, otherwise nullptr
. - auto as_table() → table* final noexcept
- Returns
nullptr
. - auto as_table() const → const table* final noexcept
- Returns
nullptr
. - auto as_time() → value<time>* final noexcept
- Returns a pointer to the value if it is a value<time>, otherwise
nullptr
. - auto as_time() const → const value<time>* final noexcept
- Returns a const-qualified pointer to the value if it is a value<time>, otherwise
nullptr
.
Type checks
-
template <typename T>auto is() const → bool noexcept
- Checks if a node is a specific type.
- auto is_array() const → bool final noexcept
- Returns
false
. - auto is_array_of_tables() const → bool final noexcept
- Returns
false
. - auto is_boolean() const → bool final noexcept
- Returns
true
if the value_type is bool
. - auto is_date() const → bool final noexcept
- Returns
true
if the value_type is toml:: date. - auto is_date_time() const → bool final noexcept
- Returns
true
if the value_type is toml_date_time. - auto is_floating_point() const → bool final noexcept
- Returns
true
if the value_type is double
. -
auto is_homogeneous(node_
type ntype) const → bool final noexcept - Checks if the node contains values/elements of only one type.
-
auto is_homogeneous(node_
type ntype, node*& first_nonmatch) → bool final noexcept - Checks if a node contains values/elements of only one type.
-
auto is_homogeneous(node_
type ntype, const node*& first_nonmatch) const → bool final noexcept - Checks if a node contains values/elements of only one type (const overload).
-
template <typename ElemType = void>auto is_homogeneous() const → bool noexcept
- Checks if the node contains values/elements of only one type.
- auto is_integer() const → bool final noexcept
- Returns
true
if the value_type is int64_t. - auto is_number() const → bool final noexcept
- Returns
true
if the value_type is int64_t or double
. - auto is_string() const → bool final noexcept
- Returns
true
if the value_type is std:: string. - auto is_table() const → bool final noexcept
- Returns
false
. - auto is_time() const → bool final noexcept
- Returns
true
if the value_type is toml:: time. - auto is_value() const → bool final noexcept
- Returns
true
. -
auto type() const → node_
type final noexcept - Returns the value's node type identifier.
Value retrieval
-
auto get() & → value_
type& noexcept - Returns a reference to the underlying value.
-
auto get() && → value_
type&& noexcept - Returns a reference to the underlying value (rvalue overload).
-
auto get() const & → const value_
type& noexcept - Returns a reference to the underlying value (const overload).
-
auto get() const && → const value_
type&& noexcept - Returns a reference to the underlying value (const rvalue overload).
- operator const value_type&() const & explicit noexcept
- Returns a reference to the underlying value (const overload).
- operator const value_type&&() && explicit noexcept
- Returns a reference to the underlying value (const rvalue overload).
- operator value_type&() & explicit noexcept
- Returns a reference to the underlying value.
- operator value_type&&() && explicit noexcept
- Returns a reference to the underlying value (rvalue overload).
-
auto operator*() & → value_
type& noexcept - Returns a reference to the underlying value.
-
auto operator*() && → value_
type&& noexcept - Returns a reference to the underlying value (rvalue overload).
-
auto operator*() const & → const value_
type& noexcept - Returns a reference to the underlying value (const overload).
-
auto operator*() const && → const value_
type&& noexcept - Returns a reference to the underlying value (const rvalue overload).
-
auto operator->() → value_
type* noexcept - Returns a pointer to the underlying value.
-
auto operator->() const → const value_
type* noexcept - Returns a pointer to the underlying value (const overload).
-
template <typename T>auto ref() & → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data.
-
template <typename T>auto ref() && → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (rvalue overload).
-
template <typename T>auto ref() const & → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (const lvalue overload).
-
template <typename T>auto ref() const && → decltype(auto) noexcept
- Gets a raw reference to a node's underlying data (const rvalue overload).
-
template <typename T>auto value() const → optional<T> noexcept(…)
- Gets the value contained by this node.
-
template <typename T>auto value_exact() const → optional<T> noexcept(…)
- Gets the value contained by this node.
-
template <typename T>auto value_or(T&& default_value) const → auto noexcept(…)
- Gets the raw value contained by this node, or a default.
Visitation
-
template <typename Func>auto visit(Func&& visitor) & → decltype(auto) noexcept(…)
- Invokes a visitor on the node based on the node's concrete type.
-
template <typename Func>auto visit(Func&& visitor) && → decltype(auto) noexcept(…)
- Invokes a visitor on the node based on the node's concrete type (rvalue overload).
-
template <typename Func>auto visit(Func&& visitor) const & → decltype(auto) noexcept(…)
- Invokes a visitor on the node based on the node's concrete type (const lvalue overload).
-
template <typename Func>auto visit(Func&& visitor) const && → decltype(auto) noexcept(…)
- Invokes a visitor on the node based on the node's concrete type (const rvalue overload).
Friends
-
auto operator<<(std::
ostream& lhs, const value& rhs) → std:: ostream& - Prints the value out to a stream as formatted TOML.
Typedef documentation
template <typename ValueType>
using toml::value::value_arg = /* ... */
A type alias for 'value arguments'.
This differs according to the value's type argument:
- ints, floats, booleans:
value_type
- strings:
string_view
- everything else:
const value_type&
Function documentation
template <typename ValueType>
template <typename... Args>
toml::value::value(Args && ... args) explicit noexcept(…)
template <typename... Args>
Constructs a toml value.
Template parameters | |
---|---|
Args | Constructor argument types. |
Parameters | |
args | Arguments to forward to the internal value's constructor. |
template <typename ValueType>
template <typename T>
bool toml::value::operator!=(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Inequality operator.
Parameters | |
---|---|
lhs | The LHS value. |
rhs | The RHS value. |
Returns | True if the values were not of the same type, or did not contain the same value. |
template <typename ValueType>
template <typename T>
bool toml::value::operator<(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Less-than operator.
Parameters | |
---|---|
lhs | The LHS toml:: |
rhs | The RHS toml:: |
Returns | Same value types:
lhs.get() < rhs.get() Different value types:
lhs.type() < rhs.type() |
template <typename ValueType>
template <typename T>
bool toml::value::operator<=(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Less-than-or-equal-to operator.
Parameters | |
---|---|
lhs | The LHS toml:: |
rhs | The RHS toml:: |
Returns | Same value types:
lhs.get() <= rhs.get() Different value types:
lhs.type() <= rhs.type() |
template <typename ValueType>
template <typename T>
bool toml::value::operator==(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Equality operator.
Parameters | |
---|---|
lhs | The LHS value. |
rhs | The RHS value. |
Returns | True if the values were of the same type and contained the same value. |
template <typename ValueType>
template <typename T>
bool toml::value::operator>(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Greater-than operator.
Parameters | |
---|---|
lhs | The LHS toml:: |
rhs | The RHS toml:: |
Returns | Same value types:
lhs.get() > rhs.get() Different value types:
lhs.type() > rhs.type() |
template <typename ValueType>
template <typename T>
bool toml::value::operator>=(const value& lhs,
const value<T>& rhs) noexcept
template <typename T>
Greater-than-or-equal-to operator.
Parameters | |
---|---|
lhs | The LHS toml:: |
rhs | The RHS toml:: |
Returns | Same value types:
lhs.get() >= rhs.get() Different value types:
lhs.type() >= rhs.type() |
template <typename ValueType>
value& toml::value::flags(value_ flags new_flags) noexcept
Sets the metadata flags associated with this value.
Returns | A reference to the value object. |
---|
template <typename ValueType>
bool toml::value::is_homogeneous(node_ type ntype) const final noexcept
Checks if the node contains values/elements of only one type.
Parameters | |
---|---|
ntype | A TOML node type. toml:: |
Returns | True if the node was homogeneous. |
auto arr = toml::array{ 1, 2, 3 }; std::cout << "homogenous: "sv << arr.is_homogeneous(toml::node_type::none) << "\n"; std::cout << "all floats: "sv << arr.is_homogeneous(toml::node_type::floating_point) << "\n"; std::cout << "all arrays: "sv << arr.is_homogeneous(toml::node_type::array) << "\n"; std::cout << "all ints: "sv << arr.is_homogeneous(toml::node_type::integer) << "\n";
homogeneous: true all floats: false all arrays: false all ints: true
template <typename ValueType>
bool toml::value::is_homogeneous(node_ type ntype,
node*& first_nonmatch) final noexcept
Checks if a node contains values/elements of only one type.
Parameters | |
---|---|
ntype | A TOML node type. toml:: |
first_nonmatch | Reference to a pointer in which the address of the first non-matching element will be stored if the return value is false. |
Returns | True if the node was homogeneous. |
auto cfg = toml::parse("arr = [ 1, 2, 3, 4.0 ]"); toml::array& arr = *cfg["arr"].as_array(); toml::node* nonmatch{}; if (arr.is_homogeneous(toml::node_type::integer, nonmatch)) std::cout << "array was homogeneous"sv << "\n"; else std::cout << "array was not homogeneous!\n" << "first non-match was a "sv << nonmatch->type() << " at " << nonmatch->source() << "\n";
array was not homogeneous! first non-match was a floating-point at line 1, column 18
template <typename ValueType>
value_ type* toml::value::operator->() noexcept
Returns a pointer to the underlying value.
template <typename ValueType>
const value_ type* toml::value::operator->() const noexcept
Returns a pointer to the underlying value (const overload).
template <typename ValueType>
std:: ostream& operator<<(std:: ostream& lhs,
const value& rhs)
Prints the value out to a stream as formatted TOML.