-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathEventLog.h
More file actions
100 lines (74 loc) · 2.26 KB
/
EventLog.h
File metadata and controls
100 lines (74 loc) · 2.26 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright Sebastian Jeckel 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef REACT_DETAIL_LOGGING_EVENTLOG_H_INCLUDED
#define REACT_DETAIL_LOGGING_EVENTLOG_H_INCLUDED
#pragma once
#include "react/detail/Defs.h"
#include <memory>
#include <cstdint>
#include <functional>
#include <iostream>
#include <chrono>
#include "tbb/concurrent_vector.h"
#include "Logging.h"
#include "react/common/Types.h"
/***************************************/ REACT_IMPL_BEGIN /**************************************/
///////////////////////////////////////////////////////////////////////////////////////////////////
/// EventLog
///////////////////////////////////////////////////////////////////////////////////////////////////
class EventLog
{
using TimestampT = std::chrono::time_point<std::chrono::system_clock>;
class Entry
{
public:
Entry();
Entry(const Entry& other);
explicit Entry(IEventRecord* ptr);
Entry& operator=(Entry& rhs);
inline const char* EventId() const
{
return data_->EventId();
}
inline const TimestampT& Time() const
{
return time_;
}
inline bool operator<(const Entry& other) const
{
return time_ < other.time_;
}
inline void Release()
{
delete data_;
}
void Serialize(std::ostream& out, const TimestampT& startTime) const;
bool Equals(const Entry& other) const;
private:
TimestampT time_;
IEventRecord* data_;
};
public:
EventLog();
~EventLog();
void Print();
void Write(std::ostream& out);
void Clear();
template
<
typename TEventRecord,
typename ... TArgs
>
void Append(TArgs ... args)
{
entries_.push_back(Entry(new TEventRecord(args ...)));
}
private:
using LogEntriesT = tbb::concurrent_vector<Entry>;
LogEntriesT entries_;
TimestampT startTime_;
};
/****************************************/ REACT_IMPL_END /***************************************/
#endif // REACT_DETAIL_LOGGING_EVENTLOG_H_INCLUDED