NeBuild dev
Loading...
Searching...
No Matches
parse_result Class Reference

The result of a parsing operation. More...

#include <parse_result.hpp>

Classes

struct  storage_t
 

Public Member Functions

TOML_NODISCARD_CTOR parse_result () noexcept
 Default constructs an 'error' result.
 
TOML_NODISCARD_CTOR parse_result (toml::table &&tbl) noexcept
 
TOML_NODISCARD_CTOR parse_result (parse_error &&err) noexcept
 
TOML_NODISCARD_CTOR parse_result (parse_result &&res) noexcept
 Move constructor.
 
parse_resultoperator= (parse_result &&rhs) noexcept
 Move-assignment operator.
 
 ~parse_result () noexcept
 Destructor.
 
Result state
TOML_NODISCARD bool succeeded () const noexcept
 Returns true if parsing succeeeded.
 
TOML_NODISCARD bool failed () const noexcept
 Returns true if parsing failed.
 
TOML_NODISCARD operator bool () const noexcept
 Returns true if parsing succeeded.
 
Successful parses
Warning
It is undefined behaviour to call these functions when the result respresents a failed parse. Check failed(), succeeded or operator bool() to determine the result's state.
TOML_NODISCARD toml::table & table () &noexcept
 Returns the internal toml::table.
 
TOML_NODISCARD toml::table && table () &&noexcept
 Returns the internal toml::table (rvalue overload).
 
TOML_NODISCARD const toml::table & table () const &noexcept
 Returns the internal toml::table (const lvalue overload).
 
TOML_NODISCARD operator toml::table & () noexcept
 Returns the internal toml::table.
 
TOML_NODISCARD operator toml::table && () noexcept
 Returns the internal toml::table (rvalue overload).
 
TOML_NODISCARD operator const toml::table & () const noexcept
 Returns the internal toml::table (const lvalue overload).
 
Failed parses
Warning
It is undefined behaviour to call these functions when the result respresents a successful parse. Check failed(), succeeded or operator bool() to determine the result's state.
TOML_NODISCARD parse_error & error () &noexcept
 Returns the internal toml::parse_error.
 
TOML_NODISCARD parse_error && error () &&noexcept
 Returns the internal toml::parse_error (rvalue overload).
 
TOML_NODISCARD const parse_error & error () const &noexcept
 Returns the internal toml::parse_error (const lvalue overload).
 
TOML_NODISCARD operator parse_error & () noexcept
 Returns the internal toml::parse_error.
 
TOML_NODISCARD operator parse_error && () noexcept
 Returns the internal toml::parse_error (rvalue overload).
 
TOML_NODISCARD operator const parse_error & () const noexcept
 Returns the internal toml::parse_error (const lvalue overload).
 
Node views
TOML_NODISCARD node_view< node > at_path (std::string_view path) noexcept
 Returns a view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< const node > at_path (std::string_view path) const noexcept
 Returns a const view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< node > at_path (const toml::path &path) noexcept
 Returns a view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< const node > at_path (const toml::path &path) const noexcept
 Returns a const view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< node > at_path (std::wstring_view path)
 Returns a view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< const node > at_path (std::wstring_view path) const
 Returns a const view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< node > operator[] (const toml::path &path) noexcept
 Returns a view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< const node > operator[] (const toml::path &path) const noexcept
 Returns a const view of the subnode matching a fully-qualified "TOML path".
 
TOML_NODISCARD node_view< node > operator[] (std::string_view key) noexcept
 Gets a node_view for the selected key-value pair in the wrapped table.
 
TOML_NODISCARD node_view< const node > operator[] (std::string_view key) const noexcept
 Gets a node_view for the selected key-value pair in the wrapped table (const overload).
 
TOML_NODISCARD node_view< node > operator[] (std::wstring_view key)
 Gets a node_view for the selected key-value pair in the wrapped table.
 
