NeBuild dev
Loading...
Searching...
No Matches
path.hpp File Reference
#include "forward_declarations.hpp"
#include "std_vector.hpp"
#include "header_start.hpp"
#include "header_end.hpp"

Go to the source code of this file.

Classes

class  path_component
 Represents a single component of a complete 'TOML-path': either a key or an array index. More...
 
class  path
 A TOML path. More...
 

Namespaces

namespace  literals
 

Functions

TOML_NODISCARD TOML_ALWAYS_INLINE path literals::operator""_tpath (const char *str, size_t len)
 Parses a TOML path from a string literal.
 
TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< node > TOML_CALLCONV at_path (node &root, const toml::path &path) noexcept
 Returns a view of the node matching a fully-qualified "TOML path".
 
TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< const node > TOML_CALLCONV at_path (const node &root, const toml::path &path) noexcept
 Returns a const view of the node matching a fully-qualified "TOML path".
 

Variables

 TOML_NAMESPACE_START
 
 TOML_NAMESPACE_END
 

Function Documentation

◆ at_path() [1/2]

TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< const node > TOML_CALLCONV at_path ( const node &  root,
const toml::path &  path 
)
noexcept

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

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

◆ at_path() [2/2]

TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< node > TOML_CALLCONV at_path ( node &  root,
const toml::path &  path 
)
noexcept

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

\detail \cpp auto config = toml::parse(R"( [foo] bar = [ 0, 1, 2, [ 3 ], { kek = 4 } ] )"sv);

toml::path path1("foo.bar[2]"); toml::path path2("foo.bar[4].kek"); std::cout << toml::at_path(config, path1) << "\n"; std::cout << toml::at_path(config, path1.parent_path()) << "\n"; std::cout << toml::at_path(config, path2) << "\n"; std::cout << toml::at_path(config, path2.parent_path()) << "\n"; \ecpp

\out 2 [ 0, 1, 2, [ 3 ], { kek = 4 } ] 4 { kek = 4 } \eout

Note
Keys in paths are interpreted literally, so whitespace (or lack thereof) matters: \cpp toml::at_path(config, toml::path("foo.bar")) // same as config["foo"]["bar"] toml::at_path(config, toml::path("foo. bar")) // same as config["foo"][" bar"] toml::at_path(config, toml::path("foo..bar")) // same as config["foo"][""]["bar"] toml::at_path(config, toml::path(".foo.bar")) // same as config[""]["foo"]["bar"] \ecpp
Additionally, TOML allows '.' (period) characters to appear in keys if they are quoted strings. This function makes no allowance for this, instead treating all period characters as sub-table delimiters.
Parameters
rootThe root node from which the path will be traversed.
pathThe "TOML path" to traverse.

Variable Documentation

◆ TOML_NAMESPACE_END

TOML_NAMESPACE_END

◆ TOML_NAMESPACE_START

TOML_NAMESPACE_START
Initial value:
{
enum class TOML_CLOSED_ENUM path_component_type : uint8_t
{
key = 0x1,
array_index = 0x2
}
#define TOML_CLOSED_ENUM
Definition preprocessor.hpp:557