NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
cancel-handle.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2021 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_CXX_DETAIL_CANCEL_HANDLE_HPP
23
#define NDN_CXX_DETAIL_CANCEL_HANDLE_HPP
24
25
#include "
ndn-cxx/detail/common.hpp
"
26
27
namespace
ndn
{
28
namespace
detail {
29
32
class
CancelHandle
33
{
34
public
:
35
CancelHandle
() noexcept;
36
37
explicit
38
CancelHandle
(std::function<
void
()>
cancel
) noexcept
39
: m_cancel(
std::move
(
cancel
))
40
{
41
}
42
45
void
46
cancel
()
const
;
47
48
private
:
49
mutable
std::function<void()> m_cancel;
50
};
51
52
inline
53
CancelHandle::CancelHandle
() noexcept =
default
;
54
57
template
<
typename
HandleT>
58
class
ScopedCancelHandle
59
{
60
static_assert(
std::is_convertible<HandleT*, CancelHandle*>::value
,
61
"HandleT must publicly derive from CancelHandle"
);
62
63
public
:
64
ScopedCancelHandle
() noexcept;
65
68
ScopedCancelHandle
(HandleT hdl) noexcept
69
: m_hdl(
std::move
(hdl))
70
{
71
}
72
75
ScopedCancelHandle
(
const
ScopedCancelHandle
&) =
delete
;
76
79
ScopedCancelHandle
(
ScopedCancelHandle
&& other) noexcept
80
: m_hdl(other.release())
81
{
82
}
83
86
ScopedCancelHandle
&
87
operator=(
const
ScopedCancelHandle
&) =
delete
;
88
91
ScopedCancelHandle
&
92
operator=
(
ScopedCancelHandle
&& other)
93
{
94
m_hdl.
cancel
();
95
m_hdl = other.release();
96
return
*
this
;
97
}
98
101
~ScopedCancelHandle
()
102
{
103
m_hdl.cancel();
104
}
105
108
void
109
cancel
()
110
{
111
release().cancel();
112
}
113
117
HandleT
118
release
() noexcept
119
{
120
return
std::exchange(m_hdl, HandleT{});
121
}
122
123
explicit
124
operator
bool() const noexcept
125
{
126
return
!!m_hdl;
127
}
128
129
private
:
130
HandleT m_hdl;
131
};
132
133
template
<
typename
T>
134
ScopedCancelHandle<T>::ScopedCancelHandle
() noexcept =
default
;
135
136
}
// namespace detail
137
}
// namespace ndn
138
139
#endif // NDN_CXX_DETAIL_CANCEL_HANDLE_HPP
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional-lite.hpp:472
ndn::detail::CancelHandle::CancelHandle
CancelHandle(std::function< void()> cancel) noexcept
Definition:
cancel-handle.hpp:38
common.hpp
Common includes and macros used throughout the library.
ndn::detail::ScopedCancelHandle::release
HandleT release() noexcept
Release the operation so that it won't be cancelled when this ScopedCancelHandle is destructed...
Definition:
cancel-handle.hpp:118
ndn::detail::CancelHandle::CancelHandle
CancelHandle() noexcept
ndn::detail::ScopedCancelHandle::operator=
ScopedCancelHandle & operator=(ScopedCancelHandle &&other)
Move assignment operator.
Definition:
cancel-handle.hpp:92
ndn::detail::ScopedCancelHandle::ScopedCancelHandle
ScopedCancelHandle(ScopedCancelHandle &&other) noexcept
Move constructor.
Definition:
cancel-handle.hpp:79
ndn::detail::ScopedCancelHandle::cancel
void cancel()
Cancel the operation.
Definition:
cancel-handle.hpp:109
ndn::detail::CancelHandle
Handle to cancel an operation.
Definition:
cancel-handle.hpp:32
ndn::detail::ScopedCancelHandle::~ScopedCancelHandle
~ScopedCancelHandle()
Cancel the operation.
Definition:
cancel-handle.hpp:101
websocketpp::session::state::value
value
Definition:
connection.hpp:179
ndn::detail::ScopedCancelHandle::ScopedCancelHandle
ScopedCancelHandle(HandleT hdl) noexcept
Implicit constructor from HandleT.
Definition:
cancel-handle.hpp:68
ndn::detail::CancelHandle::cancel
void cancel() const
Cancel the operation.
Definition:
cancel-handle.cpp:28
ndn::detail::ScopedCancelHandle
Cancels an operation automatically upon destruction.
Definition:
cancel-handle.hpp:58
ndn::detail::ScopedCancelHandle::ScopedCancelHandle
ScopedCancelHandle() noexcept
ndnSIM
ndn-cxx
ndn-cxx
detail
cancel-handle.hpp
Generated on Fri May 6 2022 12:34:10 for ndnSIM by
1.8.13