TOML_NODISCARD node_view< const node > operator[] (std::wstring_view key) const
 Gets a node_view for the selected key-value pair in the wrapped table (const overload).
 

Private Member Functions

void destroy () noexcept
 

Static Private Member Functions

template<typename Type >
TOML_NODISCARD static TOML_ALWAYS_INLINE Type * get_as (storage_t &s) noexcept
 

Private Attributes

storage_t storage_
 
bool err_
 

Friends

std::ostream & operator<< (std::ostream &os, const parse_result &result)
 Prints the held error or table object out to a text stream.
 

Iteration

using iterator = table_iterator
 A BidirectionalIterator for iterating over key-value pairs in a wrapped toml::table.
 
using const_iterator = const_table_iterator
 A BidirectionalIterator for iterating over const key-value pairs in a wrapped toml::table.
 
TOML_NODISCARD table_iterator begin () noexcept
 Returns an iterator to the first key-value pair in the wrapped table.
 
TOML_NODISCARD const_table_iterator begin () const noexcept
 Returns an iterator to the first key-value pair in the wrapped table.
 
TOML_NODISCARD const_table_iterator cbegin () const noexcept
 Returns an iterator to the first key-value pair in the wrapped table.
 
TOML_NODISCARD table_iterator end () noexcept
 Returns an iterator to one-past-the-last key-value pair in the wrapped table.
 
TOML_NODISCARD const_table_iterator end () const noexcept
 Returns an iterator to one-past-the-last key-value pair in the wrapped table.
 
TOML_NODISCARD const_table_iterator cend () const noexcept
 Returns an iterator to one-past-the-last key-value pair in the wrapped table.
 

Detailed Description

The result of a parsing operation.

\availability This type only exists when exceptions are disabled. Otherwise parse_result is just an alias for toml::table: \cpp #if TOML_EXCEPTIONS using parse_result = table; #else class parse_result { // ... #endif \ecpp

\detail A parse_result is effectively a discriminated union containing either a toml::table or a toml::parse_error. Most member functions assume a particular one of these two states, and calling them when in the wrong state will cause errors (e.g. attempting to access the error object when parsing was successful). \cpp toml::parse_result result = toml::parse_file("config.toml"); if (result) do_stuff_with_a_table(result); //implicitly converts to table& else std::cerr << "Parse failed:\n"sv << result.error() << "\n"; \ecpp

\out example output:

Parse failed: Encountered unexpected character while parsing boolean; expected 'true', saw 'trU' (error occurred at line 1, column 13 of 'config.toml') \eout

Getting node_views (operator[], at_path()) and using the iterator accessor functions (begin(), end() etc.) are unconditionally safe; when parsing fails these just return 'empty' values. A ranged-for loop on a failed parse_result is also safe since begin() and end() return the same iterator and will not lead to any dereferences and iterations.

Member Typedef Documentation

◆ const_iterator

A BidirectionalIterator for iterating over const key-value pairs in a wrapped toml::table.

◆ iterator

using parse_result::iterator = table_iterator

A BidirectionalIterator for iterating over key-value pairs in a wrapped toml::table.

Constructor & Destructor Documentation

◆ parse_result() [1/4]

TOML_NODISCARD_CTOR parse_result::parse_result ( )
inlinenoexcept

Default constructs an 'error' result.

◆ parse_result() [2/4]

TOML_NODISCARD_CTOR parse_result::parse_result ( toml::table &&  tbl)
inlineexplicitnoexcept

◆ parse_result() [3/4]

TOML_NODISCARD_CTOR parse_result::parse_result ( parse_error &&  err)
inlineexplicitnoexcept

◆ parse_result() [4/4]

TOML_NODISCARD_CTOR parse_result::parse_result ( parse_result &&  res)
inlinenoexcept

Move constructor.

◆ ~parse_result()

parse_result::~parse_result ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ at_path() [1/6]

