20 #ifndef MPD_NFS_CANCELLABLE_HXX
21 #define MPD_NFS_CANCELLABLE_HXX
25 #include <boost/intrusive/list.hpp>
33 :
public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
57 reference_type
Get() {
63 constexpr
bool Is(const_reference_type other)
const {
68 template<
typename T,
typename CT=CancellablePo
inter<T>>
75 typedef boost::intrusive::list<CT,
76 boost::intrusive::constant_time_size<false>> List;
77 typedef typename List::iterator iterator;
78 typedef typename List::const_iterator const_iterator;
82 const_reference_type p;
85 explicit constexpr MatchPointer(const_reference_type _p)
88 constexpr
bool operator()(
const CT &a)
const {
94 iterator Find(reference_type p) noexcept {
95 return std::find_if(list.begin(), list.end(), MatchPointer(p));
99 const_iterator Find(const_reference_type p)
const noexcept {
100 return std::find_if(list.begin(), list.end(), MatchPointer(p));
104 iterator Find(CT &c) noexcept {
105 return list.iterator_to(c);
109 const_iterator Find(
const CT &c)
const noexcept {
110 return list.iterator_to(c);
117 for (
const auto &c : list)
118 if (!c.IsCancelled())
126 bool Contains(const_reference_type p)
const noexcept {
127 return Find(p) != list.end();
130 template<
typename... Args>
131 CT &
Add(reference_type p, Args&&... args) {
132 assert(Find(p) == list.end());
134 CT *c =
new CT(p, std::forward<Args>(args)...);
141 assert(i != list.end());
149 assert(i != list.end());
154 CT &
Get(reference_type p) noexcept {
156 assert(i != list.end());
const T & const_reference_type
gcc_pure bool Contains(const_reference_type p) const noexcept
CT::reference_type reference_type
constexpr bool Is(const_reference_type other) const
void Cancel(reference_type p)
CancellablePointer(reference_type _p)
constexpr bool IsCancelled() const
gcc_pure bool IsEmpty() const noexcept
CT & Add(reference_type p, Args &&...args)
CT & Get(reference_type p) noexcept
CT::const_reference_type const_reference_type