13 enum class TOML_CLOSED_ENUM path_component_type : uint8_t { key = 0x1, array_index = 0x2 };
19 static constexpr size_t size =
20 (
sizeof(size_t) <
sizeof(std::string) ?
sizeof(std::string) :
sizeof(size_t));
21 static constexpr size_t align =
22 (
alignof(size_t) <
alignof(std::string) ?
alignof(std::string) :
alignof(size_t));
26 alignas(storage_t::align)
mutable storage_t value_storage_;
28 path_component_type type_;
34 template <
typename Type>
39 static void store_key(std::string_view key, storage_t& storage_) {
40 ::new (
static_cast<void*
>(storage_.bytes)) std::string{key};
43 static void store_index(
size_t index, storage_t& storage_)
noexcept {
44 ::new (
static_cast<void*
>(storage_.bytes)) std::size_t{
index};
47 void destroy()
noexcept {
48 if (type_ == path_component_type::key) get_as<std::string>(value_storage_)->~basic_string();
52 size_t& index_ref()
noexcept {
54 return *get_as<size_t>(value_storage_);
58 std::string& key_ref()
noexcept {
60 return *get_as<std::string>(value_storage_);
80#if TOML_ENABLE_WINDOWS_COMPAT
118#if TOML_ENABLE_WINDOWS_COMPAT
140 return *get_as<const size_t>(value_storage_);
145 explicit operator size_t() const noexcept {
return index(); }
156 const std::string&
key() const noexcept {
158 return *get_as<const std::string>(value_storage_);
163 explicit operator const std::string&()
const noexcept {
return key(); }
170 path_component_type
type() const noexcept {
return type_; }
213 std::vector<path_component> components_;
216 void print_to(std::ostream&)
const;
234#if TOML_ENABLE_WINDOWS_COMPAT
242 explicit path(std::wstring_view);
259 size_t size() const noexcept {
return components_.
size(); }
263 explicit operator bool() const noexcept {
return !components_.empty(); }
267 bool empty() const noexcept {
return components_.empty(); }
273 return components_[
index];
280 return components_[
index];
296#if TOML_ENABLE_WINDOWS_COMPAT
318#if TOML_ENABLE_WINDOWS_COMPAT
345#if TOML_ENABLE_WINDOWS_COMPAT
367#if TOML_ENABLE_WINDOWS_COMPAT
394#if TOML_ENABLE_WINDOWS_COMPAT
433#if TOML_ENABLE_WINDOWS_COMPAT
477 explicit operator std::string()
const {
return str(); }
479#if TOML_ENABLE_WINDOWS_COMPAT
493 explicit operator std::wstring()
const {
return wide_str(); }
530#if TOML_ENABLE_WINDOWS_COMPAT
569 using iterator = std::vector<path_component>::iterator;
bool equal(const T &x, const U &y)
TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< const node > TOML_CALLCONV at_path(const node &root, std::string_view path) noexcept
Returns a const view of the node matching a fully-qualified "TOML path".
Represents a single component of a complete 'TOML-path': either a key or an array index.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component()
Default constructor (creates an empty key).
TOML_EXPORTED_MEMBER_FUNCTION path_component & operator=(const path_component &rhs)
Copy-assignment operator.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component(const path_component &pc)
Copy constructor.
TOML_PURE_GETTER const std::string & key() const noexcept
Returns the key string.
TOML_PURE_INLINE_GETTER friend bool operator==(const path_component &lhs, const path_component &rhs) noexcept
Returns true if two path components represent the same key or array index.
~path_component() noexcept
Destructor.
TOML_PURE_INLINE_GETTER friend bool operator!=(const path_component &lhs, const path_component &rhs) noexcept
Returns true if two path components do not represent the same key or array index.
TOML_EXPORTED_MEMBER_FUNCTION path_component & operator=(std::string_view new_key)
Assigns a path key to this path component.
TOML_EXPORTED_MEMBER_FUNCTION path_component & operator=(size_t new_index) noexcept
Assigns an array index to this path component.
TOML_PURE_GETTER size_t index() const noexcept
Returns the array index (const lvalue overload).
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component(size_t index) noexcept
Constructor for a path component that is an array index.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component(std::string_view key)
Constructor for a path component that is a key string.
TOML_PURE_INLINE_GETTER path_component_type type() const noexcept
Retrieve the type of this path component, either path_component::key or path_component::array_index.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component(std::wstring_view key)
Constructor for a path component that is a key string.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path_component(path_component &&pc) noexcept
Move constructor.
TOML_EXPORTED_MEMBER_FUNCTION path_component & operator=(path_component &&rhs) noexcept
Move-assignment operator.
TOML_EXPORTED_MEMBER_FUNCTION path_component & operator=(std::wstring_view new_key)
Assigns a path key to this path component.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(std::string_view lhs, const path &rhs)
Returns whether two paths are not the same.
TOML_NODISCARD friend path operator+(std::wstring_view lhs, const path &rhs)
Concatenates two paths.
TOML_NODISCARD TOML_EXPORTED_MEMBER_FUNCTION std::wstring wide_str() const
Returns a string representation of this path.
TOML_EXPORTED_MEMBER_FUNCTION void clear() noexcept
Erases the contents of the path.
TOML_PURE_INLINE_GETTER friend bool operator!=(const path &lhs, const path &rhs) noexcept
Returns whether two paths are not the same.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(const path &lhs, std::string_view rhs)
Returns whether two paths are not the same.
std::vector< path_component >::const_iterator const_iterator
TOML_PURE_INLINE_GETTER friend bool operator==(const path &lhs, const path &rhs) noexcept
Returns whether two paths are the same.
TOML_PURE_INLINE_GETTER const path_component & operator[](size_t index) const noexcept
Fetch a path component by index (const overload).
TOML_ALWAYS_INLINE friend std::ostream & operator<<(std::ostream &os, const path &rhs)
Prints the string representation of a #toml::path out to a stream.
TOML_PURE_INLINE_GETTER iterator end() noexcept
Returns an iterator to one-past-the-last component in the path.
TOML_ALWAYS_INLINE path & append(std::string_view str)
Parses a path and appends it onto the end of this one.
TOML_EXPORTED_MEMBER_FUNCTION path & prepend(path &&)
Prepends another path onto the beginning of this one.
std::vector< path_component >::iterator iterator
TOML_NODISCARD friend path operator+(const path &lhs, std::string_view rhs)
Concatenates two paths.
TOML_PURE_INLINE_GETTER size_t size() const noexcept
Returns the number of components in the path.
TOML_NODISCARD friend path operator+(std::string_view lhs, const path &rhs)
Concatenates two paths.
TOML_NODISCARD TOML_EXPORTED_MEMBER_FUNCTION std::string str() const
Returns a string representation of this path.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(std::wstring_view lhs, const path &rhs)
Returns whether two paths are not the same.
TOML_EXPORTED_MEMBER_FUNCTION path & operator+=(path &&)
Appends another path onto the end of this one.
TOML_NODISCARD_CTOR path() noexcept=default
Default constructor.
TOML_ALWAYS_INLINE path & append(std::wstring_view str)
Parses a path and appends it onto the end of this one.
TOML_PURE_INLINE_GETTER iterator begin() noexcept
Returns an iterator to the first component in the path.
TOML_ALWAYS_INLINE path & assign(std::wstring_view str)
Replaces the contents of the path object by a new path.
TOML_PURE_INLINE_GETTER const_iterator begin() const noexcept
Returns a const iterator to the first component in the path.
TOML_EXPORTED_MEMBER_FUNCTION path & operator+=(std::wstring_view)
Parses a path and appends it onto the end of this one.
TOML_EXPORTED_MEMBER_FUNCTION path & prepend(std::wstring_view)
Parses a path and prepends it onto the beginning of this one.
path & operator=(path &&) noexcept=default
Move-assignment operator.
TOML_NODISCARD friend path operator+(const path &lhs, std::wstring_view rhs)
Concatenates two paths.
TOML_PURE_INLINE_GETTER path_component & operator[](size_t index) noexcept
Fetch a path component by index.
TOML_EXPORTED_MEMBER_FUNCTION path & prepend(std::string_view)
Parses a path and prepends it onto the beginning of this one.
TOML_ALWAYS_INLINE path & append(const path &p)
Appends another path onto the end of this one.
TOML_EXPORTED_MEMBER_FUNCTION path & prepend(const path &)
Prepends another path onto the beginning of this one.
TOML_PURE_INLINE_GETTER const_iterator end() const noexcept
Returns a const iterator to one-past-the-last component in the path.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(std::string_view lhs, const path &rhs)
Returns whether two paths are the same.
TOML_EXPORTED_MEMBER_FUNCTION path & operator=(std::wstring_view)
Replaces the contents of the path by parsing from a string.
TOML_NODISCARD_CTOR TOML_EXPORTED_MEMBER_FUNCTION path(std::wstring_view)
Construct a path by parsing from a string.
TOML_PURE_INLINE_GETTER const_iterator cbegin() const noexcept
Returns a const iterator to the first component in the path.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(const path &lhs, std::wstring_view rhs)
Returns whether two paths are not the same.
TOML_EXPORTED_MEMBER_FUNCTION path & operator+=(const path &)
Appends another path onto the end of this one.
TOML_PURE_INLINE_GETTER bool empty() const noexcept
Whether (true) or not (false) the path is empty.
TOML_ALWAYS_INLINE path & assign(const path &p)
Replaces the contents of the path with that of another.
TOML_PURE_INLINE_GETTER const_iterator cend() const noexcept
Returns a const iterator to one-past-the-last component in the path.
TOML_NODISCARD friend path operator+(const path &lhs, const path &rhs)
Concatenates two paths.
TOML_EXPORTED_MEMBER_FUNCTION path & operator+=(std::string_view)
Parses a path and appends it onto the end of this one.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(const path &lhs, std::wstring_view rhs)
Returns whether two paths are the same.
TOML_ALWAYS_INLINE path & assign(path &&p) noexcept
Replaces the contents of the path with that of another.
TOML_ALWAYS_INLINE path & append(path &&p)
Appends another path onto the end of this one.
path & operator=(const path &)=default
Copy-assignment operator.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(std::wstring_view lhs, const path &rhs)
Returns whether two paths are the same.
TOML_ALWAYS_INLINE path & assign(std::string_view str)
Replaces the contents of the path object by a new path.
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(const path &lhs, std::string_view rhs)
Returns whether two paths are the same.
~path() noexcept=default
Default destructor.
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
#define TOML_EXPORTED_STATIC_FUNCTION
An 'export' annotation to add to static class member functions. \detail Not defined by default.
#define TOML_ASSERT(expr)
Sets the assert function used by the library. \detail Defaults to the standard C assert().
#define TOML_ASSERT_ASSUME(expr)
#define TOML_EXPORTED_FREE_FUNCTION
An 'export' annotation to add to free functions. \detail Not defined by default.
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
#define TOML_NODISCARD_CTOR
#define TOML_PURE_INLINE_GETTER
#define TOML_ALWAYS_INLINE