![]() |
OpenSWMM Engine
6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
|
Classes | |
| struct | RelativeResult |
Outcome of computing target relative to anchor_dir. More... | |
Enumerations | |
| enum class | PathClass : int { Relative = 0 , AbsoluteSameVolume = 1 , AbsoluteCrossVolume = 2 , Invalid = 3 } |
| Classification of a makeRelative() result. More... | |
Functions | |
| bool | isAbsolutePath (const std::string &path) noexcept |
True iff path is absolute on the current platform. | |
| std::string | normaliseSeparators (const std::string &path) |
Convert all backslashes to forward-slashes; collapse ./ and duplicate slashes; drop trailing slash (except for filesystem roots like / or C:/). | |
| std::string | parentDir (const std::string &file_path) |
Parent directory portion of file_path, canonicalised for use as an anchor to makeRelative / resolveRelative. | |
| std::string | resolveRelative (const std::string &stored_token, const std::string &anchor_dir) |
| Resolve a possibly-relative token against an anchor directory. | |
| RelativeResult | makeRelative (const std::string &target_absolute, const std::string &anchor_dir, int max_up_levels=16) |
Compute target_absolute expressed relative to anchor_dir. | |
|
strong |
Classification of a makeRelative() result.
Callers use this to decide whether the produced string is usable as a portable token in a .inp file. Only Relative is portable; the absolute variants are returned when the relative form would be invalid or worse than the absolute one.
|
noexcept |
True iff path is absolute on the current platform.
Treats \\server\share\… (UNC) and C:\… (Windows drive) as absolute even on POSIX builds — the legacy .inp format may carry such tokens regardless of the platform the engine runs on.
| RelativeResult openswmm::io::makeRelative | ( | const std::string & | target_absolute, |
| const std::string & | anchor_dir, | ||
| int | max_up_levels = 16 ) |
Compute target_absolute expressed relative to anchor_dir.
Uses std::filesystem::path::lexically_proximate rather than relative so symlinks are preserved and missing files do not throw. The output path always uses forward-slash separators regardless of platform.
Classification rules:
root_name() (different Windows drive letter, different UNC share). The absolute target is returned unchanged (modulo separator normalisation).max_up_levels .. segments, OR anchor_dir is empty (no anchor → return target as-is). The absolute target is returned.The depth cap defends against pathological cases like a .inp at /Users/alice/... referencing /etc/swmm/data/ — the relative form ../../../../../../etc/swmm/data/ is technically valid but unreadable.
| target_absolute | The path to express relatively. Must be absolute. |
| anchor_dir | The directory the relative form is anchored to. May be a file path; the parent directory is used. |
| max_up_levels | Maximum number of leading .. segments before falling back to absolute. Default 16. |
| std::string openswmm::io::normaliseSeparators | ( | const std::string & | path | ) |
Convert all backslashes to forward-slashes; collapse ./ and duplicate slashes; drop trailing slash (except for filesystem roots like / or C:/).
Idempotent. Does not touch .. segments (use makeRelative for full lexical normalisation). Used by the InpWriter when emitting path tokens so the .inp file is platform-portable.
| path | Any path-like string. |
| std::string openswmm::io::parentDir | ( | const std::string & | file_path | ) |
Parent directory portion of file_path, canonicalised for use as an anchor to makeRelative / resolveRelative.
Returns the directory portion in the platform's preferred form, without trailing separator. If file_path has no parent (it's a single filename), returns empty. If file_path is itself a directory path, returns it unchanged (modulo trailing slash removal).
| file_path | Path to a file or directory. |
| std::string openswmm::io::resolveRelative | ( | const std::string & | stored_token, |
| const std::string & | anchor_dir ) |
Resolve a possibly-relative token against an anchor directory.
Mirrors the legacy addAbsolutePath() semantics:
stored_token returns empty (no error).stored_token (drive letter, leading /, UNC) is returned unchanged, separators normalised to the platform preferred form.stored_token is joined onto anchor_dir and normalised. If anchor_dir is empty, the token is returned unchanged (caller's responsibility to provide an anchor when relative tokens are expected).Accepts both / and \ separators on input. Returns a path in the platform's preferred form for direct use with fopen().
| stored_token | The token as it appeared in the .inp file. |
| anchor_dir | Directory to resolve against (typically the .inp's parent directory). |