toml namespace
The root namespace for all toml++ functions and types.
Namespaces
- namespace literals inline
- Convenience literal operators for working with toml++.
Classes
- class array
- A TOML array.
- struct date
- A local date.
- struct date_time
- A date-time.
-
template <typename Char = char>class default_formatter
- A wrapper for printing TOML objects out to a stream as formatted TOML.
-
template <typename T>struct inserter
- Helper class for suppressing move-construction in single-argument array constructors.
-
template <typename Char = char>class json_formatter
- A wrapper for printing TOML objects out to a stream as formatted JSON.
- class node
- A TOML node.
-
template <typename ViewedType>class node_view
- A view of a node.
- class parse_error
- An error generated when parsing fails.
- class parse_result
- The result of a parsing operation.
- struct source_position
- A source document line-and-column pair.
- struct source_region
- A source document region.
- class table
- A TOML table.
- struct time
- A local time-of-day.
- struct time_offset
- A timezone offset.
-
template <typename ValueType>class value
- A TOML value.
Enums
- enum class format_flags: uint8_t { none, quote_dates_and_times = 1, allow_literal_strings = 2, allow_multi_line_strings = 4, allow_value_format_flags = 8 }
- Format flags for modifying how TOML data is printed to streams.
- enum class node_type: uint8_t { none, table, array, string, integer, floating_point, boolean, date, time, date_time }
- TOML node type identifiers.
- enum class value_flags: uint8_t { none, format_as_binary = 1, format_as_octal = 2, format_as_hexadecimal = 3 }
- Metadata associated with TOML values.
Typedefs
- using array_iterator = impl::array_iterator<false>
- A RandomAccessIterator for iterating over elements in a toml::
array. - using const_array_iterator = impl::array_iterator<true>
- A RandomAccessIterator for iterating over const elements in a toml::
array. - using const_table_iterator = impl::table_iterator<true>
- A BidirectionalIterator for iterating over const key-value pairs in a toml::
table. -
template <typename T>using inserted_type_of = typename impl::inserted_type_of_<impl::remove_cvref_t<T>>::type
- Metafunction for determining which node type would be constructed if an object of this type was inserted into a toml::
table or toml:: array. -
template <typename T>using optional = std::
optional<T> - The 'optional' type used throughout the library.
- using source_index = uint16_t
- The integer type used to tally line numbers and columns.
-
using source_path_ptr = std::
shared_ptr<const std:: string> - A pointer to a shared string resource containing a source path.
- using table_iterator = impl::table_iterator<false>
- A BidirectionalIterator for iterating over key-value pairs in a toml::
table.
Functions
-
auto operator""_toml(const char* str,
size_t len) → parse_
result - Parses TOML data from a string literal.
-
auto operator""_toml(const char8_t* str,
size_t len) → parse_
result - Parses TOML data from a UTF-8 string literal.
-
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, node_ type rhs) → std:: basic_ostream<Char>& - Pretty-prints the value of a node_type to a stream.
-
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const date& rhs) → std:: basic_ostream<Char>& - Prints a date out to a stream as
YYYY-MM-DD
(per RFC 3339). -
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const time& rhs) → std:: basic_ostream<Char>& - Prints a time out to a stream as
HH:MM:SS.FFFFFF
(per RFC 3339). -
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const time_ offset& rhs) → std:: basic_ostream<Char>& - Prints a time_
offset out to a stream as +-HH:MM or Z
(per RFC 3339). -
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const date_ time& rhs) → std:: basic_ostream<Char>& - Prints a date_
time out to a stream in RFC 3339 format. -
template <typename T, typename U>auto operator<<(std::
basic_ostream<T>& lhs, default_ formatter<U>& rhs) → std:: basic_ostream<T>& - Prints the bound TOML object out to the stream as formatted TOML.
-
template <typename T, typename U>auto operator<<(std::
basic_ostream<T>& lhs, default_ formatter<U>&& rhs) → std:: basic_ostream<T>& - Prints the bound TOML object out to the stream as formatted TOML (rvalue overload).
-
template <typename T, typename U>auto operator<<(std::
basic_ostream<T>& lhs, json_ formatter<U>& rhs) → std:: basic_ostream<T>& - Prints the bound TOML object out to the stream as JSON.
-
template <typename T, typename U>auto operator<<(std::
basic_ostream<T>& lhs, json_ formatter<U>&& rhs) → std:: basic_ostream<T>& - Prints the bound TOML object out to the stream as JSON (rvalue overload).
-
template <typename Char, typename T>auto operator<<(std::
basic_ostream<Char>& os, const node_ view<T>& nv) → std:: basic_ostream<Char>& - Prints the viewed node out to a stream.
-
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const parse_ error& rhs) → std:: basic_ostream<Char>& - Prints a parse_
error to a stream. -
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const source_ position& rhs) → std:: basic_ostream<Char>& - Prints a source_
position to a stream. -
template <typename Char>auto operator<<(std::
basic_ostream<Char>& lhs, const source_ region& rhs) → std:: basic_ostream<Char>& - Prints a source_
region to a stream. -
auto parse(std::
string_view doc, std:: string_view source_path = {}) → parse_ result - Parses a TOML document from a string view.
-
auto parse(std::
string_view doc, std:: string&& source_path) → parse_ result - Parses a TOML document from a string view.
-
auto parse(std::
string_view doc, std:: wstring_view source_path) → parse_ result - Parses a TOML document from a string view.
-
auto parse(std::
u8string_view doc, std:: string_view source_path = {}) → parse_ result - Parses a TOML document from a char8_t string view.
-
auto parse(std::
u8string_view doc, std:: string&& source_path) → parse_ result - Parses a TOML document from a char8_t string view.
-
auto parse(std::
u8string_view doc, std:: wstring_view source_path) → parse_ result - Parses a TOML document from a char8_t string view.
-
template <typename Char>auto parse(std::
basic_istream<Char>& doc, std:: string_view source_path = {}) → parse_ result - Parses a TOML document from a stream.
-
template <typename Char>auto parse(std::
basic_istream<Char>& doc, std:: string&& source_path) → parse_ result - Parses a TOML document from a stream.
-
template <typename Char>auto parse(std::
basic_istream<Char>& doc, std:: wstring_view source_path) → parse_ result - Parses a TOML document from a stream.
-
auto parse_file(std::
string_view file_path) → parse_ result - Parses a TOML document from a file.
-
auto parse_file(std::
u8string_view file_path) → parse_ result - Parses a TOML document from a file.
-
auto parse_file(std::
wstring_view file_path) → parse_ result - Parses a TOML document from a file.
Variables
-
template <typename T>bool is_array constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
array. -
template <typename T>bool is_boolean constexpr
- Metafunction for determining if a type is, or is a reference to, a bool or toml::value<bool>.
-
template <typename T>bool is_chronological constexpr
- Metafunction for determining if a type satisfies any of toml::
is_date, toml:: is_time or toml:: is_date_time. -
template <typename T>bool is_container constexpr
- Metafunction for determining if a type satisfies either toml::
is_table or toml:: is_array. -
template <typename T>bool is_date constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
date or toml::value<date>. -
template <typename T>bool is_date_time constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
date_time or toml::value<date_time>. -
template <typename T>bool is_floating_point constexpr
- Metafunction for determining if a type is, or is a reference to, a double or toml::value<double>.
-
template <typename T>bool is_integer constexpr
- Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
-
template <typename T>bool is_node constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
node (or one of its subclasses). -
template <typename T>bool is_node_view constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
node_view. -
template <typename T>bool is_number constexpr
- Metafunction for determining if a type satisfies either toml::
is_integer or toml:: is_floating_point. -
template <typename T>bool is_string constexpr
- Metafunction for determining if a type is, or is a reference to, a std::
string or toml::value<std::string>. -
template <typename T>bool is_table constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
table. -
template <typename T>bool is_time constexpr
- Metafunction for determining if a type is, or is a reference to, a toml::
time or toml::value<time>. -
template <typename T>bool is_value constexpr
- Metafunction for determining if a type is, or is a reference to, any of the toml value types. Excludes tables and arrays.
Enum documentation
enum class toml:: format_flags: uint8_t
Format flags for modifying how TOML data is printed to streams.
Enumerators | |
---|---|
none |
None. |
quote_dates_and_times |
Dates and times will be emitted as quoted strings. |
allow_literal_strings |
Strings will be emitted as single-quoted literal strings where possible. |
allow_multi_line_strings |
Strings containing newlines will be emitted as triple-quoted 'multi-line' strings where possible. |
allow_value_format_flags |
Values with special format flags will be formatted accordingly. |
enum class toml:: node_type: uint8_t
TOML node type identifiers.
Enumerators | |
---|---|
none |
Not-a-node. |
table |
The node is a toml:: |
array |
The node is a toml:: |
string |
The node is a toml::value<std::string>. |
integer |
The node is a toml::value<int64_t>. |
floating_point |
The node is a toml::value<double>. |
boolean |
The node is a toml::value<bool>. |
date |
The node is a toml::value<date>. |
time |
The node is a toml::value<time>. |
date_time |
The node is a toml::value<date_time>. |
enum class toml:: value_flags: uint8_t
Metadata associated with TOML values.
Enumerators | |
---|---|
none |
None. |
format_as_binary |
Format integer values as binary. |
format_as_octal |
Format integer values as octal. |
format_as_hexadecimal |
Format integer values as hexadecimal. |
Typedef documentation
template <typename T>
using toml:: inserted_type_of = typename impl::inserted_type_of_<impl::remove_cvref_t<T>>::type
Metafunction for determining which node type would be constructed if an object of this type was inserted into a toml::
template <typename T>
using toml:: optional = std:: optional<T>
The 'optional' type used throughout the library.
using toml:: source_index = uint16_t
The integer type used to tally line numbers and columns.
Function documentation
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
node_ type rhs)
Pretty-prints the value of a node_type to a stream.
auto arr = toml::array{ 1, 2.0, "3", false }; for (size_t i = 0; i < arr.size() i++) std::cout << "Element ["sv << i << "] is: "sv << arr[i].type() << "\n";
Element [0] is: integer Element [1] is: floating-point Element [2] is: string Element [3] is: boolean
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const date& rhs)
Prints a date out to a stream as YYYY-MM-DD
(per RFC 3339).
std::cout << toml::date{ 1987, 3, 16 } << "\n";
1987-03-16
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const time& rhs)
Prints a time out to a stream as HH:MM:SS.FFFFFF
(per RFC 3339).
std::cout << toml::time{ 10, 20, 34 } << "\n"; std::cout << toml::time{ 10, 20, 34, 500000000 } << "\n";
10:20:34 10:20:34.5
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const time_ offset& rhs)
Prints a time_+-HH:MM or Z
(per RFC 3339).
std::cout << toml::time_offset{ 2, 30 } << "\n"; std::cout << toml::time_offset{ 2, -30 } << "\n"; std::cout << toml::time_offset{} << "\n"; std::cout << toml::time_offset{ -2, 30 } << "\n"; std::cout << toml::time_offset{ -2, -30 } << "\n";
+02:30 +01:30 Z -01:30 -02:30
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const date_ time& rhs)
Prints a date_
std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 } } << "\n"; std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 }, { -2, -30 } } << "\n"; std::cout << toml::date_time{ { 1987, 3, 16 }, { 10, 20, 34 }, {} } << "\n";
1987-03-16T10:20:34 1987-03-16T10:20:34-02:30 1987-03-16T10:20:34Z
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const parse_ error& rhs)
Prints a parse_
Template parameters | |
---|---|
Char | The output stream's underlying character type. Must be 1 byte in size. |
Parameters | |
lhs | The stream. |
rhs | The parse_ |
Returns | The input stream. |
try { auto tbl = toml::parse("enabled = trUe"sv); } catch (const toml::parse_error & err) { std::cerr << "Parsing failed:\n"sv << err << "\n"; }
Parsing failed: Encountered unexpected character while parsing boolean; expected 'true', saw 'trU' (error occurred at line 1, column 13)
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const source_ position& rhs)
Prints a source_
Template parameters | |
---|---|
Char | The output stream's underlying character type. Must be 1 byte in size. |
Parameters | |
lhs | The stream. |
rhs | The source_ |
Returns | The input stream. |
auto tbl = toml::parse("bar = 42"sv); std::cout << "The value for 'bar' was found on "sv << tbl.get("bar")->source().begin() << "\n";
The value for 'bar' was found on line 1, column 7
template <typename Char>
std:: basic_ostream<Char>& toml:: operator<<(std:: basic_ostream<Char>& lhs,
const source_ region& rhs)
Prints a source_
Template parameters | |
---|---|
Char | The output stream's underlying character type. Must be 1 byte in size. |
Parameters | |
lhs | The stream. |
rhs | The source_ |
Returns | The input stream. |
auto tbl = toml::parse("bar = 42", "config.toml"); std::cout << "The value for 'bar' was found on "sv << tbl.get("bar")->source() << "\n";
The value for 'bar' was found on line 1, column 7 of 'config.toml'
parse_ result toml:: parse(std:: string_view doc,
std:: string_view source_path = {})
Parses a TOML document from a string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse("a = 3"sv); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse(std:: string_view doc,
std:: string&& source_path)
Parses a TOML document from a string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse("a = 3"sv, "foo.toml"); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse(std:: string_view doc,
std:: wstring_view source_path)
Parses a TOML document from a string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse("a = 3"sv, L"foo.toml"); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse(std:: u8string_view doc,
std:: string_view source_path = {})
Parses a TOML document from a char8_t string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse(u8"a = 3"sv); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse(std:: u8string_view doc,
std:: string&& source_path)
Parses a TOML document from a char8_t string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse(u8"a = 3"sv, "foo.toml"); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse(std:: u8string_view doc,
std:: wstring_view source_path)
Parses a TOML document from a char8_t string view.
Parameters | |
---|---|
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
auto tbl = toml::parse(u8"a = 3"sv, L"foo.toml"); std::cout << tbl["a"] << "\n";
3
template <typename Char>
parse_ result toml:: parse(std:: basic_istream<Char>& doc,
std:: string_view source_path = {})
Parses a TOML document from a stream.
Template parameters | |
---|---|
Char | The stream's underlying character type. Must be 1 byte in size. |
Parameters | |
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
std::stringstream ss; ss << "a = 3"sv; auto tbl = toml::parse(ss); std::cout << tbl["a"] << "\n";
3
template <typename Char>
parse_ result toml:: parse(std:: basic_istream<Char>& doc,
std:: string&& source_path)
Parses a TOML document from a stream.
Template parameters | |
---|---|
Char | The stream's underlying character type. Must be 1 byte in size. |
Parameters | |
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
std::stringstream ss; ss << "a = 3"sv; auto tbl = toml::parse(ss, "foo.toml"); std::cout << tbl["a"] << "\n";
3
template <typename Char>
parse_ result toml:: parse(std:: basic_istream<Char>& doc,
std:: wstring_view source_path)
Parses a TOML document from a stream.
Template parameters | |
---|---|
Char | The stream's underlying character type. Must be 1 byte in size. |
Parameters | |
doc | The TOML document to parse. Must be valid UTF-8. |
source_path | The path used to initialize each node's source().path . If you don't have a path (or you have no intention of using paths in diagnostics) then this parameter can safely be left blank. |
Returns | With exceptions: A toml:: |
std::stringstream ss; ss << "a = 3"sv; auto tbl = toml::parse(ss); std::cout << tbl["a"] << "\n";
3
parse_ result toml:: parse_file(std:: string_view file_path)
Parses a TOML document from a file.
Parameters | |
---|---|
file_path | The TOML document to parse. Must be valid UTF-8. |
Returns | With exceptions: A toml:: |
toml::parse_result get_foo_toml() { return toml::parse_file("foo.toml"); }
parse_ result toml:: parse_file(std:: u8string_view file_path)
Parses a TOML document from a file.
Parameters | |
---|---|
file_path | The TOML document to parse. Must be valid UTF-8. |
Returns | With exceptions: A toml:: |
toml::parse_result get_foo_toml() { return toml::parse_file(u8"foo.toml"); }
parse_ result toml:: parse_file(std:: wstring_view file_path)
Parses a TOML document from a file.
Parameters | |
---|---|
file_path | The TOML document to parse. Must be valid UTF-8. |
Returns | With exceptions: A toml:: |
toml::parse_result get_foo_toml() { return toml::parse_file(L"foo.toml"); }