OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
PathResolver.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
46
47#ifndef OPENSWMM_ENGINE_PATH_RESOLVER_HPP
48#define OPENSWMM_ENGINE_PATH_RESOLVER_HPP
49
50#include <string>
51
52namespace openswmm::io {
53
54// ============================================================================
55// PathClass — outcome of a makeRelative() attempt
56// ============================================================================
57
74
75// ============================================================================
76// RelativeResult — full outcome of makeRelative()
77// ============================================================================
78
98
99// ============================================================================
100// Public API
101// ============================================================================
102
136RelativeResult makeRelative(const std::string& target_absolute,
137 const std::string& anchor_dir,
138 int max_up_levels = 16);
139
161std::string resolveRelative(const std::string& stored_token,
162 const std::string& anchor_dir);
163
176std::string normaliseSeparators(const std::string& path);
177
191std::string parentDir(const std::string& file_path);
192
193// ============================================================================
194// Test hooks — exposed for unit tests; not part of the supported API.
195// ============================================================================
196
205bool isAbsolutePath(const std::string& path) noexcept;
206
207} // namespace openswmm::io
208
209#endif // OPENSWMM_ENGINE_PATH_RESOLVER_HPP
Definition PathResolver.cpp:36
std::string resolveRelative(const std::string &stored_token, const std::string &anchor_dir)
Resolve a possibly-relative token against an anchor directory.
Definition PathResolver.cpp:206
PathClass
Classification of a makeRelative() result.
Definition PathResolver.hpp:66
@ Relative
Expressible relative to anchor; portable.
Definition PathResolver.hpp:67
@ Invalid
Empty or malformed input.
Definition PathResolver.hpp:72
@ AbsoluteSameVolume
Definition PathResolver.hpp:68
@ AbsoluteCrossVolume
Definition PathResolver.hpp:70
std::string normaliseSeparators(const std::string &path)
Convert all backslashes to forward-slashes; collapse ./ and duplicate slashes; drop trailing slash (e...
Definition PathResolver.cpp:173
bool isAbsolutePath(const std::string &path) noexcept
True iff path is absolute on the current platform.
Definition PathResolver.cpp:154
std::string parentDir(const std::string &file_path)
Parent directory portion of file_path, canonicalised for use as an anchor to makeRelative / resolveRe...
Definition PathResolver.cpp:185
RelativeResult makeRelative(const std::string &target_absolute, const std::string &anchor_dir, int max_up_levels)
Compute target_absolute expressed relative to anchor_dir.
Definition PathResolver.cpp:236
Outcome of computing target relative to anchor_dir.
Definition PathResolver.hpp:92
int up_levels
Definition PathResolver.hpp:95
PathClass classification
Definition PathResolver.hpp:94
std::string path
Definition PathResolver.hpp:93
std::string warning
Definition PathResolver.hpp:96