OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm::io Namespace Reference

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.
 

Enumeration Type Documentation

◆ PathClass

enum class openswmm::io::PathClass : int
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.

Enumerator
Relative 

Expressible relative to anchor; portable.

AbsoluteSameVolume 

Different sub-tree, same root/drive; not portable across folder layouts but still on the same volume.

AbsoluteCrossVolume 

Different drive / UNC / mount point; not portable across machines without identical mounts.

Invalid 

Empty or malformed input.

Function Documentation

◆ isAbsolutePath()

bool openswmm::io::isAbsolutePath ( const std::string & path)
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.

Here is the caller graph for this function:

◆ makeRelative()

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:

  • Invalid: either input is empty.
  • AbsoluteCrossVolume: the two paths have different root_name() (different Windows drive letter, different UNC share). The absolute target is returned unchanged (modulo separator normalisation).
  • AbsoluteSameVolume: the relative form would require more than max_up_levels .. segments, OR anchor_dir is empty (no anchor → return target as-is). The absolute target is returned.
  • Relative: the relative form is well-formed and within the depth cap.

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.

Parameters
target_absoluteThe path to express relatively. Must be absolute.
anchor_dirThe directory the relative form is anchored to. May be a file path; the parent directory is used.
max_up_levelsMaximum number of leading .. segments before falling back to absolute. Default 16.
Returns
RelativeResult with the path + classification + diagnostics.
Here is the call graph for this function:

◆ normaliseSeparators()

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.

Parameters
pathAny path-like string.
Returns
Same logical path with normalised separators.
Here is the caller graph for this function:

◆ parentDir()

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).

Parameters
file_pathPath to a file or directory.
Returns
Parent directory, or empty when none.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveRelative()

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:

  • Empty stored_token returns empty (no error).
  • Absolute stored_token (drive letter, leading /, UNC) is returned unchanged, separators normalised to the platform preferred form.
  • Relative 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().

Parameters
stored_tokenThe token as it appeared in the .inp file.
anchor_dirDirectory to resolve against (typically the .inp's parent directory).
Returns
Absolute path ready for filesystem operations, or empty.
Here is the call graph for this function:
Here is the caller graph for this function: