Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
key.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "header_start.hpp"
8#include "print_to_stream.hpp"
9#include "source_region.hpp"
10#include "std_utility.hpp"
11
30 class key {
31 private:
32 std::string key_;
33 source_region source_;
34
35 public:
38 key() noexcept = default;
39
42 explicit key(std::string_view k, source_region&& src = {}) //
43 : key_{k}, source_{std::move(src)} {}
44
47 explicit key(std::string_view k, const source_region& src) //
48 : key_{k}, source_{src} {}
49
52 explicit key(std::string&& k, source_region&& src = {}) noexcept //
53 : key_{std::move(k)}, source_{std::move(src)} {}
54
57 explicit key(std::string&& k, const source_region& src) noexcept //
58 : key_{std::move(k)}, source_{src} {}
59
62 explicit key(const char* k, source_region&& src = {}) //
63 : key_{k}, source_{std::move(src)} {}
64
67 explicit key(const char* k, const source_region& src) //
68 : key_{k}, source_{src} {}
69
70#if TOML_ENABLE_WINDOWS_COMPAT
71
77 explicit key(std::wstring_view k, source_region&& src = {}) //
78 : key_{impl::narrow(k)}, source_{std::move(src)} {}
79
85 explicit key(std::wstring_view k, const source_region& src) //
86 : key_{impl::narrow(k)}, source_{src} {}
87
88#endif
89
92
95 std::string_view str() const noexcept { return std::string_view{key_}; }
96
99 /*implicit*/ operator std::string_view() const noexcept { return str(); }
100
103 bool empty() const noexcept { return key_.empty(); }
104
107 const char* data() const noexcept { return key_.data(); }
108
111 size_t length() const noexcept { return key_.length(); }
112
114
117
120 const source_region& source() const noexcept { return source_; }
121
123
128
131 friend bool operator==(const key& lhs, const key& rhs) noexcept { return lhs.key_ == rhs.key_; }
132
135 friend bool operator!=(const key& lhs, const key& rhs) noexcept { return lhs.key_ != rhs.key_; }
136
139 friend bool operator<(const key& lhs, const key& rhs) noexcept { return lhs.key_ < rhs.key_; }
140
143 friend bool operator<=(const key& lhs, const key& rhs) noexcept { return lhs.key_ <= rhs.key_; }
144
147 friend bool operator>(const key& lhs, const key& rhs) noexcept { return lhs.key_ > rhs.key_; }
148
151 friend bool operator>=(const key& lhs, const key& rhs) noexcept { return lhs.key_ >= rhs.key_; }
152
155 friend bool operator==(const key& lhs, std::string_view rhs) noexcept {
156 return lhs.key_ == rhs;
157 }
158
161 friend bool operator!=(const key& lhs, std::string_view rhs) noexcept {
162 return lhs.key_ != rhs;
163 }
164
167 friend bool operator<(const key& lhs, std::string_view rhs) noexcept { return lhs.key_ < rhs; }
168
171 friend bool operator<=(const key& lhs, std::string_view rhs) noexcept {
172 return lhs.key_ <= rhs;
173 }
174
177 friend bool operator>(const key& lhs, std::string_view rhs) noexcept { return lhs.key_ > rhs; }
178
181 friend bool operator>=(const key& lhs, std::string_view rhs) noexcept {
182 return lhs.key_ >= rhs;
183 }
184
187 friend bool operator==(std::string_view lhs, const key& rhs) noexcept {
188 return lhs == rhs.key_;
189 }
190
193 friend bool operator!=(std::string_view lhs, const key& rhs) noexcept {
194 return lhs != rhs.key_;
195 }
196
199 friend bool operator<(std::string_view lhs, const key& rhs) noexcept { return lhs < rhs.key_; }
200
203 friend bool operator<=(std::string_view lhs, const key& rhs) noexcept {
204 return lhs <= rhs.key_;
205 }
206
209 friend bool operator>(std::string_view lhs, const key& rhs) noexcept { return lhs > rhs.key_; }
210
213 friend bool operator>=(std::string_view lhs, const key& rhs) noexcept {
214 return lhs >= rhs.key_;
215 }
216
218
221
223 using const_iterator = const char*;
224
226 using iterator = const_iterator;
227
230 const_iterator begin() const noexcept { return key_.data(); }
231
234 const_iterator end() const noexcept { return key_.data() + key_.length(); }
235
237
239 friend std::ostream& operator<<(std::ostream& lhs, const key& rhs) {
240 impl::print_to_stream(lhs, rhs.key_);
241 return lhs;
242 }
243 };
244
246 template <typename T>
247 inline constexpr bool is_key = std::is_same_v<impl::remove_cvref<T>, toml::key>;
248
251 template <typename T>
252 inline constexpr bool is_key_or_convertible =
253 is_key<T> //
254 || impl::is_constructible_or_convertible<toml::key, T>;
255}
257
258#include "header_end.hpp"
#define k
Definition 17.names.cpp:128
#define rhs
Definition 17.names.cpp:536
#define lhs
Definition 17.names.cpp:489
const char *const data[]
const int end
const char * str
Definition exec.cpp:170
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
bool operator>(const DistancePair &lhs, const DistancePair &rhs)
Definition graph.cpp:47
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14787
TOML_NAMESPACE_START
Definition key.hpp:12
constexpr bool is_key
Metafunction for determining if a type is, or is a reference to, a toml::key.
Definition key.hpp:247
constexpr bool is_key_or_convertible
Metafunction for determining if a type is, or is a reference to, a toml::key, or is implicitly or exp...
Definition key.hpp:252
TOML_NAMESPACE_END
Definition key.hpp:256
#define TOML_NODISCARD_CTOR
#define TOML_PURE_INLINE_GETTER
A source document region.