30 const size_t count = receivers_.size();
31 for (
size_t i = 0; i < count; ++i)
32 if (ptr == receivers_[i])
34 receivers_.push_back(ptr);
42 const size_t count = receivers_.size();
45 for (
size_t i = 0; i < count; ++i) {
46 if (receivers_[i] == ptr) {
47 receivers_[i] = receivers_[receivers_.size() - 1U];
48 receivers_.pop_back();
58 for (
size_t i = 0; i < receivers_.size();) {
59 if (receivers_[i].GetUnderlyingRefCountUnsynchronized()) {
62 receivers_[i] = receivers_[receivers_.size() - 1U];
63 receivers_.pop_back();
74 return receivers_.size();
84 for (
size_t i = 0; i < receivers_.size();) {
87 receiver->OnNotify(
this);
90 receivers_[i] = receivers_[receivers_.size() - 1U];
91 receivers_.pop_back();
void AddReceiver(Notifier *receiver)
Adds a Notifier to be notified.
A Notifier both sends notifications to and receives notifications from other Notifiers.
void Notify() const
Notifies all contained Notifiers by calling their OnNotify().
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
size_t GetReceiverCount() const
Returns the number of Notifiers that will be notified.
A LockGuard locks a mutex when created, and unlocks it when destroyed.
int GetRefCount() const
GetRefCount() is part of the interface necessary for SharedPtr.
~Notifier() override
The destructor is protected because this is derived from Referent.
void RemoveReceiver(Notifier *receiver)
Removes a Notifier to be notified.
A WriteLock obtains a write lock, but has a similar interface to a Mutex and can be used with a Write...
virtual void OnNotify(const Notifier *notifier)
Subclasses can override this to provide custom behavior on notifications.
const NotifierPtrVector & GetReceivers() const
Returns the set of Notifiers that will be notified.
A ReadLock obtains a read lock, but has a similar interface to a Mutex and can be used with a ReadGua...
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
A WeakReferentPtr is a weak reference to an instance of some class derived from Referent.