cxxitimer 2.0.5
A C++ library to handle linux interval timer
Loading...
Searching...
No Matches
cxxitimer::ITimer_Virtual Class Reference

class ITimer_Virtual More...

#include <cxxitimer.hpp>

Inheritance diagram for cxxitimer::ITimer_Virtual:
Collaboration diagram for cxxitimer::ITimer_Virtual:

Public Member Functions

 ITimer_Virtual (const timeval &interval={.tv_sec=1,.tv_usec=0})
 create ITimer_Virtual instance
 
 ITimer_Virtual (const timeval &interval, const timeval &value)
 create ITimer_Virtual instance
 
 ITimer_Virtual (double interval)
 create ITimer_Virtual instance
 
 ITimer_Virtual (double interval, double value)
 create ITimer_Virtual instance
 
 ~ITimer_Virtual () override
 
 ITimer_Virtual (const ITimer_Virtual &other)=delete
 
 ITimer_Virtual (ITimer_Virtual &&other)=delete
 
ITimer_Virtualoperator= (const ITimer_Virtual &other)=delete
 
ITimer_Virtualoperator= (ITimer_Virtual &&other)=delete
 
void start ()
 start timer
 
void stop ()
 stop timer
 
void set_speed_factor (double factor)
 set speed factor
 
void set_interval (const timeval &interval)
 set interval (timeval)
 
void set_interval (double interval)
 set interval (double)
 
void set_interval_value (const timeval &interval, const timeval &value)
 set interval and value
 
void set_interval_value (double interval, double value)
 set interval and value
 
void set_speed_to_normal ()
 set speed to normal
 
void to_fstream (std::ofstream &fstream) const
 write to binary file stream
 
void from_fstream (std::ifstream &fstream)
 read from binary filestream
 
timeval get_timer_value () const
 get timer value
 
bool is_running () const noexcept
 check if timer is running
 

Private Member Functions

virtual void adjust_speed (double new_factor)
 

Private Attributes

timeval timer_value
 
timeval timer_interval
 
int type
 
double speed_factor
 speed adjustment factor
 
bool running
 

Static Private Attributes

static bool instance_exists = false
 

Detailed Description

class ITimer_Virtual

"This timer counts down against the user-mode CPU time consumed by the process. (The measurement includes CPU time consumed by all threads in the process.) At each expiration, a SIGVTALRM signal is generated." (man getitimer)

Definition at line 243 of file cxxitimer.hpp.

Constructor & Destructor Documentation

