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
67 FilePathPair() = default;
68 FilePathPair(const FilePathPair&) = default;
69 FilePathPair(FilePathPair&&) noexcept = default;
70 FilePathPair& operator=(const FilePathPair&) = default;
71 FilePathPair& operator=(FilePathPair&&) noexcept = default;
72
73 // Implicit construction from a string token — assigns to `original`
74 // and leaves `absolute` empty. Mirrors legacy storage semantics so the
75 // mechanical migration touches only struct definitions.
76 FilePathPair(const std::string& s) : original(s) {} // NOLINT
77 FilePathPair(std::string&& s) noexcept : original(std::move(s)) {} // NOLINT
78 FilePathPair(const char* s) : original(s ? s : "") {} // NOLINT
79
80 // Assignment from string clears the cached absolute resolution because
81 // the original token just changed; the next read of `absolute` is the
82 // job of PostParseResolver or an explicit caller.
83 FilePathPair& operator=(const std::string& s) {
84 original = s;
85 absolute.clear();
86 return *this;
87 }
88 FilePathPair& operator=(std::string&& s) noexcept {
89 original = std::move(s);
90 absolute.clear();
91 return *this;
92 }
93 FilePathPair& operator=(const char* s) {
94 original.assign(s ? s : "");
95 absolute.clear();
96 return *this;
97 }
98
99 // Implicit conversion to const std::string& exposes the token to all
100 // existing readers (`fprintf`, comparisons, copies, etc.).
101 operator const std::string&() const noexcept { return original; } // NOLINT
102
103 // Common std::string-like introspection.
104 [[nodiscard]] bool empty() const noexcept { return original.empty(); }
105 [[nodiscard]] std::size_t size() const noexcept { return original.size(); }
106 [[nodiscard]] const char* c_str() const noexcept { return original.c_str(); }
107 [[nodiscard]] const std::string& str() const noexcept { return original; }
108
109 // Explicit comparison helpers — template matchers like gtest's EXPECT_EQ
110 // prefer direct ops over relying on implicit conversion.
111 friend bool operator==(const FilePathPair& a, const FilePathPair& b) {
112 return a.original == b.original;
113 }
114 friend bool operator!=(const FilePathPair& a, const FilePathPair& b) {
115 return !(a == b);
116 }
117 friend bool operator==(const FilePathPair& a, const std::string& s) {
118 return a.original == s;
119 }
120 friend bool operator==(const std::string& s, const FilePathPair& a) {
121 return s == a.original;
122 }
123 friend bool operator!=(const FilePathPair& a, const std::string& s) {
124 return !(a == s);
125 }
126 friend bool operator!=(const std::string& s, const FilePathPair& a) {
127 return !(s == a);
128 }
129 friend bool operator==(const FilePathPair& a, const char* s) {
130 return s ? (a.original == s) : a.original.empty();
131 }
132 friend bool operator==(const char* s, const FilePathPair& a) { return a == s; }
133 friend bool operator!=(const FilePathPair& a, const char* s) { return !(a == s); }
134 friend bool operator!=(const char* s, const FilePathPair& a) { return !(a == s); }
135};
136
137} // namespace openswmm
138
139#endif // OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
Definition NodeCoupling.cpp:16
friend bool operator!=(const FilePathPair &a, const char *s)
Definition FilePathPair.hpp:133
FilePathPair(FilePathPair &&) noexcept=default
std::size_t size() const noexcept
Definition FilePathPair.hpp:105
friend bool operator==(const FilePathPair &a, const char *s)
Definition FilePathPair.hpp:129
FilePathPair & operator=(const char *s)
Definition FilePathPair.hpp:93
const std::string & str() const noexcept
Definition FilePathPair.hpp:107
friend bool operator==(const std::string &s, const FilePathPair &a)
Definition FilePathPair.hpp:120
bool empty() const noexcept
Definition FilePathPair.hpp:104
std::string original
Definition FilePathPair.hpp:65
FilePathPair(const char *s)
Definition FilePathPair.hpp:78
const char * c_str() const noexcept
Definition FilePathPair.hpp:106
friend bool operator!=(const std::string &s, const FilePathPair &a)
Definition FilePathPair.hpp:126
FilePathPair(std::string &&s) noexcept
Definition FilePathPair.hpp:77
FilePathPair & operator=(const std::string &s)
Definition FilePathPair.hpp:83
friend bool operator!=(const FilePathPair &a, const std::string &s)
Definition FilePathPair.hpp:123
friend bool operator==(const FilePathPair &a, const FilePathPair &b)
Definition FilePathPair.hpp:111
std::string absolute
Definition FilePathPair.hpp:64
friend bool operator==(const char *s, const FilePathPair &a)
Definition FilePathPair.hpp:132
friend bool operator!=(const FilePathPair &a, const FilePathPair &b)
Definition FilePathPair.hpp:114
friend bool operator==(const FilePathPair &a, const std::string &s)
Definition FilePathPair.hpp:117
friend bool operator!=(const char *s, const FilePathPair &a)
Definition FilePathPair.hpp:134
FilePathPair & operator=(std::string &&s) noexcept
Definition FilePathPair.hpp:88
FilePathPair(const FilePathPair &)=default