26 static constexpr size_t size =
27 (
sizeof(size_t) <
sizeof(std::string) ?
sizeof(std::string) :
sizeof(size_t));
28 static constexpr size_t align =
29 (
alignof(size_t) <
alignof(std::string) ?
alignof(std::string) :
alignof(size_t));
31 alignas(align)
unsigned char bytes[size];
33 alignas(storage_t::align)
mutable storage_t value_storage_;
35 path_component_type type_;
41 template <
typename Type>
43 static Type* get_as(storage_t& s)
noexcept
48 static void store_key(std::string_view key, storage_t& storage_)
50 ::new (
static_cast<void*
>(storage_.bytes)) std::string{ key };
53 static void store_index(
size_t index, storage_t& storage_)
noexcept
55 ::new (
static_cast<void*
>(storage_.bytes)) std::size_t{ index };
58 void destroy()
noexcept
60 if (type_ == path_component_type::key)
61 get_as<std::string>(value_storage_)->~basic_string();
65 size_t& index_ref()
noexcept
68 return *get_as<size_t>(value_storage_);
72 std::string& key_ref()
noexcept
75 return *get_as<std::string>(value_storage_);
95#if TOML_ENABLE_WINDOWS_COMPAT
132#if TOML_ENABLE_WINDOWS_COMPAT
158 return *get_as<const size_t>(value_storage_);
163 explicit operator size_t() const noexcept
177 const std::string&
key() const noexcept
180 return *get_as<const std::string>(value_storage_);
185 explicit operator const std::string&()
const noexcept
194 path_component_type
type() const noexcept
206 return equal(lhs, rhs);
213 return !equal(lhs, rhs);
243 std::vector<path_component> components_;
246 void print_to(std::ostream&)
const;
264#if TOML_ENABLE_WINDOWS_COMPAT
271 explicit path(std::wstring_view);
288 size_t size() const noexcept
290 return components_.
size();
295 explicit operator bool() const noexcept
297 return !components_.empty();
304 return components_.empty();
312 return components_[index];
320 return components_[index];
336#if TOML_ENABLE_WINDOWS_COMPAT
357 return *
this = std::move(p);
367#if TOML_ENABLE_WINDOWS_COMPAT
397#if TOML_ENABLE_WINDOWS_COMPAT
418 return *
this += std::move(p);
428#if TOML_ENABLE_WINDOWS_COMPAT
458#if TOML_ENABLE_WINDOWS_COMPAT
500#if TOML_ENABLE_WINDOWS_COMPAT
547 explicit operator std::string()
const
552#if TOML_ENABLE_WINDOWS_COMPAT
566 explicit operator std::wstring()
const
582 return equal(lhs, rhs);
589 return !equal(lhs, rhs);
597 return lhs ==
path{ rhs };
613 return lhs !=
path{ rhs };
624#if TOML_ENABLE_WINDOWS_COMPAT
633 return lhs ==
path{ rhs };
653 return lhs !=
path{ rhs };
675 using iterator = std::vector<path_component>::iterator;
686 return components_.begin();
694 return components_.end();
702 return components_.begin();
710 return components_.end();
718 return components_.begin();
726 return components_.end();
745 path truncated(
size_t n) const;
767 path subpath(
size_t start,
size_t length) const;
793 path operator"" _tpath(
const char* str,
size_t len)
795 return path(std::string_view{ str, len });
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.
Definition path.hpp:22
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.
Definition path.hpp:177
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.
Definition path.hpp:204
~path_component() noexcept
Destructor.
Definition path.hpp:143
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.
Definition path.hpp:211
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).
Definition path.hpp:155
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.
Definition path.hpp:194
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.
A TOML path.
Definition path.hpp:239
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(std::string_view lhs, const path &rhs)
Returns whether two paths are not the same.
Definition path.hpp:619
TOML_NODISCARD friend path operator+(std::wstring_view lhs, const path &rhs)
Concatenates two paths.
Definition path.hpp:517
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.
Definition path.hpp:587
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(const path &lhs, std::string_view rhs)
Returns whether two paths are not the same.
Definition path.hpp:611
std::vector< path_component >::const_iterator const_iterator
Definition path.hpp:679
TOML_PURE_INLINE_GETTER friend bool operator==(const path &lhs, const path &rhs) noexcept
Returns whether two paths are the same.
Definition path.hpp:580
TOML_PURE_INLINE_GETTER const path_component & operator[](size_t index) const noexcept
Fetch a path component by index (const overload).
Definition path.hpp:317
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.
Definition path.hpp:533
TOML_PURE_INLINE_GETTER iterator end() noexcept
Returns an iterator to one-past-the-last component in the path.
Definition path.hpp:692
TOML_ALWAYS_INLINE path & append(std::string_view str)
Parses a path and appends it onto the end of this one.
Definition path.hpp:423
TOML_EXPORTED_MEMBER_FUNCTION path & prepend(path &&)
Prepends another path onto the beginning of this one.
std::vector< path_component >::iterator iterator
Definition path.hpp:675
TOML_NODISCARD friend path operator+(const path &lhs, std::string_view rhs)
Concatenates two paths.
Definition path.hpp:484
TOML_PURE_INLINE_GETTER size_t size() const noexcept
Returns the number of components in the path.
Definition path.hpp:288
TOML_NODISCARD friend path operator+(std::string_view lhs, const path &rhs)
Concatenates two paths.
Definition path.hpp:493
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.
Definition path.hpp:661
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.
Definition path.hpp:434
TOML_PURE_INLINE_GETTER iterator begin() noexcept
Returns an iterator to the first component in the path.
Definition path.hpp:684
TOML_ALWAYS_INLINE path & assign(std::wstring_view str)
Replaces the contents of the path object by a new path.
Definition path.hpp:373
TOML_PURE_INLINE_GETTER const_iterator begin() const noexcept
Returns a const iterator to the first component in the path.
Definition path.hpp:700
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.
Definition path.hpp:506
TOML_PURE_INLINE_GETTER path_component & operator[](size_t index) noexcept
Fetch a path component by index.
Definition path.hpp:309
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.
Definition path.hpp:409
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.
Definition path.hpp:708
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(std::string_view lhs, const path &rhs)
Returns whether two paths are the same.
Definition path.hpp:603
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.
Definition path.hpp:716
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator!=(const path &lhs, std::wstring_view rhs)
Returns whether two paths are not the same.
Definition path.hpp:651
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.
Definition path.hpp:302
TOML_ALWAYS_INLINE path & assign(const path &p)
Replaces the contents of the path with that of another.
Definition path.hpp:348
TOML_PURE_INLINE_GETTER const_iterator cend() const noexcept
Returns a const iterator to one-past-the-last component in the path.
Definition path.hpp:724
TOML_NODISCARD friend path operator+(const path &lhs, const path &rhs)
Concatenates two paths.
Definition path.hpp:475
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.
Definition path.hpp:631
TOML_ALWAYS_INLINE path & assign(path &&p) noexcept
Replaces the contents of the path with that of another.
Definition path.hpp:355
TOML_ALWAYS_INLINE path & append(path &&p)
Appends another path onto the end of this one.
Definition path.hpp:416
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.
Definition path.hpp:641
TOML_ALWAYS_INLINE path & assign(std::string_view str)
Replaces the contents of the path object by a new path.
Definition path.hpp:362
TOML_NODISCARD TOML_ALWAYS_INLINE friend bool operator==(const path &lhs, std::string_view rhs)
Returns whether two paths are the same.
Definition path.hpp:595
~path() noexcept=default
Default destructor.
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
Definition preprocessor.hpp:1134
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
Definition preprocessor.hpp:979
#define TOML_EXPORTED_STATIC_FUNCTION
An 'export' annotation to add to static class member functions. \detail Not defined by default.
Definition preprocessor.hpp:985
#define TOML_ASSERT(expr)
Sets the assert function used by the library. \detail Defaults to the standard C assert().
Definition preprocessor.hpp:1185
#define TOML_ASSERT_ASSUME(expr)
Definition preprocessor.hpp:1190
#define TOML_EXPORTED_FREE_FUNCTION
An 'export' annotation to add to free functions. \detail Not defined by default.
Definition preprocessor.hpp:988
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
Definition preprocessor.hpp:982
TOML_NAMESPACE_START
Definition path.hpp:12
TOML_NAMESPACE_END
Definition path.hpp:849
#define TOML_NODISCARD_CTOR
Definition preprocessor.hpp:446
#define TOML_CLOSED_ENUM
Definition preprocessor.hpp:557
#define TOML_NODISCARD
Definition preprocessor.hpp:439
#define TOML_PURE_GETTER
Definition preprocessor.hpp:474
#define TOML_PURE_INLINE_GETTER
Definition preprocessor.hpp:479
#define TOML_ALWAYS_INLINE
Definition preprocessor.hpp:405
#define TOML_LAUNDER(x)
Definition std_new.hpp:17