Sen API
Sen Libraries
Loading...
Searching...
No Matches
sen::ObjectProvider Class Referenceabstract

Base class for an entity that is able to produce objects. More...

#include <object_provider.h>

Inheritance diagram for sen::ObjectProvider:

Public Member Functions

 ObjectProvider ()
virtual ~ObjectProvider ()
virtual void addListener (ObjectProviderListener *listener, bool notifyAboutExistingObjects)
 Registers an event listener.
virtual void removeListener (ObjectProviderListener *listener, bool notifyAboutExistingObjects)
 Un-registers an event listener.
virtual void replaceListener (ObjectProviderListener *oldListener, ObjectProviderListener *newListener)
 Replaces an existing listener with a new one without triggering notifications. Keep in mind that the links to the providers in the listeners are not updated during this operation. Used in move constructors of the ObjectFilter.
virtual bool hasListener (ObjectProviderListener *listener) const noexcept
 Returns true if the listener has been added.
virtual bool hasListeners () const noexcept
 Returns true if there are registered listeners.

Protected Member Functions

virtual void notifyObjectsAdded (const ObjectAdditionList &additions)
 Calls onObjectAdded on all the registered listeners.
virtual void notifyObjectsRemoved (const ObjectRemovalList &removals)
 Calls onObjectRemoved on all the registered listeners.
virtual void listenerAdded (ObjectProviderListener *listener, bool notifyAboutExistingObjects)
 Does nothing by default.
virtual void listenerRemoved (ObjectProviderListener *listener, bool notifyAboutExistingObjects)
 Does nothing by default.
virtual void notifyAddedOnExistingObjects (ObjectProviderListener *listener)=0
 Subclasses must call onObjectAdded on the listener for all the existing objects.
virtual void notifyRemovedOnExistingObjects (ObjectProviderListener *listener)=0
 Subclasses must call onObjectRemoved on the listener for all the existing objects.
void notifyRemovedOnExistingObjectsForAllListeners ()
 Same as notifyRemovedOnExistingObjects but for all registered listeners.
void forEachListener (const std::function< void(ObjectProviderListener *)> &callback) const
 Calls callback once for each registered listener.
void callOnObjectsAdded (ObjectProviderListener *listener, const ObjectAdditionList &additions) const
void callOnObjectsRemoved (ObjectProviderListener *listener, const ObjectRemovalList &removals) const

Friends

class ObjectFilter

Detailed Description

Base class for an entity that is able to produce objects.

Constructor & Destructor Documentation

◆ ObjectProvider()

sen::ObjectProvider::ObjectProvider ( )

◆ ~ObjectProvider()

virtual sen::ObjectProvider::~ObjectProvider ( )
virtual

Member Function Documentation

◆ addListener()

virtual void sen::ObjectProvider::addListener ( ObjectProviderListener * listener,
bool notifyAboutExistingObjects )
virtual

Registers an event listener.

The listener will be notified of objects being added and removed, and this provider will pass itself as the source of the objects.

A listener can be only added once to the same provider. So calling his method with the same listener will do nothing.

This provider will not take ownership of the added listener. But when a listener gets destroyed, it will ensure that it removes itself from the providers it was added to. Note that in this case your listener will not be notified about the removal of existing objects.

Parameters
listenerthe entity that will be notified about objects.
notifyAboutExistingObjectsif true, the listener will get an immediate 'onObjectAdded' call for each existing object in the provider.

Reimplemented in sen::ObjectMux.

◆ removeListener()

virtual void sen::ObjectProvider::removeListener ( ObjectProviderListener * listener,
bool notifyAboutExistingObjects )
virtual

Un-registers an event listener.

Does nothing if the provided event listener was not added.

Parameters
listenerthe listener that was previously added.
notifyAboutExistingObjectsif true, the listener will get a 'onObjectRemoved' call for each existing object in the provider.

Reimplemented in sen::ObjectMux.

◆ replaceListener()

virtual void sen::ObjectProvider::replaceListener ( ObjectProviderListener * oldListener,
ObjectProviderListener * newListener )
virtual

Replaces an existing listener with a new one without triggering notifications. Keep in mind that the links to the providers in the listeners are not updated during this operation. Used in move constructors of the ObjectFilter.

Does nothing if the old listener is not found.

Parameters
oldListenerthe currently registered listener to be replaced.
newListenerthe new listener to take its place.

◆ hasListener()

virtual bool sen::ObjectProvider::hasListener ( ObjectProviderListener * listener) const
nodiscardvirtualnoexcept

Returns true if the listener has been added.

Reimplemented in sen::ObjectMux.

◆ hasListeners()

virtual bool sen::ObjectProvider::hasListeners ( ) const
nodiscardvirtualnoexcept

Returns true if there are registered listeners.

Reimplemented in sen::ObjectMux.

◆ notifyObjectsAdded()

virtual void sen::ObjectProvider::notifyObjectsAdded ( const ObjectAdditionList & additions)
protectedvirtual

Calls onObjectAdded on all the registered listeners.

Reimplemented in sen::ObjectMux.

◆ notifyObjectsRemoved()

virtual void sen::ObjectProvider::notifyObjectsRemoved ( const ObjectRemovalList & removals)
protectedvirtual

Calls onObjectRemoved on all the registered listeners.

Reimplemented in sen::ObjectMux.

◆ listenerAdded()

virtual void sen::ObjectProvider::listenerAdded ( ObjectProviderListener * listener,
bool notifyAboutExistingObjects )
protectedvirtual

Does nothing by default.

◆ listenerRemoved()

virtual void sen::ObjectProvider::listenerRemoved ( ObjectProviderListener * listener,
bool notifyAboutExistingObjects )
protectedvirtual

Does nothing by default.

◆ notifyAddedOnExistingObjects()

virtual void sen::ObjectProvider::notifyAddedOnExistingObjects ( ObjectProviderListener * listener)
protectedpure virtual

Subclasses must call onObjectAdded on the listener for all the existing objects.

Implemented in sen::ObjectMux.

◆ notifyRemovedOnExistingObjects()

virtual void sen::ObjectProvider::notifyRemovedOnExistingObjects ( ObjectProviderListener * listener)
protectedpure virtual

Subclasses must call onObjectRemoved on the listener for all the existing objects.

Implemented in sen::ObjectMux.

◆ notifyRemovedOnExistingObjectsForAllListeners()

void sen::ObjectProvider::notifyRemovedOnExistingObjectsForAllListeners ( )
protected

Same as notifyRemovedOnExistingObjects but for all registered listeners.

◆ forEachListener()

void sen::ObjectProvider::forEachListener ( const std::function< void(ObjectProviderListener *)> & callback) const
protected

Calls callback once for each registered listener.

The registry is a lock-free list and cannot lend out a container. Its iterators survive a concurrent insert or erase, so the callback may add or remove listeners; one erased before the walk reaches it is not visited.

◆ callOnObjectsAdded()

void sen::ObjectProvider::callOnObjectsAdded ( ObjectProviderListener * listener,
const ObjectAdditionList & additions ) const
protected

◆ callOnObjectsRemoved()

void sen::ObjectProvider::callOnObjectsRemoved ( ObjectProviderListener * listener,
const ObjectRemovalList & removals ) const
protected

◆ ObjectFilter

friend class ObjectFilter
friend

The documentation for this class was generated from the following file: