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

abstract class ITimer More...

#include <cxxitimer.hpp>

Inheritance diagram for cxxitimer::ITimer:
Collaboration diagram for cxxitimer::ITimer:

Public Member Functions

 ITimer (const ITimer &other)=delete
 copying is not possible
 
 ITimer (ITimer &&other)=delete
 moving is not possible
 
ITimeroperator= (const ITimer &other)=delete
 copying is not possible
 
ITimeroperator= (ITimer &&other)=delete
 moving is not possible
 
virtual ~ITimer ()
 Destroy the timer instance.
 
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
 

Protected Member Functions

 ITimer (int type, const timeval &interval={.tv_sec=1,.tv_usec=0}) noexcept
 
 ITimer (int type, const timeval &interval, const timeval &value) noexcept
 
 ITimer (int type, double interval) noexcept
 
 ITimer (int type, double interval, double value) noexcept
 

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
 

Detailed Description

abstract class ITimer

Definition at line 16 of file cxxitimer.hpp.

Constructor & Destructor Documentation

◆ ITimer() [1/6]

cxxitimer::ITimer::ITimer ( int  type,
const timeval &  interval = {.tv_sec = 1, .tv_usec = 0} 
)
explicitprotectednoexcept

Definition at line 26 of file cxxitimer.cpp.

References running, speed_factor, timer_interval, timer_value, and type.

Referenced by cxxitimer::ITimer_Prof::ITimer_Prof(), cxxitimer::ITimer_Real::ITimer_Real(), and cxxitimer::ITimer_Virtual::ITimer_Virtual().

Here is the caller graph for this function:

◆ ITimer() [2/6]

cxxitimer::ITimer::ITimer ( int  type,
const timeval &  interval,
const timeval &  value 
)
protectednoexcept

Definition at line 42 of file cxxitimer.cpp.

References running, speed_factor, timer_interval, timer_value, and type.

Referenced by cxxitimer::ITimer_Prof::ITimer_Prof(), cxxitimer::ITimer_Real::ITimer_Real(), and cxxitimer::ITimer_Virtual::ITimer_Virtual().

Here is the caller graph for this function:

◆ ITimer() [3/6]

cxxitimer::ITimer::ITimer ( int  type,
double  interval 
)
protectednoexcept

Definition at line 34 of file cxxitimer.cpp.

References cxxitimer::double_to_timeval(), running, speed_factor, timer_interval, timer_value, and type.

Referenced by cxxitimer::ITimer_Prof::ITimer_Prof(), cxxitimer::ITimer_Real::ITimer_Real(), and cxxitimer::ITimer_Virtual::ITimer_Virtual().

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

◆ ITimer() [4/6]

cxxitimer::ITimer::ITimer ( int  type,
double  interval,
double  value 
)
protectednoexcept

Definition at line 50 of file cxxitimer.cpp.

References cxxitimer::double_to_timeval(), running, speed_factor, timer_interval, timer_value, and type.

Referenced by cxxitimer::ITimer_Prof::ITimer_Prof(), cxxitimer::ITimer_Real::ITimer_Real(), and cxxitimer::ITimer_Virtual::ITimer_Virtual().

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

◆ ITimer() [5/6]

cxxitimer::ITimer::ITimer ( const ITimer other)
delete

copying is not possible

◆ ITimer() [6/6]

cxxitimer::ITimer::ITimer ( ITimer &&  other)
delete

moving is not possible

◆ ~ITimer()

cxxitimer::ITimer::~ITimer ( )
virtual

Destroy the timer instance.

Timer is stopped if running, however, the timer should be stopped beforehand if possible. If the timer is still running and the call of stop() fails, the process will be terminated.

Definition at line 59 of file cxxitimer.cpp.

References running, and stop().

Here is the call graph for this function:

Member Function Documentation

◆ adjust_speed()

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

Definition at line 71 of file cxxitimer.cpp.

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

Referenced by set_speed_factor(), and 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)

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 running, timer_interval, and timer_value.

◆ get_timer_value()

timeval cxxitimer::ITimer::get_timer_value ( ) const

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*(), running, speed_factor, timer_value, and type.

Here is the call graph for this function:

◆ is_running()

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

check if timer is running

Returns
true timer is running
false timer is stopped

Definition at line 175 of file cxxitimer.hpp.

References running.

◆ operator=() [1/2]

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

copying is not possible

◆ operator=() [2/2]

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

moving is not possible

◆ set_interval() [1/2]

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

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 set_interval_value().

Here is the call graph for this function:

◆ set_interval() [2/2]

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

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

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 running, timer_interval, and timer_value.

Referenced by set_interval(), and 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 
)

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 set_interval_value().

Referenced by 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)

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 adjust_speed(), running, and speed_factor.

Here is the call graph for this function:

◆ set_speed_to_normal()

void cxxitimer::ITimer::set_speed_to_normal ( )

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 adjust_speed(), running, and speed_factor.

Here is the call graph for this function:

◆ start()

void cxxitimer::ITimer::start ( )

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/(), running, speed_factor, timer_interval, timer_value, and type.

Here is the call graph for this function:

◆ stop()

void cxxitimer::ITimer::stop ( )

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*(), running, speed_factor, cxxitimer::STOP_TIMER, timer_value, and type.

Referenced by ~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

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*=(), running, speed_factor, timer_interval, timer_value, and type.

Here is the call graph for this function:

Member Data Documentation

◆ running

◆ speed_factor

double cxxitimer::ITimer::speed_factor
private

speed adjustment factor

  • ]0;1[ --> slower
  • ]1;inf[ --> faster
  • 1 --> normal speed

Definition at line 34 of file cxxitimer.hpp.

Referenced by adjust_speed(), get_timer_value(), ITimer(), ITimer(), ITimer(), ITimer(), set_speed_factor(), set_speed_to_normal(), start(), stop(), and to_fstream().

◆ timer_interval

timeval cxxitimer::ITimer::timer_interval
private

◆ timer_value

timeval cxxitimer::ITimer::timer_value
private

◆ type

int cxxitimer::ITimer::type
private

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