NeBuild dev
Loading...
Searching...
No Matches
source_region.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 "std_optional.hpp"
8#include "std_string.hpp"
10#include "print_to_stream.hpp"
11#include "header_start.hpp"
12
14{
16 using source_index = uint32_t;
17
19 using source_path_ptr = std::shared_ptr<const std::string>;
20
43 {
46 source_index line;
47
50 source_index column;
51
54 explicit constexpr operator bool() const noexcept
55 {
56 return line > source_index{} //
57 && column > source_index{};
58 }
59
62 friend constexpr bool operator==(const source_position& lhs, const source_position& rhs) noexcept
63 {
64 return lhs.line == rhs.line //
65 && lhs.column == rhs.column;
66 }
67
70 friend constexpr bool operator!=(const source_position& lhs, const source_position& rhs) noexcept
71 {
72 return !(lhs == rhs);
73 }
74
75 private:
77
79 static constexpr uint64_t pack(const source_position& pos) noexcept
80 {
81 return static_cast<uint64_t>(pos.line) << 32 | static_cast<uint64_t>(pos.column);
82 }
83
85
86 public:
89 friend constexpr bool operator<(const source_position& lhs, const source_position& rhs) noexcept
90 {
91 return pack(lhs) < pack(rhs);
92 }
93
96 friend constexpr bool operator<=(const source_position& lhs, const source_position& rhs) noexcept
97 {
98 return pack(lhs) <= pack(rhs);
99 }
100
103 friend constexpr bool operator>(const source_position& lhs, const source_position& rhs) noexcept
104 {
105 return pack(lhs) > pack(rhs);
106 }
107
110 friend constexpr bool operator>=(const source_position& lhs, const source_position& rhs) noexcept
111 {
112 return pack(lhs) >= pack(rhs);
113 }
114
133 friend std::ostream& operator<<(std::ostream& lhs, const source_position& rhs)
134 {
135 impl::print_to_stream(lhs, rhs);
136 return lhs;
137 }
138 };
139
167 {
170
173
178
179#if TOML_ENABLE_WINDOWS_COMPAT
180
187 optional<std::wstring> wide_path() const
188 {
189 if (!path || path->empty())
190 return {};
191 return { impl::widen(*path) };
192 }
193
194#endif
195
214 friend std::ostream& operator<<(std::ostream& lhs, const source_region& rhs)
215 {
216 impl::print_to_stream(lhs, rhs);
217 return lhs;
218 }
219 };
220}
222
223#include "header_end.hpp"
A TOML path.
Definition path.hpp:239
TOML_PURE_INLINE_GETTER bool empty() const noexcept
Whether (true) or not (false) the path is empty.
Definition path.hpp:302
#define TOML_TRIVIAL_ABI
Definition preprocessor.hpp:430
#define TOML_NODISCARD
Definition preprocessor.hpp:439
#define TOML_PURE_GETTER
Definition preprocessor.hpp:474
#define TOML_PURE_INLINE_GETTER
Definition preprocessor.hpp:479
TOML_NAMESPACE_START
Definition source_region.hpp:14
std::shared_ptr< const std::string > source_path_ptr
A pointer to a shared string resource containing a source path.
Definition source_region.hpp:19
TOML_NAMESPACE_END
Definition source_region.hpp:221
A source document line-and-column pair.
Definition source_region.hpp:43
TOML_PURE_GETTER friend constexpr bool operator>=(const source_position &lhs, const source_position &rhs) noexcept
Greater-than-or-equal-to operator.
Definition source_region.hpp:110
TOML_PURE_INLINE_GETTER friend constexpr bool operator!=(const source_position &lhs, const source_position &rhs) noexcept
Inequality operator.
Definition source_region.hpp:70
source_index line
The line number.
Definition source_region.hpp:46
source_index column
The column number.
Definition source_region.hpp:50
TOML_PURE_GETTER friend constexpr bool operator==(const source_position &lhs, const source_position &rhs) noexcept
Equality operator.
Definition source_region.hpp:62
TOML_PURE_GETTER friend constexpr bool operator>(const source_position &lhs, const source_position &rhs) noexcept
Greater-than operator.
Definition source_region.hpp:103
TOML_PURE_GETTER friend constexpr bool operator<(const source_position &lhs, const source_position &rhs) noexcept
Less-than operator.
Definition source_region.hpp:89
TOML_PURE_GETTER friend constexpr bool operator<=(const source_position &lhs, const source_position &rhs) noexcept
Less-than-or-equal-to operator.
Definition source_region.hpp:96
friend std::ostream & operator<<(std::ostream &lhs, const source_position &rhs)
Prints a source_position to a stream.
Definition source_region.hpp:133
A source document region.
Definition source_region.hpp:167
source_path_ptr path
The path to the corresponding source document.
Definition source_region.hpp:177
friend std::ostream & operator<<(std::ostream &lhs, const source_region &rhs)
Prints a source_region to a stream.
Definition source_region.hpp:214
source_position end
The end of the region (exclusive).
Definition source_region.hpp:172
TOML_NODISCARD optional< std::wstring > wide_path() const
The path to the corresponding source document as a wide-string.
Definition source_region.hpp:187
source_position begin
The beginning of the region (inclusive).
Definition source_region.hpp:169