◆ ITimer_Virtual() [1/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( const timeval &  interval = {.tv_sec = 1, .tv_usec = 0})
explicit

create ITimer_Virtual instance

only one instance is allowed

Parameters
intervaltimer interval
Exceptions
std::logic_errorinstance exists

Definition at line 228 of file cxxitimer.cpp.

References instance_exists, and cxxitimer::ITimer::ITimer().

Here is the call graph for this function:

◆ ITimer_Virtual() [2/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( const timeval &  interval,
const timeval &  value 
)

create ITimer_Virtual instance

only one instance is allowed

Parameters
intervalinterval at which the timer is triggered
valueime period after which the timer expires for the first time
Exceptions
std::logic_errorinstance exists

Definition at line 234 of file cxxitimer.cpp.

References instance_exists, and cxxitimer::ITimer::ITimer().

Here is the call graph for this function:

◆ ITimer_Virtual() [3/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( double  interval)
explicit

create ITimer_Virtual instance

only one instance is allowed

Parameters
intervaltimer interval
Exceptions
std::logic_errorinstance exists

Definition at line 241 of file cxxitimer.cpp.

References instance_exists, and cxxitimer::ITimer::ITimer().

Here is the call graph for this function:

◆ ITimer_Virtual() [4/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( double  interval,
double  value 
)

create ITimer_Virtual instance

only one instance is allowed

Parameters
intervalinterval at which the timer is triggered
valueime period after which the timer expires for the first time
Exceptions
std::logic_errorinstance exists

Definition at line 247 of file cxxitimer.cpp.

References instance_exists, and cxxitimer::ITimer::ITimer().

Here is the call graph for this function:

◆ ~ITimer_Virtual()

cxxitimer::ITimer_Virtual::~ITimer_Virtual ( )
override

Definition at line 253 of file cxxitimer.cpp.

References instance_exists.

◆ ITimer_Virtual() [5/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( const ITimer_Virtual other)
delete

◆ ITimer_Virtual() [6/6]

cxxitimer::ITimer_Virtual::ITimer_Virtual ( ITimer_Virtual &&  other)
delete

Member Function Documentation

◆ adjust_speed()

void cxxitimer::ITimer::adjust_speed ( double  new_factor)
privatevirtualinherited

Definition at line 71 of file cxxitimer.cpp.

References cxxitimer::operator*=(), cxxitimer::operator/(), cxxitimer::ITimer::running, cxxitimer::ITimer::speed_factor, cxxitimer::STOP_TIMER, cxxitimer::ITimer::timer_interval, and cxxitimer::ITimer::type.

Referenced by cxxitimer::ITimer::set_speed_factor(), and cxxitimer::ITimer::set_speed_to_normal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_fstream()

void cxxitimer::ITimer::from_fstream ( std::ifstream &  fstream)
inherited

read from binary filestream

Parameters
fstreamfile stream to read from
Exceptions
std::logic_errortimer is running

Definition at line 180 of file cxxitimer.cpp.

References cxxitimer::ITimer::running, cxxitimer::ITimer::timer_interval, and cxxitimer::ITimer::timer_value.

◆ get_timer_value()

timeval cxxitimer::ITimer::get_timer_value ( ) const
inherited

get timer value

returns the stored timer value if the timer is stopped or the actual timer value if running

Returns
timer value

Definition at line 189 of file cxxitimer.cpp.

References cxxitimer::operator*(), cxxitimer::ITimer::running, cxxitimer::ITimer::speed_factor, cxxitimer::ITimer::timer_value, and cxxitimer::ITimer::type.

Here is the call graph for this function:

◆ is_running()

bool cxxitimer::ITimer::is_running ( ) const
inlinenoexceptinherited

check if timer is running

Returns
true timer is running
false timer is stopped

Definition at line 175 of file cxxitimer.hpp.

References cxxitimer::ITimer::running.

◆ operator=() [1/2]

ITimer_Virtual & cxxitimer::ITimer_Virtual::operator= ( const ITimer_Virtual other)
delete

◆ operator=() [2/2]

ITimer_Virtual & cxxitimer::ITimer_Virtual::operator= ( ITimer_Virtual &&  other)
delete

◆ set_interval() [1/2]

void cxxitimer::ITimer::set_interval ( const timeval &  interval)
inlineinherited

set interval (timeval)

only allowed if the timer is stopped! set the timer value to the same time

Parameters
intervaltimer interval
Exceptions
std::logic_errortimer is started

Definition at line 109 of file cxxitimer.hpp.

References cxxitimer::ITimer::set_interval_value().

Here is the call graph for this function:

◆ set_interval() [2/2]

void cxxitimer::ITimer::set_interval ( double  interval)
inlineinherited

set interval (double)

only allowed if the timer is stopped! set the timer value to the same time

Parameters
intervaltimer interval (seconds)
Exceptions
std::logic_errortimer is started

Definition at line 119 of file cxxitimer.hpp.

References cxxitimer::ITimer::set_interval_value().

Here is the call graph for this function:

◆ set_interval_value() [1/2]

void cxxitimer::ITimer::set_interval_value ( const timeval &  interval,
const timeval &  value 
)
inherited

set interval and value

only allowed if the timer is stopped

Parameters
intervaltimer interval
valuetimer value
Exceptions
std::logic_errortimer is started

Definition at line 146 of file cxxitimer.cpp.

References cxxitimer::ITimer::running, cxxitimer::ITimer::timer_interval, and cxxitimer::ITimer::timer_value.

Referenced by cxxitimer::ITimer::set_interval(), and cxxitimer::ITimer::set_interval_value().

Here is the caller graph for this function:

◆ set_interval_value() [2/2]

void cxxitimer::ITimer::set_interval_value ( double  interval,
double  value 
)
inherited

set interval and value

only allowed if the timer is stopped

Parameters
intervaltimer interval (seconds)
valuetimer value (seconds)
Exceptions
std::logic_errortimer is started

Definition at line 153 of file cxxitimer.cpp.

References cxxitimer::double_to_timeval(), and cxxitimer::ITimer::set_interval_value().

Referenced by cxxitimer::ITimer::set_interval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_speed_factor()

void cxxitimer::ITimer::set_speed_factor ( double  factor)
inherited

set speed factor

is applied directly, even if the timer is running

  • ]0;1[ --> slower
  • ]1;inf[ --> faster
  • 1 --> normal speed
    Parameters
    factorspeed factor
    Exceptions
    std::invalid_argumentnegative values or nan/inf
    std::system_errorcall of setitimer failed

Definition at line 135 of file cxxitimer.cpp.

References cxxitimer::ITimer::adjust_speed(), cxxitimer::ITimer::running, and cxxitimer::ITimer::speed_factor.

Here is the call graph for this function:

◆ set_speed_to_normal()

void cxxitimer::ITimer::set_speed_to_normal ( )
inherited

set speed to normal

like calling set_speed_factor with 1.0

Exceptions
std::system_errorcall of setitimer failed

Definition at line 157 of file cxxitimer.cpp.

References cxxitimer::ITimer::adjust_speed(), cxxitimer::ITimer::running, and cxxitimer::ITimer::speed_factor.

Here is the call graph for this function:

◆ start()

void cxxitimer::ITimer::start ( )
inherited

start timer

Exceptions
std::logic_errortimer already started
std::runtime_errorinvalid timer values due to a too small speed factor
std::system_errorcall of setitimer failed

Definition at line 96 of file cxxitimer.cpp.

References cxxitimer::operator/(), cxxitimer::ITimer::running, cxxitimer::ITimer::speed_factor, cxxitimer::ITimer::timer_interval, cxxitimer::ITimer::timer_value, and cxxitimer::ITimer::type.

Here is the call graph for this function:

◆ stop()

void cxxitimer::ITimer::stop ( )
inherited

stop timer

Exceptions
std::logic_errortimer already stopped
std::system_errorcall of setitimer failed

Definition at line 121 of file cxxitimer.cpp.

References cxxitimer::operator*(), cxxitimer::ITimer::running, cxxitimer::ITimer::speed_factor, cxxitimer::STOP_TIMER, cxxitimer::ITimer::timer_value, and cxxitimer::ITimer::type.

Referenced by cxxitimer::ITimer::~ITimer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_fstream()

void cxxitimer::ITimer::to_fstream ( std::ofstream &  fstream) const
inherited

write to binary file stream

writes interval and value to file stream. type and speed factor is not stored!

Parameters
fstreamfile stream to write to
Exceptions
std::system_errorcall of getitimer failed

Definition at line 164 of file cxxitimer.cpp.

References cxxitimer::operator*=(), cxxitimer::ITimer::running, cxxitimer::ITimer::speed_factor, cxxitimer::ITimer::timer_interval, cxxitimer::ITimer::timer_value, and cxxitimer::ITimer::type.

Here is the call graph for this function:

Member Data Documentation

◆ instance_exists

bool cxxitimer::ITimer_Virtual::instance_exists = false
staticprivate

◆ running

◆ speed_factor

◆ timer_interval

◆ timer_value

◆ type


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