TOML_NODISCARD node_view< const node > parse_result::at_path ( const toml::path &  path) const
inlinenoexcept

Returns a const view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::at_path(const toml::path&)

◆ at_path() [2/6]

TOML_NODISCARD node_view< node > parse_result::at_path ( const toml::path &  path)
inlinenoexcept

Returns a view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::at_path(const toml::path&)

◆ at_path() [3/6]

TOML_NODISCARD node_view< const node > parse_result::at_path ( std::string_view  path) const
inlinenoexcept

Returns a const view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::at_path(std::string_view)

◆ at_path() [4/6]

TOML_NODISCARD node_view< node > parse_result::at_path ( std::string_view  path)
inlinenoexcept

Returns a view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::at_path(std::string_view)

◆ at_path() [5/6]

TOML_NODISCARD node_view< node > parse_result::at_path ( std::wstring_view  path)
inline

Returns a view of the subnode matching a fully-qualified "TOML path".

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

See also
#toml::node::at_path(std::string_view)

◆ at_path() [6/6]

TOML_NODISCARD node_view< const node > parse_result::at_path ( std::wstring_view  path) const
inline

Returns a const view of the subnode matching a fully-qualified "TOML path".

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

See also
#toml::node::at_path(std::string_view)

◆ begin() [1/2]

TOML_NODISCARD const_table_iterator parse_result::begin ( ) const
inlinenoexcept

Returns an iterator to the first key-value pair in the wrapped table.

Remarks
Always returns the same value as end() if parsing failed.

◆ begin() [2/2]

TOML_NODISCARD table_iterator parse_result::begin ( )
inlinenoexcept

Returns an iterator to the first key-value pair in the wrapped table.

Remarks
Always returns the same value as end() if parsing failed.

◆ cbegin()

TOML_NODISCARD const_table_iterator parse_result::cbegin ( ) const
inlinenoexcept

Returns an iterator to the first key-value pair in the wrapped table.

Remarks
Always returns the same value as cend() if parsing failed.

◆ cend()

TOML_NODISCARD const_table_iterator parse_result::cend ( ) const
inlinenoexcept

Returns an iterator to one-past-the-last key-value pair in the wrapped table.

◆ destroy()

void parse_result::destroy ( )
inlineprivatenoexcept

◆ end() [1/2]

TOML_NODISCARD const_table_iterator parse_result::end ( ) const
inlinenoexcept

Returns an iterator to one-past-the-last key-value pair in the wrapped table.

◆ end() [2/2]

TOML_NODISCARD table_iterator parse_result::end ( )
inlinenoexcept

Returns an iterator to one-past-the-last key-value pair in the wrapped table.

◆ error() [1/3]

TOML_NODISCARD parse_error && parse_result::error ( ) &&
inlinenoexcept

Returns the internal toml::parse_error (rvalue overload).

◆ error() [2/3]

TOML_NODISCARD parse_error & parse_result::error ( ) &
inlinenoexcept

Returns the internal toml::parse_error.

◆ error() [3/3]

TOML_NODISCARD const parse_error & parse_result::error ( ) const &
inlinenoexcept

Returns the internal toml::parse_error (const lvalue overload).

◆ failed()

TOML_NODISCARD bool parse_result::failed ( ) const
inlinenoexcept

Returns true if parsing failed.

◆ get_as()

template<typename Type >
TOML_NODISCARD static TOML_ALWAYS_INLINE Type * parse_result::get_as ( storage_t s)
inlinestaticprivatenoexcept

◆ operator bool()

TOML_NODISCARD parse_result::operator bool ( ) const
inlineexplicitnoexcept

Returns true if parsing succeeded.

◆ operator const parse_error &()

TOML_NODISCARD parse_result::operator const parse_error & ( ) const
inlineexplicitnoexcept

Returns the internal toml::parse_error (const lvalue overload).

◆ operator const toml::table &()

