OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
FilePathPair.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
34
35#ifndef OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
36#define OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
37
38#include <cstddef>
39#include <string>
40#include <utility>
41
42namespace openswmm {
43
64 std::string absolute;
65 std::string original;
66
70 FilePathPair() = default;
76 FilePathPair(const FilePathPair&) = default;
82 FilePathPair(FilePathPair&&) noexcept = default;
87 FilePathPair& operator=(const FilePathPair&) = default;
92 FilePathPair& operator=(FilePathPair&&) noexcept = default;
93
94 // Implicit construction from a string token — assigns to `original`
95 // and leaves `absolute` empty. Mirrors legacy storage semantics so the
96 // mechanical migration touches only struct definitions.
104 FilePathPair(const std::string& s) : original(s) {} // NOLINT
112 FilePathPair(std::string&& s) noexcept : original(std::move(s)) {} // NOLINT
120 FilePathPair(const char* s) : original(s ? s : "") {} // NOLINT
121
122 // Assignment from string clears the cached absolute resolution because
123 // the original token just changed; the next read of `absolute` is the
124 // job of PostParseResolver or an explicit caller.
133 FilePathPair& operator=(const std::string& s) {
134 original = s;
135 absolute.clear();
136 return *this;
137 }
138
146 FilePathPair& operator=(std::string&& s) noexcept {
147 original = std::move(s);
148 absolute.clear();
149 return *this;
150 }
151
159 FilePathPair& operator=(const char* s) {
160 original.assign(s ? s : "");
161 absolute.clear();
162 return *this;
163 }
164
165 // Implicit conversion to const std::string& exposes the token to all
166 // existing readers (`fprintf`, comparisons, copies, etc.).
171 operator const std::string&() const noexcept { return original; } // NOLINT
172
173 // Common std::string-like introspection.
178 [[nodiscard]] bool empty() const noexcept { return original.empty(); }
183 [[nodiscard]] std::size_t size() const noexcept { return original.size(); }
188 [[nodiscard]] const char* c_str() const noexcept { return original.c_str(); }
193 [[nodiscard]] const std::string& str() const noexcept { return original; }
194
195 // Explicit comparison helpers — template matchers like gtest's EXPECT_EQ
196 // prefer direct ops over relying on implicit conversion.
206 friend bool operator==(const FilePathPair& a, const FilePathPair& b) {
207 return a.original == b.original;
208 }
209
218 friend bool operator!=(const FilePathPair& a, const FilePathPair& b) { return !(a == b); }
228 friend bool operator==(const FilePathPair& a, const std::string& s) { return a.original == s; }
238 friend bool operator==(const std::string& s, const FilePathPair& a) { return s == a.original; }
248 friend bool operator!=(const FilePathPair& a, const std::string& s) { return !(a == s); }
258 friend bool operator!=(const std::string& s, const FilePathPair& a) { return !(s == a); }
268 friend bool operator==(const FilePathPair& a, const char* s) {
269 return s ? (a.original == s) : a.original.empty();
270 }
271
280 friend bool operator==(const char* s, const FilePathPair& a) { return a == s; }
290 friend bool operator!=(const FilePathPair& a, const char* s) { return !(a == s); }
300 friend bool operator!=(const char* s, const FilePathPair& a) { return !(a == s); }
301};
302
303} // namespace openswmm
304
305#endif // OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
Definition ExchangeLaw.hpp:60
friend bool operator!=(const FilePathPair &a, const char *s)
Compare authored tokens for exact-byte inequality.
Definition FilePathPair.hpp:290
FilePathPair(FilePathPair &&) noexcept=default
Move the authored token and resolved cache from another pair.
std::size_t size() const noexcept
Count bytes in the authored token.
Definition FilePathPair.hpp:183
friend bool operator==(const FilePathPair &a, const char *s)
Compare authored tokens for exact-byte equality.
Definition FilePathPair.hpp:268
FilePathPair & operator=(const char *s)
Copy a new authored token and clear cached absolute resolution.
Definition FilePathPair.hpp:159
const std::string & str() const noexcept
Borrow the complete authored token.
Definition FilePathPair.hpp:193
friend bool operator==(const std::string &s, const FilePathPair &a)
Compare authored tokens for exact-byte equality.
Definition FilePathPair.hpp:238
bool empty() const noexcept
Test whether the authored token is empty.
Definition FilePathPair.hpp:178
std::string original
Definition FilePathPair.hpp:65
FilePathPair(const char *s)
Copy a token into original and leave the resolved cache empty.
Definition FilePathPair.hpp:120
const char * c_str() const noexcept
Borrow a NUL-terminated view of the authored token.
Definition FilePathPair.hpp:188
friend bool operator!=(const std::string &s, const FilePathPair &a)
Compare authored tokens for exact-byte inequality.
Definition FilePathPair.hpp:258
FilePathPair(std::string &&s) noexcept
Move a token into original and leave the resolved cache empty.
Definition FilePathPair.hpp:112
FilePathPair & operator=(const std::string &s)
Copy a new authored token and clear cached absolute resolution.
Definition FilePathPair.hpp:133
friend bool operator!=(const FilePathPair &a, const std::string &s)
Compare authored tokens for exact-byte inequality.
Definition FilePathPair.hpp:248
friend bool operator==(const FilePathPair &a, const FilePathPair &b)
Compare authored tokens for exact-byte equality.
Definition FilePathPair.hpp:206
std::string absolute
Definition FilePathPair.hpp:64
friend bool operator==(const char *s, const FilePathPair &a)
Compare authored tokens for exact-byte equality.
Definition FilePathPair.hpp:280
friend bool operator!=(const FilePathPair &a, const FilePathPair &b)
Compare authored tokens for exact-byte inequality.
Definition FilePathPair.hpp:218
friend bool operator==(const FilePathPair &a, const std::string &s)
Compare authored tokens for exact-byte equality.
Definition FilePathPair.hpp:228
friend bool operator!=(const char *s, const FilePathPair &a)
Compare authored tokens for exact-byte inequality.
Definition FilePathPair.hpp:300
FilePathPair & operator=(std::string &&s) noexcept
Move a new authored token and clear cached absolute resolution.
Definition FilePathPair.hpp:146
FilePathPair()=default
Create an empty authored token and empty resolved-path cache.
FilePathPair(const FilePathPair &)=default
Copy the authored token and resolved absolute cache from another pair.