powerd++
0.4.4
|
A collection of functions to process command line arguments. More...
Functions | |
types::cptime_t | load (char const *const str) |
Convert string to load in the range [0, 1024]. More... | |
types::mhz_t | freq (char const *const str) |
Convert string to frequency in MHz. More... | |
types::ms | ival (char const *const str) |
Convert string to time interval in milliseconds. More... | |
size_t | samples (char const *const str) |
A string encoded number of samples. More... | |
types::decikelvin_t | temperature (char const *const str) |
Convert string to temperature in dK. More... | |
int | celsius (types::decikelvin_t const val) |
Converts dK into °C for display purposes. More... | |
template<typename T > | |
std::pair< T, T > | range (T(&func)(char const *const), char const *const str) |
Takes a string encoded range of values and returns them. More... | |
const char * | sysctlname (char const *const str) |
Verify that the given string only contains characters allowed in sysctl names. More... | |
template<typename ... CharTs> | |
const char * | formatfields (char const *const fmt, CharTs const ... fields) |
Sanitise user-provided formatting strings. More... | |
A collection of functions to process command line arguments.
|
inline |
Converts dK into °C for display purposes.
val | A temperature in dK |
const char* clas::formatfields | ( | char const *const | fmt, |
CharTs const ... | fields | ||
) |
Sanitise user-provided formatting strings.
Ensure that the given string contains no more than the given formatting fields in the given order.
This only passes plain data format fields, no flags, field width or precision are allowed.
errors::Exit::EFORMATFIELD | For unexpected formatting fields |
fmt | The formatting string to sanitise |
fields | A set of characters representing a printf-style formatting |
types::mhz_t clas::freq | ( | char const *const | str | ) |
Convert string to frequency in MHz.
The given string must have the following format:
freq = <float>, [ "hz" | "khz" | "mhz" | "ghz" | "thz" ];
For compatibility with powerd MHz are assumed, if no unit string is given.
The resulting frequency must be in the range [0Hz, 1THz].
str | A string encoded frequency |
types::ms clas::ival | ( | char const *const | str | ) |
Convert string to time interval in milliseconds.
The given string must have the following format:
ival = <float>, [ "s" | "ms" ];
For compatibility with powerd scalar values are assumed to represent milliseconds.
str | A string encoded time interval |
types::cptime_t clas::load | ( | char const *const | str | ) |
Convert string to load in the range [0, 1024].
The given string must have the following format:
load = <float>, [ "%" ];
The input value must be in the range [0.0, 1.0] or [0%, 100%].
str | A string encoded load |
[0,1024] | The load given by str |
> | 1024 The given string is not a load |
std::pair<T, T> clas::range | ( | T(&)(char const *const) | func, |
char const *const | str | ||
) |
Takes a string encoded range of values and returns them.
A range has the format from:to
.
T | The return type of the conversion function |
func | The function that converts the values from the string |
str | The string containing the range |
from
and to
values size_t clas::samples | ( | char const *const | str | ) |
A string encoded number of samples.
The string is expected to contain a scalar integer.
str | The string containing the number of samples |
const char * clas::sysctlname | ( | char const *const | str | ) |
Verify that the given string only contains characters allowed in sysctl names.
The currently permitted characters are: [0-9A-Za-z%._-]
errors::Exit::ESYSCTLNAME | For empty or invalid strings |
types::decikelvin_t clas::temperature | ( | char const *const | str | ) |
Convert string to temperature in dK.
The given string must have the following format:
temperature = <float>, [ "C" | "K" | "F" | "R" ];
In absence of a unit °C is assumed.
str | A string encoded temperature |