TOML_NODISCARD parse_result::operator const toml::table & ( ) const
inlinenoexcept

Returns the internal toml::table (const lvalue overload).

◆ operator parse_error &()

TOML_NODISCARD parse_result::operator parse_error & ( )
inlineexplicitnoexcept

Returns the internal toml::parse_error.

◆ operator parse_error &&()

TOML_NODISCARD parse_result::operator parse_error && ( )
inlineexplicitnoexcept

Returns the internal toml::parse_error (rvalue overload).

◆ operator toml::table &()

TOML_NODISCARD parse_result::operator toml::table & ( )
inlinenoexcept

Returns the internal toml::table.

◆ operator toml::table &&()

TOML_NODISCARD parse_result::operator toml::table && ( )
inlinenoexcept

Returns the internal toml::table (rvalue overload).

◆ operator=()

parse_result & parse_result::operator= ( parse_result &&  rhs)
inlinenoexcept

Move-assignment operator.

◆ operator[]() [1/6]

TOML_NODISCARD node_view< const node > parse_result::operator[] ( const toml::path &  path) const
inlinenoexcept

Returns a const view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::operator[](const toml::path&)

◆ operator[]() [2/6]

TOML_NODISCARD node_view< node > parse_result::operator[] ( const toml::path &  path)
inlinenoexcept

Returns a view of the subnode matching a fully-qualified "TOML path".

See also
#toml::node::operator[](const toml::path&)

◆ operator[]() [3/6]

TOML_NODISCARD node_view< const node > parse_result::operator[] ( std::string_view  key) const
inlinenoexcept

Gets a node_view for the selected key-value pair in the wrapped table (const overload).

Parameters
keyThe key used for the lookup.
Returns
A view of the value at the given key if parsing was successful and a matching key existed, or an empty node view.
See also
toml::node_view

◆ operator[]() [4/6]

TOML_NODISCARD node_view< node > parse_result::operator[] ( std::string_view  key)
inlinenoexcept

Gets a node_view for the selected key-value pair in the wrapped table.

Parameters
keyThe key used for the lookup.
Returns
A view of the value at the given key if parsing was successful and a matching key existed, or an empty node view.
See also
toml::node_view

◆ operator[]() [5/6]

TOML_NODISCARD node_view< node > parse_result::operator[] ( std::wstring_view  key)
inline

Gets a node_view for the selected key-value pair in the wrapped table.

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

Parameters
keyThe key used for the lookup.
Returns
A view of the value at the given key if parsing was successful and a matching key existed, or an empty node view.
See also
toml::node_view

◆ operator[]() [6/6]

TOML_NODISCARD node_view< const node > parse_result::operator[] ( std::wstring_view  key) const
inline

Gets a node_view for the selected key-value pair in the wrapped table (const overload).

\availability This overload is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

Parameters
keyThe key used for the lookup.
Returns
A view of the value at the given key if parsing was successful and a matching key existed, or an empty node view.
See also
toml::node_view

◆ succeeded()

TOML_NODISCARD bool parse_result::succeeded ( ) const
inlinenoexcept

Returns true if parsing succeeeded.

◆ table() [1/3]

TOML_NODISCARD toml::table && parse_result::table ( ) &&
inlinenoexcept

Returns the internal toml::table (rvalue overload).

◆ table() [2/3]

TOML_NODISCARD toml::table & parse_result::table ( ) &
inlinenoexcept

Returns the internal toml::table.

◆ table() [3/3]

TOML_NODISCARD const toml::table & parse_result::table ( ) const &
inlinenoexcept

Returns the internal toml::table (const lvalue overload).

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const parse_result result 
)
friend

Prints the held error or table object out to a text stream.

\availability This operator is only available when TOML_ENABLE_FORMATTERS is enabled.

Member Data Documentation

◆ err_

bool parse_result::err_
private

◆ storage_

storage_t parse_result::storage_
mutableprivate

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