OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches

Pure-function path normalisation and relative-path math. More...

#include <string>
Include dependency graph for PathResolver.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  openswmm::io::RelativeResult
 Outcome of computing target relative to anchor_dir. More...
 

Namespaces

namespace  openswmm
 
namespace  openswmm::io
 

Enumerations

enum class  openswmm::io::PathClass : int {
  openswmm::io::Relative = 0 ,
  openswmm::io::AbsoluteSameVolume = 1 ,
  openswmm::io::AbsoluteCrossVolume = 2 ,
  openswmm::io::Invalid = 3
}
 Classification of a makeRelative() result. More...
 

Functions

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.
 
std::string openswmm::io::resolveRelative (const std::string &stored_token, const std::string &anchor_dir)
 Resolve a possibly-relative token against an anchor directory.
 
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:/).
 
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.
 
bool openswmm::io::isAbsolutePath (const std::string &path) noexcept
 True iff path is absolute on the current platform.
 

Detailed Description

Pure-function path normalisation and relative-path math.

Foundation of the IO portability work (see openswmm.gui/docs/IO_PORTABILITY_PLAN.md §3.1). Three jobs:

  1. Compute target expressed relative to an anchor directory, classifying the result so callers can fall back to absolute when relative is impossible (cross-volume, UNC, beyond depth cap).
  2. Resolve a stored token (relative or absolute) against an anchor directory, mirroring the legacy addAbsolutePath() semantics in src/legacy/engine/swmm5.c:2820.
  3. Normalise separators to forward-slash on write while accepting both / and \ on read — the SWMM .inp text format is platform-neutral, the in-memory representation is platform-native.

All functions are pure, allocation-only, and thread-safe. They use std::filesystem::path for parsing but never throw on missing files (no canonical() calls).

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License\n MIT License