未完成
#pragma once
#ifndef _ANTIMER_H_
#define _ANTIMER_H_
#include <Windows.h>
#include <thread>
#include <mutex>
#include <condition_variable>
template<typename Callback, typename ...Args>
class AnTimer{
public:
AnTimer(){}
~AnTimer(){}
void SetTimer (int Sec, Callback func, Args... args);
void Start (void);
void Stop (void);
private:
void ThreadRun(Callback *func, int Sec, int flag, Args &&... args);
private:
Callback *pFunc;
int RunTimes;
bool Flag;
};
AnTimer::AnTimer():pFunc(nullptr), RunTimes(0),Flag(false){}
AnTimer::~AnTimer(){}
void ThreadRun(Callback *func, int Sec, int flag, Args &&.. args){
do{
BeginTime = xx;
while(EndTime < BeginTime){
std::this_thread::sleep_for(std::chrono::microseconds(1));
EndTime = xx;
while(Flag != true){
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
}
*func(args);
if(flag > 0){ flag--; }
}while(flag != 0);
}
void AnTimer::SetTimer (Callback func, int Sec, int flag, Args &&.. args){
pFunc = &func;
}
namespace ANTimer {
template<typename Callback, typename ..Args>
void SingleShot (Callback func, int Sec, Args .. args){
AnTimer tmp;
tmp.SetTimer
}
}
#endif
|