powerd++  0.4.4
Public Member Functions | Private Attributes | List of all members
sys::ctl::Sysctl< 0 > Class Reference

This is a specialisation of Sysctl for sysctls using symbolic names. More...

#include <sysctl.hpp>

Public Member Functions

constexpr Sysctl ()
 The default constructor. More...
 
 Sysctl (char const *const name)
 Initialise the MIB address from a character string. More...
 
size_t size () const
 The size of the sysctl. More...
 
void get (void *const buf, size_t const bufsize) const
 Update the given buffer with a value retrieved from the sysctl. More...
 
template<typename T >
void get (T &value) const
 Update the given value with a value retreived from the sysctl. More...
 
template<typename T >
std::unique_ptr< T[]> get () const
 Retrieve an array from the sysctl address. More...
 
void set (void const *const buf, size_t const bufsize)
 Update the the sysctl value with the given buffer. More...
 
template<typename T >
void set (T const &value)
 Update the the sysctl value with the given value. More...
 

Private Attributes

mib_t mib [CTL_MAXNAME]
 Stores the MIB address.
 
size_t depth
 The MIB depth.
 

Detailed Description

This is a specialisation of Sysctl for sysctls using symbolic names.

A Sysctl instance created with the default constructor is unitialised, initialisation can be deferred to a later moment by using copy assignment. This can be used to create globals but construct them inline where exceptions can be handled.

Constructor & Destructor Documentation

◆ Sysctl() [1/2]

constexpr sys::ctl::Sysctl< 0 >::Sysctl ( )
inlineconstexpr

The default constructor.

This is available to defer initialisation to a later moment.

◆ Sysctl() [2/2]

sys::ctl::Sysctl< 0 >::Sysctl ( char const *const  name)
inline

Initialise the MIB address from a character string.

Parameters
nameThe symbolic name of the sysctl
Exceptions
sys::sc_error<error>May throw an exception if the addressed sysct does not exist or if the address is too long to store

Member Function Documentation

◆ get() [1/3]

template<typename T >
std::unique_ptr<T[]> sys::ctl::Sysctl< 0 >::get ( ) const
inline

Retrieve an array from the sysctl address.

This is useful to retrieve variable length sysctls, like characer strings.

Template Parameters
TThe type stored in the array
Returns
And array of T with the right length to store the whole sysctl value
Exceptions
sys::sc_error<error>May throw if the size of the sysctl increases after the length was queried

◆ get() [2/3]

template<typename T >
void sys::ctl::Sysctl< 0 >::get ( T &  value) const
inline

Update the given value with a value retreived from the sysctl.

Template Parameters
TThe type store the sysctl value in
Parameters
valueA reference to the target value
Exceptions
sys::sc_error<error>Throws if value retrieval fails or is incomplete, e.g. because the value does not fit into the target type

◆ get() [3/3]

void sys::ctl::Sysctl< 0 >::get ( void *const  buf,
size_t const  bufsize 
) const
inline

Update the given buffer with a value retrieved from the sysctl.

Parameters
buf,bufsizeThe target buffer and its size
Exceptions
sys::sc_error<error>Throws if value retrieval fails or is incomplete, e.g. because the value does not fit into the target buffer

◆ set() [1/2]

template<typename T >
void sys::ctl::Sysctl< 0 >::set ( T const &  value)
inline

Update the the sysctl value with the given value.

Template Parameters
TThe value type
Parameters
valueThe value to set the sysctl to

◆ set() [2/2]

void sys::ctl::Sysctl< 0 >::set ( void const *const  buf,
size_t const  bufsize 
)
inline

Update the the sysctl value with the given buffer.

Parameters
buf,bufsizeThe source buffer
Exceptions
sys::sc_error<error>If the source buffer cannot be stored in the sysctl

◆ size()

size_t sys::ctl::Sysctl< 0 >::size ( ) const
inline

The size of the sysctl.

Returns
The size in characters

The documentation for this class was generated from the following file: