lichao
2021-06-03 b674aecae951c1f83e07f80956160fadf331d026
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
/*
 * =====================================================================================
 *
 *       Filename:  timed_queue.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年04月12日 09时36分04秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), lichao@aiotlink.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef TIMED_QUEUE_Y2YLRBS3
#define TIMED_QUEUE_Y2YLRBS3
 
#include "bh_util.h"
#include <chrono>
#include <list>
#include <string>
 
template <class Data, class ClockType = std::chrono::steady_clock>
class TimedData
{
public:
    typedef ClockType Clock;
    typedef typename Clock::time_point TimePoint;
    typedef typename Clock::duration Duration;
 
    TimedData(const TimePoint &expire, const Data &data) :
        expire_(expire), data_(data) {}
    TimedData(const TimePoint &expire, Data &&data) :
        expire_(expire), data_(std::move(data)) {}
    bool Expired() const { return Clock::now() > expire_; }
    const TimePoint &expire() const { return expire_; }
    Data &data() { return data_; }
    Data const &data() const { return data_; }
 
private:
    TimePoint expire_;
    Data data_;
};
 
#endif // end of include guard: TIMED_QUEUE_Y2YLRBS3