NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
event-emitter.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#ifndef NDN_UTIL_EVENT_EMITTER_HPP
23
#define NDN_UTIL_EVENT_EMITTER_HPP
24
25
#include "../common.hpp"
26
#include <vector>
27
28
namespace
ndn
{
29
namespace
util {
30
46
template
<
typename
...TArgs>
47
class
EventEmitter
: noncopyable
48
{
49
public
:
52
typedef
function
<void(
const
TArgs&...)>
Handler
;
53
56
void
57
operator+=
(
const
Handler& handler);
58
61
bool
62
isEmpty
()
const
;
63
66
void
67
clear
();
68
71
void
72
operator()
(
const
TArgs&...args)
const
;
73
74
private
:
75
std::vector<Handler> m_handlers;
76
};
77
78
template
<
typename
...TArgs>
79
inline
void
80
EventEmitter<TArgs...>::operator+=
(
const
Handler
& handler)
81
{
82
m_handlers.push_back(handler);
83
}
84
85
template
<
typename
...TArgs>
86
inline
bool
87
EventEmitter<TArgs...>::isEmpty
()
const
88
{
89
return
m_handlers.empty();
90
}
91
92
template
<
typename
...TArgs>
93
inline
void
94
EventEmitter<TArgs...>::clear
()
95
{
96
return
m_handlers.clear();
97
}
98
99
template
<
typename
...TArgs>
100
inline
void
101
EventEmitter<TArgs...>::operator()
(
const
TArgs&...args)
const
102
{
103
for
(
const
Handler
& handler : m_handlers) {
104
handler(args...);
105
if
(m_handlers.empty())
// .clear has been called
106
return
;
107
}
108
}
109
110
111
}
// namespace util
112
}
// namespace ndn
113
114
#endif // NDN_UTIL_EVENT_EMITTER_HPP
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::util::EventEmitter::clear
void clear()
clears all subscriptions
Definition:
event-emitter.hpp:94
ndn::util::EventEmitter::Handler
function< void(const TArgs &...)> Handler
represents a handler that can subscribe to the event
Definition:
event-emitter.hpp:52
ndn::util::EventEmitter::isEmpty
bool isEmpty() const
Definition:
event-emitter.hpp:87
ndn::util::EventEmitter::operator()
void operator()(const TArgs &...args) const
triggers the event
Definition:
event-emitter.hpp:101
ndn::util::EventEmitter::operator+=
void operator+=(const Handler &handler)
subscribes to the event
Definition:
event-emitter.hpp:80
ndn::util::EventEmitter
provides a lightweight event system
Definition:
event-emitter.hpp:47
ndnSIM
ndn-cxx
src
util
event-emitter.hpp
Generated on Tue Feb 23 2016 22:18:44 for ndnSIM by
1.8.11