11template<
class Event,
class CompareOrder>
16 const Event* lookup (
const Event &event)
const;
17 const Event* lookup_after (
const Event &event)
const;
19 CompareOrder compare_;
23template<
class Event,
class Compare>
28 using CIter =
typename EventVector::const_iterator;
30 bool insert (
const Event &event,
Event *replaced =
nullptr);
42 CIter
end ()
const {
return events_.
end(); }
44 bool equals (
const EventVector &ev)
const {
return ev == events_; }
52 static void nop (
const Event&,
int) {}
56template<
class Event,
class Compare>
inline
57EventList<Event,Compare>::EventList (
const Notify &n,
const Compare &c) :
58 compare_ (c), notify_ (n)
64template<
class Event,
class Compare>
inline void
71template<
class Event,
class Compare>
inline void
77template<
class Event,
class Compare>
inline bool
78EventList<Event,Compare>::insert (
const Event &event, Event *replaced)
81 if (events_.size() && compare_ (event, events_.back()) > 0)
83 events_.push_back (event);
88 auto it = insmatch.first;
89 if (insmatch.second ==
true)
99 events_.insert (it, event);
105template<
class Event,
class Compare>
inline bool
109 if (insmatch.second ==
true)
112 auto it = insmatch.first;
122template<
class Event,
class Compare>
inline bool
126 const int cmp = events_.empty() ? +1 : compare_ (event, events_.
back());
130 *removed = events_.
back();
138 if (it != events_.end())
150template<
class Event,
class Compare>
inline const Event*
153 return events_.
empty() ? nullptr : &events_.front();
156template<
class Event,
class Compare>
inline const Event*
159 return events_.
empty() ? nullptr : &events_.back();
162template<
class Event,
class Compare>
inline size_t
165 return events_.size();
168template<
class Event,
class Compare>
inline const Event*
172 return it != events_.end() ? &*it :
nullptr;
175template<
class Event,
class Compare>
inline const Event*
179 return it != events_.end() ? &*it :
nullptr;
182template<
class Event,
class Compare>
197template<
class Event,
class CompareOrder>
201 auto lesser = [
this] (
const Event &a,
const Event &b) {
202 return compare_ (a, b) < 0;
207template<
class Event,
class CompareOrder>
inline const Event*
208OrderedEventList<Event,CompareOrder>::lookup (
const Event &event)
const
211 return it != this->
end() ? &*it :
nullptr;
214template<
class Event,
class CompareOrder>
inline const Event*
215OrderedEventList<Event,CompareOrder>::lookup_after (
const Event &event)
const
218 return it != this->
end() ? &*it :
nullptr;
Maintain an array of unique Event structures with change notification.
bool remove(const Event &event, Event *removed=nullptr)
Only replace event, notifies.
CIter end() const
Const iterator that points to the first element.
void clear_silently()
Return the numberof elements.
OrderedEventList::ConstP ordered_events()
Clear list without notification.
bool replace(const Event &event, Event *replaced=nullptr)
Insert or replace event, notifies.
CIter begin() const
Create a read-only copy of this EventList (possibly cached).
const Event * lookup(const Event &event) const
Return true if event was removed, notifies.
size_t size() const
Return last element or nullptr.
EventVector copy() const
Const iterator that points one past the last element.
const Event * lookup_after(const Event &event) const
Return pointer to matching event or nullptr.
const Event * first() const
Return pointer to element that is >= event or nullptr.
const Event * last() const
Return first element or nullptr.
#define ASE_ASSERT_RETURN(expr,...)
Return from the current function if expr evaluates to false and issue an assertion warning.
RandIter binary_lookup(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
Perform binary lookup and yield exact match or end.
std::pair< RandIter, bool > binary_lookup_insertion_pos(RandIter begin, RandIter end, Cmp cmp_elements, const Arg &arg)
Perform a binary lookup to find the insertion position for a new element.
The Anklang C++ API namespace.
Structure for callback based notifications.
Container for a sorted array of opaque Event structures with binary lookup.