powerd++  0.4.4
Public Member Functions | Private Attributes | List of all members
sys::ctl::Once< T, SysctlT > Class Template Reference

A read once representation of a Sysctl. More...

#include <sysctl.hpp>

Public Member Functions

 Once (T const &value, SysctlT const &sysctl) noexcept
 The constructor tries to read and store the requested sysctl. More...
 
 operator T const & () const
 Return a const reference to the value. More...
 

Private Attributes

value
 The sysctl value read upon construction.
 

Detailed Description

template<typename T, class SysctlT>
class sys::ctl::Once< T, SysctlT >

A read once representation of a Sysctl.

This reads a sysctl once upon construction and always returns that value. It does not support assignment.

This class is intended for sysctls that are not expected to change, such as hw.ncpu. A special property of this class is that the constructor does not throw and takes a default value in case reading the sysctl fails.

// Read number of CPU cores, assume 1 on failure:
Once<coreid_t, Sysctl<2>> ncpu{1, {CTL_HW, HW_NCPU}};
// Equivalent:
int hw_ncpu;
try {
Sysctl<2>{CTL_HW, HW_NCPU}.get(hw_ncpu);
hw_ncpu = 1;
}
Template Parameters
TThe type to represent the sysctl as
SysctlTThe Sysctl type

Constructor & Destructor Documentation

◆ Once()

template<typename T , class SysctlT >
sys::ctl::Once< T, SysctlT >::Once ( T const &  value,
SysctlT const &  sysctl 
)
inlinenoexcept

The constructor tries to read and store the requested sysctl.

If reading the requested sysctl fails for any reason, the given value is stored instead.

Parameters
valueThe fallback value
sysctlThe sysctl to represent

Member Function Documentation

◆ operator T const &()

template<typename T , class SysctlT >
sys::ctl::Once< T, SysctlT >::operator T const & ( ) const
inline

Return a const reference to the value.

Returns
A const reference to the value

The documentation for this class was generated from the following file:
sys::sc_error
Can be thrown by syscall function wrappers if the function returned with an error.
Definition: error.hpp:26