OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::FileNames

The SDK's own file-naming rule: the same functions its alarm actions and time-lapses use. Added in 12.0.35.

The placeholders are {rule}, {region}, {serial}, {model}, {sequence}, {timestamp} (the local date and time as YYYYmmdd_HHMMSS, read when the name is made) and {timestamp_us}. Each value goes in once and is not read again, so a rule named {timestamp} is named that; {{ and }} write a literal brace, and a name in braces that is none of these is written as it stands.

Public static functions

Sanitize

static auto Sanitize(const std::string &text, const std::string &fallback={}) -> std::string

text as one part of a file name: a slash, a backslash, a colon, *, ?, ", <, >, |, a control character and a space each become _.

Parameters

Name Description
text What to clean, UTF-8.
fallback What to return when text is empty.

Returns: The cleaned text, or fallback.

Expand

static auto Expand(const std::string &pattern, const FileNameContext &context, const std::string &fallback={}) -> std::string

pattern with its placeholders filled in from context, then cleaned as Sanitize() cleans. Each value is cleaned on its own first, so a rule named ../../etc cannot walk out of a directory.

optris::sdk::FileNameContext context;
context.rule = "over temp";
context.sequence = 7;
// "over_temp_000007"
auto stem = optris::sdk::FileNames::Expand("{rule}_{sequence}",
                                           context);

Parameters

Name Description
pattern The pattern, UTF-8, without a directory or an extension.
context The values.
fallback What to return when nothing is left; the SDK's alarm actions use "alarm".

Returns: The file name's stem.

Unique

static auto Unique(const std::string &directory, const std::string &stem, const std::string &extension) -> std::string

directory/stem + extension, or, when that exists, the first of stem-1, stem-2 ... up to stem-9999 that does not. Nothing is created, so two programs asking at once can be told the same name.

Parameters

Name Description
directory The directory, UTF-8; empty means the current one.
stem The name without its extension, for example from Expand().
extension The extension with its dot, for example ".png".

Returns: The path, UTF-8.

Public functions

FileNames

FileNames()=delete