NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
time-unit-test-clock.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2018 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*/
21
22
#ifndef NDN_UTIL_TIME_UNIT_TEST_CLOCK_HPP
23
#define NDN_UTIL_TIME_UNIT_TEST_CLOCK_HPP
24
25
#include "
ndn-cxx/util/time-custom-clock.hpp
"
26
27
namespace
ndn
{
28
namespace
time
{
29
36
template
<
class
BaseClock>
37
class
UnitTestClockTraits
38
{
39
public
:
40
static
nanoseconds
41
getDefaultStartTime
()
42
{
43
return
nanoseconds::zero();
44
}
45
};
46
53
template
<>
54
class
UnitTestClockTraits
<
system_clock
>
55
{
56
public
:
57
static
nanoseconds
58
getDefaultStartTime
()
59
{
60
return
seconds(1415684132);
61
}
62
};
63
72
template
<
class
BaseClock,
class
ClockTraits = UnitTestClockTraits<BaseClock>>
73
class
UnitTestClock
:
public
CustomClock
<BaseClock>
74
{
75
public
:
76
explicit
77
UnitTestClock
(nanoseconds startTime = ClockTraits::getDefaultStartTime());
78
82
void
83
advance
(nanoseconds duration);
84
88
void
89
setNow
(nanoseconds timeSinceEpoch);
90
91
public
:
92
std::string
93
getSince
()
const override
;
94
95
typename
BaseClock::time_point
96
getNow
()
const override
;
97
98
typename
BaseClock::duration
99
toWaitDuration
(
typename
BaseClock::duration d)
const override
;
100
101
private
:
102
nanoseconds m_currentTime;
103
};
104
105
extern
template
class
UnitTestClock<system_clock>
;
106
extern
template
class
UnitTestClock<steady_clock>
;
107
108
using
UnitTestSystemClock
=
UnitTestClock<system_clock>
;
109
using
UnitTestSteadyClock
=
UnitTestClock<steady_clock>
;
110
111
}
// namespace time
112
}
// namespace ndn
113
114
#endif // NDN_UTIL_TIME_UNIT_TEST_CLOCK_HPP
ndn::time::UnitTestClockTraits
Traits for UnitTestClock, defining default behavior for different clocks.
Definition:
time-unit-test-clock.hpp:38
ndn::time::UnitTestClock::toWaitDuration
BaseClock::duration toWaitDuration(typename BaseClock::duration d) const override
Definition:
time-unit-test-clock.cpp:53
ndn::time::UnitTestClock
Clock that can be used in unit tests for time-dependent tests independent of wall clock.
Definition:
time-unit-test-clock.hpp:74
ndn::time::CustomClock
Class implementing custom system or steady clock behavior.
Definition:
time-custom-clock.hpp:38
ndn::time::system_clock
System clock.
Definition:
time.hpp:187
time-custom-clock.hpp
ndn::time::UnitTestClock::getSince
std::string getSince() const override
Definition:
time-unit-test-clock.cpp:39
ndn::time::UnitTestClock::UnitTestClock
UnitTestClock(nanoseconds startTime=ClockTraits::getDefaultStartTime())
Definition:
time-unit-test-clock.cpp:32
ndn::time
Definition:
time-custom-clock.hpp:28
ndn::time::UnitTestClock::setNow
void setNow(nanoseconds timeSinceEpoch)
Explicitly set clock to timeSinceEpoch.
Definition:
time-unit-test-clock.cpp:81
ndn::time::UnitTestClockTraits::getDefaultStartTime
static nanoseconds getDefaultStartTime()
Definition:
time-unit-test-clock.hpp:41
ndn::time::UnitTestClock::advance
void advance(nanoseconds duration)
Advance unit test clock by duration.
Definition:
time-unit-test-clock.cpp:60
ndn::time::UnitTestClock::getNow
BaseClock::time_point getNow() const override
Definition:
time-unit-test-clock.cpp:46
ndn::time::UnitTestClockTraits< system_clock >::getDefaultStartTime
static nanoseconds getDefaultStartTime()
Definition:
time-unit-test-clock.hpp:58
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
util
time-unit-test-clock.hpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18