forked from chunyi1994/cppevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_event.cpp
66 lines (51 loc) · 903 Bytes
/
time_event.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "time_event.h"
namespace cppevent{
TimeEvent::TimeEvent(TimeEventType type) :
time_() , interval_(), type_(type)
{
}
TimeEvent::TimeEvent(const Time &time, TimeEventType type) :
time_(time) , interval_(), type_(type)
{
}
void TimeEvent::setTime(const Time &time)
{
time_ = time;
}
void TimeEvent::setInterval(const Time &time)
{
interval_ = time;
}
void TimeEvent::setTimeCallback(const TimeCallback &cb)
{
timeCallback_ = cb;
}
void TimeEvent::setNextTime()
{
time_.now();
time_.add(interval_);
}
void TimeEvent::executeCallback() const
{
if(timeCallback_)
{
timeCallback_();
}
}
const Time &TimeEvent::getTime() const
{
return time_;
}
void TimeEvent::cancel()
{
type_ = TIME_TYPE_NOLONGER;
}
void TimeEvent::setType(TimeEventType type)
{
type_ = type;
}
TimeEventType TimeEvent::type() const
{
return type_;
}
}