30.11.2010 - initial commit

This commit is contained in:
peri4
2010-11-30 08:11:27 +03:00
commit 2925e4d786
24 changed files with 2403 additions and 0 deletions

69
pitimer.h Normal file
View File

@@ -0,0 +1,69 @@
#ifndef PITIMER_H
#define PITIMER_H
#include <ctime>
#include <csignal>
#include "pithread.h"
typedef void (*TimerEvent)(void * );
struct PITime {
int seconds;
int minutes;
int hours;
};
struct PIDate {
int day;
int month;
int year; // since 1900
};
class PITimer
#ifdef __WIN32__
: public PIThread
#endif
{
public:
PITimer(void * data = 0, TimerEvent slot = 0);
~PITimer() {stop();}
#ifdef __WIN32__
void reset() {t_st = GetCurrentTime();}
#else
void reset() {clock_gettime(0, &t_st);}
void start(double msecs);
void stop() {if (ti == 0) timer_delete(timer); ti = -1; running = false;}
bool isRunning() const {return running;}
#endif
double elapsed_n(); // nanoseconds
double elapsed_u(); // microseconds
double elapsed_m(); // miliseconds
double elapsed_s(); // seconds
private:
#ifdef __WIN32__
void run() {if (ret_func != 0) ret_func(data);}
long int t_st, t_cur;
#else
static void timer_event(sigval e);
bool running;
int ti;
itimerspec spec;
timespec t_st, t_cur;
timer_t timer;
sigevent se;
#endif
void * data;
TimerEvent ret_func;
};
PITime currentTime();
PIDate currentDate();
string time2string(const PITime & time, const string & format = "h:m:s");
string date2string(const PIDate & date, const string & format = "d.m.y");
#endif // PITIMER_H