Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
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
8#include "header_start.hpp"
9#include "print_to_stream.hpp"
10#include "std_optional.hpp"
11#include "std_string.hpp"
12
15 using source_index = uint32_t;
16
18 using source_path_ptr = std::shared_ptr<const std::string>;
19
44 source_index line;
45
48 source_index column;
49
52 explicit constexpr operator bool() const noexcept {
53 return line > source_index{} //
54 && column > source_index{};
55 }
56
59 friend constexpr bool operator==(const source_position& lhs,
60 const source_position& rhs) noexcept {
61 return lhs.line == rhs.line //
62 && lhs.column == rhs.column;
63 }
64
67 friend constexpr bool operator!=(const source_position& lhs,
68 const source_position& rhs) noexcept {
69 return !(lhs == rhs);
70 }
71
72 private:
74
76 static constexpr uint64_t pack(const source_position& pos) noexcept {
77 return static_cast<uint64_t>(pos.line) << 32 | static_cast<uint64_t>(pos.column);
78 }
79
81
82 public:
85 friend constexpr bool operator<(const source_position& lhs,
86 const source_position& rhs) noexcept {
87 return pack(lhs) < pack(rhs);
88 }
89
92 friend constexpr bool operator<=(const source_position& lhs,
93 const source_position& rhs) noexcept {
94 return pack(lhs) <= pack(rhs);
95 }
96
99 friend constexpr bool operator>(const source_position& lhs,
100 const source_position& rhs) noexcept {
101 return pack(lhs) > pack(rhs);
102 }
103
106 friend constexpr bool operator>=(const source_position& lhs,
107 const source_position& rhs) noexcept {
108 return pack(lhs) >= pack(rhs);
109 }
110
129 friend std::ostream& operator<<(std::ostream& lhs, const source_position& rhs) {
130 impl::print_to_stream(lhs, rhs);
131 return lhs;
132 }
133 };
134
164
167
172
173#if TOML_ENABLE_WINDOWS_COMPAT
174
181 optional<std::wstring> wide_path() const {
182 if (!path || path->empty()) return {};
183 return {impl::widen(*path)};
184 }
185
186#endif
187
206 friend std::ostream& operator<<(std::ostream& lhs, const source_region& rhs) {
207 impl::print_to_stream(lhs, rhs);
208 return lhs;
209 }
210 };
211}
213
214#include "header_end.hpp"
#define rhs
Definition 17.names.cpp:536
#define line
Definition 17.names.cpp:490
#define lhs
Definition 17.names.cpp:489
#define pos
Definition 17.names.cpp:518
A TOML path.
Definition path.hpp:209
TOML_PURE_INLINE_GETTER bool empty() const noexcept
Whether (true) or not (false) the path is empty.
Definition path.hpp:267
#define TOML_TRIVIAL_ABI
#define TOML_NODISCARD
#define TOML_PURE_GETTER
#define TOML_PURE_INLINE_GETTER
TOML_NAMESPACE_START
std::shared_ptr< const std::string > source_path_ptr
A pointer to a shared string resource containing a source path.
TOML_NAMESPACE_END
#define bool
Definition stdbool.h:24
A source document line-and-column pair.
TOML_PURE_GETTER friend constexpr bool operator>=(const source_position &lhs, const source_position &rhs) noexcept
Greater-than-or-equal-to operator.
TOML_PURE_INLINE_GETTER friend constexpr bool operator!=(const source_position &lhs, const source_position &rhs) noexcept
Inequality operator.
source_index line
The line number.
source_index column
The column number.
TOML_PURE_GETTER friend constexpr bool operator==(const source_position &lhs, const source_position &rhs) noexcept
Equality operator.
TOML_PURE_GETTER friend constexpr bool operator>(const source_position &lhs, const source_position &rhs) noexcept
Greater-than operator.
TOML_PURE_GETTER friend constexpr bool operator<(const source_position &lhs, const source_position &rhs) noexcept
Less-than operator.
TOML_PURE_GETTER friend constexpr bool operator<=(const source_position &lhs, const source_position &rhs) noexcept
Less-than-or-equal-to operator.
friend std::ostream & operator<<(std::ostream &lhs, const source_position &rhs)
Prints a source_position to a stream.
A source document region.
source_path_ptr path
The path to the corresponding source document.
friend std::ostream & operator<<(std::ostream &lhs, const source_region &rhs)
Prints a source_region to a stream.
source_position end
The end of the region (exclusive).
TOML_NODISCARD optional< std::wstring > wide_path() const
The path to the corresponding source document as a wide-string.
source_position begin
The beginning of the region (inclusive).