Coverage Report

Created: 2026-12-03 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/DefaultStrategy.h
Line
Count
Source
1
//
2
// DefaultStrategy.h
3
//
4
// Library: Foundation
5
// Package: Events
6
// Module:  DefaultStrategy
7
//
8
// Implementation of the DefaultStrategy template.
9
//
10
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_DefaultStrategy_INCLUDED
18
#define Foundation_DefaultStrategy_INCLUDED
19
20
21
#include "Poco/NotificationStrategy.h"
22
#include "Poco/SharedPtr.h"
23
#include <vector>
24
25
26
namespace Poco {
27
28
29
template <class TArgs, class TDelegate>
30
class DefaultStrategy: public NotificationStrategy<TArgs, TDelegate>
31
  /// Default notification strategy.
32
  ///
33
  /// Internally, a std::vector<> is used to store
34
  /// delegate objects. Delegates are invoked in the
35
  /// order in which they have been registered.
36
{
37
public:
38
  using DelegateHandle = TDelegate*;
39
  using DelegatePtr = SharedPtr<TDelegate>;
40
  using Delegates = std::vector<DelegatePtr>;
41
  using Iterator = typename Delegates::iterator;
42
43
public:
44
33.6k
  DefaultStrategy() = default;
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::DefaultStrategy()
Line
Count
Source
44
16.8k
  DefaultStrategy() = default;
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::DefaultStrategy()
Line
Count
Source
44
16.8k
  DefaultStrategy() = default;
45
46
  DefaultStrategy(const DefaultStrategy& s):
47
50.8k
    _delegates(s._delegates)
48
50.8k
  {
49
50.8k
  }
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::DefaultStrategy(Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > > const&)
Line
Count
Source
47
33.3k
    _delegates(s._delegates)
48
33.3k
  {
49
33.3k
  }
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::DefaultStrategy(Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > > const&)
Line
Count
Source
47
17.4k
    _delegates(s._delegates)
48
17.4k
  {
49
17.4k
  }
50
51
84.4k
  ~DefaultStrategy() = default;
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::~DefaultStrategy()
Line
Count
Source
51
50.1k
  ~DefaultStrategy() = default;
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::~DefaultStrategy()
Line
Count
Source
51
34.2k
  ~DefaultStrategy() = default;
52
53
  void notify(const void* sender, TArgs& arguments)
54
50.8k
  {
55
68.3k
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
56
17.4k
    {
57
17.4k
      (*it)->notify(sender, arguments);
58
17.4k
    }
59
50.8k
  }
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::notify(void const*, std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>&)
Line
Count
Source
54
33.3k
  {
55
33.3k
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
56
0
    {
57
0
      (*it)->notify(sender, arguments);
58
0
    }
59
33.3k
  }
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::notify(void const*, std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>&)
Line
Count
Source
54
17.4k
  {
55
34.9k
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
56
17.4k
    {
57
17.4k
      (*it)->notify(sender, arguments);
58
17.4k
    }
59
17.4k
  }
60
61
  DelegateHandle add(const TDelegate& delegate)
62
16.8k
  {
63
16.8k
    DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
64
16.8k
    _delegates.push_back(pDelegate);
65
16.8k
    return pDelegate.get();
66
16.8k
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::add(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > const&)
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::add(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > const&)
Line
Count
Source
62
16.8k
  {
63
16.8k
    DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
64
16.8k
    _delegates.push_back(pDelegate);
65
16.8k
    return pDelegate.get();
66
16.8k
  }
67
68
  void remove(const TDelegate& delegate)
69
0
  {
70
0
    DelegatePtr p = detach(delegate);
71
0
    if (p) p->disable();
72
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::remove(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > const&)
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::remove(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > const&)
73
74
  void remove(DelegateHandle delegateHandle)
75
0
  {
76
0
    DelegatePtr p = detach(delegateHandle);
77
0
    if (p) p->disable();
78
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::remove(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> >*)
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::remove(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> >*)
79
80
  DelegatePtr detach(const TDelegate& delegate)
81
    /// Removes a matching delegate from the internal list without
82
    /// disabling it, and returns the detached delegate (or an empty
83
    /// DelegatePtr if no match). The caller is responsible for
84
    /// calling disable() on the returned delegate. This separation
85
    /// allows AbstractEvent to call disable() outside its own mutex,
86
    /// breaking the lock-order edge M_event -> M_delegate.
87
16.8k
  {
88
16.8k
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
89
16.8k
    {
90
16.8k
      if (delegate.equals(**it))
91
16.8k
      {
92
16.8k
        DelegatePtr p = *it;
93
16.8k
        _delegates.erase(it);
94
16.8k
        return p;
95
16.8k
      }
96
16.8k
    }
97
0
    return DelegatePtr();
98
16.8k
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::detach(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > const&)
Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::detach(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > const&)
Line
Count
Source
87
16.8k
  {
88
16.8k
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
89
16.8k
    {
90
16.8k
      if (delegate.equals(**it))
91
16.8k
      {
92
16.8k
        DelegatePtr p = *it;
93
16.8k
        _delegates.erase(it);
94
16.8k
        return p;
95
16.8k
      }
96
16.8k
    }
97
0
    return DelegatePtr();
98
16.8k
  }
99
100
  DelegatePtr detach(DelegateHandle delegateHandle)
101
0
  {
102
0
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
103
0
    {
104
0
      if (*it == delegateHandle)
105
0
      {
106
0
        DelegatePtr p = *it;
107
0
        _delegates.erase(it);
108
0
        return p;
109
0
      }
110
0
    }
111
0
    return DelegatePtr();
112
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::detach(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> >*)
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::detach(Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> >*)
113
114
  Delegates detachAll()
115
    /// Removes all delegates from the internal list without disabling
116
    /// them, and returns them so the caller can call disable() outside
117
    /// its mutex. See detach().
118
0
  {
119
0
    Delegates out;
120
0
    out.swap(_delegates);
121
0
    return out;
122
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::detachAll()
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::detachAll()
123
124
  DefaultStrategy& operator = (const DefaultStrategy& s)
125
  {
126
    if (this != &s)
127
    {
128
      _delegates = s._delegates;
129
    }
130
    return *this;
131
  }
132
133
  void clear()
134
0
  {
135
0
    Delegates detached = detachAll();
136
0
    for (Iterator it = detached.begin(); it != detached.end(); ++it)
137
0
    {
138
0
      (*it)->disable();
139
0
    }
140
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::clear()
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::clear()
141
142
  [[nodiscard]] bool empty() const
143
0
  {
144
0
    return _delegates.empty();
145
0
  }
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const> > >::empty() const
Unexecuted instantiation: Poco::DefaultStrategy<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const>, Poco::AbstractDelegate<std::__1::pair<Poco::Zip::ZipLocalFileHeader const, Poco::Path const> > >::empty() const
146
147
protected:
148
  Delegates _delegates;
149
};
150
151
152
template <class TDelegate>
153
class DefaultStrategy<void,TDelegate>: public NotificationStrategy<void, TDelegate>
154
  /// Default notification strategy.
155
  ///
156
  /// Internally, a std::vector<> is used to store
157
  /// delegate objects. Delegates are invoked in the
158
  /// order in which they have been registered.
159
{
160
public:
161
  using DelegateHandle = TDelegate*;
162
  using DelegatePtr = SharedPtr<TDelegate>;
163
  using Delegates = std::vector<DelegatePtr>;
164
  using Iterator = typename Delegates::iterator;
165
166
public:
167
  DefaultStrategy() = default;
168
169
  DefaultStrategy(const DefaultStrategy& s):
170
    _delegates(s._delegates)
171
  {
172
  }
173
174
  DefaultStrategy(DefaultStrategy&& s):
175
    _delegates(std::move(s._delegates))
176
  {
177
  }
178
179
  ~DefaultStrategy() = default;
180
181
  void notify(const void* sender)
182
  {
183
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
184
    {
185
      (*it)->notify(sender);
186
    }
187
  }
188
189
  DelegateHandle add(const TDelegate& delegate)
190
  {
191
    DelegatePtr pDelegate(static_cast<TDelegate*>(delegate.clone()));
192
    _delegates.push_back(pDelegate);
193
    return pDelegate.get();
194
  }
195
196
  void remove(const TDelegate& delegate)
197
  {
198
    DelegatePtr p = detach(delegate);
199
    if (p) p->disable();
200
  }
201
202
  void remove(DelegateHandle delegateHandle)
203
  {
204
    DelegatePtr p = detach(delegateHandle);
205
    if (p) p->disable();
206
  }
207
208
  DelegatePtr detach(const TDelegate& delegate)
209
    /// See the TArgs specialization above.
210
  {
211
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
212
    {
213
      if (delegate.equals(**it))
214
      {
215
        DelegatePtr p = *it;
216
        _delegates.erase(it);
217
        return p;
218
      }
219
    }
220
    return DelegatePtr();
221
  }
222
223
  DelegatePtr detach(DelegateHandle delegateHandle)
224
  {
225
    for (Iterator it = _delegates.begin(); it != _delegates.end(); ++it)
226
    {
227
      if (*it == delegateHandle)
228
      {
229
        DelegatePtr p = *it;
230
        _delegates.erase(it);
231
        return p;
232
      }
233
    }
234
    return DelegatePtr();
235
  }
236
237
  Delegates detachAll()
238
  {
239
    Delegates out;
240
    out.swap(_delegates);
241
    return out;
242
  }
243
244
  DefaultStrategy& operator = (const DefaultStrategy& s)
245
  {
246
    if (this != &s)
247
    {
248
      _delegates = s._delegates;
249
    }
250
    return *this;
251
  }
252
253
  DefaultStrategy& operator = (DefaultStrategy&& s)
254
  {
255
    if (this != &s)
256
    {
257
      _delegates = std::move(s._delegates);
258
    }
259
    return *this;
260
  }
261
262
  void clear()
263
  {
264
    Delegates detached = detachAll();
265
    for (Iterator it = detached.begin(); it != detached.end(); ++it)
266
    {
267
      (*it)->disable();
268
    }
269
  }
270
271
  [[nodiscard]] bool empty() const
272
  {
273
    return _delegates.empty();
274
  }
275
276
protected:
277
  Delegates _delegates;
278
};
279
280
281
} // namespace Poco
282
283
284
#endif // Foundation_DefaultStrategy_INCLUDED