forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLog.cpp
More file actions
84 lines (68 loc) · 1.89 KB
/
EventLog.cpp
File metadata and controls
84 lines (68 loc) · 1.89 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
// 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)
#include "react/logging/EventLog.h"
/***************************************/ REACT_IMPL_BEGIN /**************************************/
using std::chrono::duration_cast;
using std::chrono::microseconds;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// EventLog
///////////////////////////////////////////////////////////////////////////////////////////////////
EventLog::Entry::Entry() :
time_{ std::chrono::system_clock::now() },
data_{ nullptr }
{
}
EventLog::Entry::Entry(const Entry& other) :
time_{ other.time_ },
data_{ other.data_}
{
}
EventLog::Entry::Entry(IEventRecord* ptr) :
time_{ std::chrono::system_clock::now() },
data_{ ptr }
{
}
void EventLog::Entry::Serialize(std::ostream& out, const TimestampT& startTime) const
{
out << EventId() << " : " << duration_cast<microseconds>(Time() - startTime).count() << std::endl;
data_->Serialize(out);
}
EventLog::Entry& EventLog::Entry::operator=(Entry& rhs)
{
time_ = rhs.time_,
data_ = std::move(rhs.data_);
return *this;
}
bool EventLog::Entry::Equals(const Entry& other) const
{
if (EventId() != other.EventId())
return false;
// Todo
return false;
}
EventLog::EventLog() :
startTime_(std::chrono::system_clock::now())
{
}
EventLog::~EventLog()
{
Clear();
}
void EventLog::Print()
{
Write(std::cout);
}
void EventLog::Write(std::ostream& out)
{
for (auto& e : entries_)
e.Serialize(out, startTime_);
}
void EventLog::Clear()
{
for (auto& e : entries_)
e.Release();
entries_.clear();
}
/****************************************/ REACT_IMPL_END /***************************************/