powerd++  0.4.4
Functions
clas Namespace Reference

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

Detailed Description

A collection of functions to process command line arguments.

Function Documentation

◆ celsius()

int clas::celsius ( types::decikelvin_t const  val)
inline

Converts dK into °C for display purposes.

Parameters
valA temperature in dK
Returns
The temperature in °C

◆ formatfields()

template<typename ... CharTs>
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.

Exceptions
errors::Exit::EFORMATFIELDFor unexpected formatting fields
Parameters
fmtThe formatting string to sanitise
fieldsA set of characters representing a printf-style formatting
Returns
The given string

◆ freq()

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

Parameters
strA string encoded frequency
Returns
The frequency given by str

◆ ival()

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.

Parameters
strA string encoded time interval
Returns
The interval in milliseconds

◆ load()

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%].

Parameters
strA string encoded load
Return values
[0,1024]The load given by str
>1024 The given string is not a load

◆ range()

template<typename T >
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.

Template Parameters
TThe return type of the conversion function
Parameters
funcThe function that converts the values from the string
strThe string containing the range
Returns
A pair with the from and to values

◆ samples()

size_t clas::samples ( char const *const  str)

A string encoded number of samples.

The string is expected to contain a scalar integer.

Parameters
strThe string containing the number of samples
Returns
The number of samples

◆ sysctlname()

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%._-]

Exceptions
errors::Exit::ESYSCTLNAMEFor empty or invalid strings
Returns
The given string

◆ temperature()

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.

Parameters
strA string encoded temperature
Returns
The temperature given by str