OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
FilePathPair.hpp
Go to the documentation of this file.
1
18
19#ifndef OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
20#define OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
21
22#include <cstddef>
23#include <string>
24#include <utility>
25
26namespace openswmm {
27
48 std::string absolute;
49 std::string original;
50
51 FilePathPair() = default;
52 FilePathPair(const FilePathPair&) = default;
53 FilePathPair(FilePathPair&&) noexcept = default;
54 FilePathPair& operator=(const FilePathPair&) = default;
55 FilePathPair& operator=(FilePathPair&&) noexcept = default;
56
57 // Implicit construction from a string token — assigns to `original`
58 // and leaves `absolute` empty. Mirrors legacy storage semantics so the
59 // mechanical migration touches only struct definitions.
60 FilePathPair(const std::string& s) : original(s) {} // NOLINT
61 FilePathPair(std::string&& s) noexcept : original(std::move(s)) {} // NOLINT
62 FilePathPair(const char* s) : original(s ? s : "") {} // NOLINT
63
64 // Assignment from string clears the cached absolute resolution because
65 // the original token just changed; the next read of `absolute` is the
66 // job of PostParseResolver or an explicit caller.
67 FilePathPair& operator=(const std::string& s) {
68 original = s;
69 absolute.clear();
70 return *this;
71 }
72 FilePathPair& operator=(std::string&& s) noexcept {
73 original = std::move(s);
74 absolute.clear();
75 return *this;
76 }
77 FilePathPair& operator=(const char* s) {
78 original.assign(s ? s : "");
79 absolute.clear();
80 return *this;
81 }
82
83 // Implicit conversion to const std::string& exposes the token to all
84 // existing readers (`fprintf`, comparisons, copies, etc.).
85 operator const std::string&() const noexcept { return original; } // NOLINT
86
87 // Common std::string-like introspection.
88 [[nodiscard]] bool empty() const noexcept { return original.empty(); }
89 [[nodiscard]] std::size_t size() const noexcept { return original.size(); }
90 [[nodiscard]] const char* c_str() const noexcept { return original.c_str(); }
91 [[nodiscard]] const std::string& str() const noexcept { return original; }
92
93 // Explicit comparison helpers — template matchers like gtest's EXPECT_EQ
94 // prefer direct ops over relying on implicit conversion.
95 friend bool operator==(const FilePathPair& a, const FilePathPair& b) {
96 return a.original == b.original;
97 }
98 friend bool operator!=(const FilePathPair& a, const FilePathPair& b) {
99 return !(a == b);
100 }
101 friend bool operator==(const FilePathPair& a, const std::string& s) {
102 return a.original == s;
103 }
104 friend bool operator==(const std::string& s, const FilePathPair& a) {
105 return s == a.original;
106 }
107 friend bool operator!=(const FilePathPair& a, const std::string& s) {
108 return !(a == s);
109 }
110 friend bool operator!=(const std::string& s, const FilePathPair& a) {
111 return !(s == a);
112 }
113 friend bool operator==(const FilePathPair& a, const char* s) {
114 return s ? (a.original == s) : a.original.empty();
115 }
116 friend bool operator==(const char* s, const FilePathPair& a) { return a == s; }
117 friend bool operator!=(const FilePathPair& a, const char* s) { return !(a == s); }
118 friend bool operator!=(const char* s, const FilePathPair& a) { return !(a == s); }
119};
120
121} // namespace openswmm
122
123#endif // OPENSWMM_ENGINE_FILE_PATH_PAIR_HPP
Definition NodeCoupling.cpp:15
friend bool operator!=(const FilePathPair &a, const char *s)
Definition FilePathPair.hpp:117
FilePathPair(FilePathPair &&) noexcept=default
std::size_t size() const noexcept
Definition FilePathPair.hpp:89
friend bool operator==(const FilePathPair &a, const char *s)
Definition FilePathPair.hpp:113
FilePathPair & operator=(const char *s)
Definition FilePathPair.hpp:77
const std::string & str() const noexcept
Definition FilePathPair.hpp:91
friend bool operator==(const std::string &s, const FilePathPair &a)
Definition FilePathPair.hpp:104
bool empty() const noexcept
Definition FilePathPair.hpp:88
std::string original
Definition FilePathPair.hpp:49
FilePathPair(const char *s)
Definition FilePathPair.hpp:62
const char * c_str() const noexcept
Definition FilePathPair.hpp:90
friend bool operator!=(const std::string &s, const FilePathPair &a)
Definition FilePathPair.hpp:110
FilePathPair(std::string &&s) noexcept
Definition FilePathPair.hpp:61
FilePathPair & operator=(const std::string &s)
Definition FilePathPair.hpp:67
friend bool operator!=(const FilePathPair &a, const std::string &s)
Definition FilePathPair.hpp:107
friend bool operator==(const FilePathPair &a, const FilePathPair &b)
Definition FilePathPair.hpp:95
std::string absolute
Definition FilePathPair.hpp:48
friend bool operator==(const char *s, const FilePathPair &a)
Definition FilePathPair.hpp:116
friend bool operator!=(const FilePathPair &a, const FilePathPair &b)
Definition FilePathPair.hpp:98
friend bool operator==(const FilePathPair &a, const std::string &s)
Definition FilePathPair.hpp:101
friend bool operator!=(const char *s, const FilePathPair &a)
Definition FilePathPair.hpp:118
FilePathPair & operator=(std::string &&s) noexcept
Definition FilePathPair.hpp:72
FilePathPair(const FilePathPair &)=default