libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
ObjectBase Class Reference

Base object for promeki. More...

#include <objectbase.h>

Inheritance diagram for ObjectBase:
Collaboration diagram for ObjectBase:

Classes

class  MetaInfo
 Captures all the metadata about this object. More...
 
class  SignalMeta
 Metadata entry describing a signal on an ObjectBase-derived class. More...
 
class  SlotMeta
 Metadata entry describing a slot on an ObjectBase-derived class. More...
 

Public Types

using SlotVariantFunc = std::function< void(const VariantList &)>
 Function type for invoking a slot with a list of Variants.
 

Public Member Functions

 ObjectBase (ObjectBase *p=nullptr)
 Default ObjectBase constructor.
 
virtual ~ObjectBase ()
 Destructor. Emits aboutToDestroy, detaches from parent, and destroys children.
 
ObjectBaseparent () const
 Returns the parent object, if one. nullptr if none.
 
void setParent (ObjectBase *p)
 Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one.
 
const ObjectBaseListchildList () const
 Returns a list of children of this object.
 
template<typename... Args>
int registerSlot (Slot< Args... > *slot)
 Registers a slot with this object and assigns it an ID.
 
EventLoopeventLoop () const
 Returns the EventLoop this object is affiliated with.
 
void moveToThread (EventLoop *loop)
 Changes the EventLoop affinity of this object.
 
int startTimer (unsigned int intervalMs, bool singleShot=false)
 Starts a timer on this object's EventLoop.
 
void stopTimer (int timerId)
 Stops a timer previously started with startTimer().
 
template<typename... Args>
PROMEKI_NAMESPACE_BEGIN void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 

Static Public Member Functions

static const MetaInfometaInfo ()
 Returns the MetaInfo for the ObjectBase class.
 
template<typename... Args>
static void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object
 

Public Attributes

Signal< ObjectBase * > aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName)
 

Static Public Attributes

static constexpr const charaboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")"
 
static SignalMeta aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName)
 

Protected Member Functions

ObjectBasesignalSender ()
 Returns the ObjectBase that emitted the signal currently being handled.
 
virtual void event (Event *e)
 Called by EventLoop to deliver events to this object.
 
virtual void timerEvent (TimerEvent *e)
 Called when a timer fires for this object.
 

Friends

class ObjectBasePtr
 
class EventLoop
 

Detailed Description

Base object for promeki.

This object is used by promeki to provide certain objects with a base level of funtionality which include:

  • Signals and slots
  • Some level of meta type and reflection

The object was modeled from the Qt QObject, although isn't quite as versitle but it trades off that versatility for not needing an external meta object compiler.

Constructor & Destructor Documentation

◆ ObjectBase()

ObjectBase::ObjectBase ( ObjectBase p = nullptr)

Default ObjectBase constructor.

Parameters
[in]pParent object

This is the default constructor you'll normally use to construct the ObjectBase object in your derived class constructor. If your class is meant to have a parent object, you should pass it in. This will ensure that this object is destroyed if the parent is destroyed.

Member Function Documentation

◆ childList()

const ObjectBaseList & ObjectBase::childList ( ) const
inline

Returns a list of children of this object.

Returns
List of children

◆ event()

virtual void ObjectBase::event ( Event e)
protectedvirtual

Called by EventLoop to deliver events to this object.

The default implementation dispatches TimerEvent to timerEvent() and accepts it.

Parameters
eThe event to handle.

Reimplemented in TuiWidget.

◆ eventLoop()

EventLoop * ObjectBase::eventLoop ( ) const
inline

Returns the EventLoop this object is affiliated with.

Returns
The EventLoop set at construction time, or nullptr.

◆ moveToThread()

void ObjectBase::moveToThread ( EventLoop loop)

Changes the EventLoop affinity of this object.

Must be called from the object's current thread. The object must have no parent. Children are moved recursively. Asserts on violation of either constraint.

Parameters
loopThe new EventLoop to affiliate with.

◆ parent()

ObjectBase * ObjectBase::parent ( ) const
inline

Returns the parent object, if one. nullptr if none.

Returns
Parent object pointer, or nullptr if none.

◆ registerSlot()

template<typename... Args>
int ObjectBase::registerSlot ( Slot< Args... > *  slot)
inline

Registers a slot with this object and assigns it an ID.

Template Parameters
ArgsThe slot's parameter types.
Parameters
slotPointer to the Slot to register.
Returns
The assigned slot ID.

◆ startTimer()

int ObjectBase::startTimer ( unsigned int  intervalMs,
bool  singleShot = false 
)

Starts a timer on this object's EventLoop.

TimerEvent will be delivered to this object's timerEvent() method each time the timer fires.

Parameters
intervalMsThe timer interval in milliseconds.
singleShotIf true, the timer fires once and is removed.
Returns
The timer ID, or -1 if no EventLoop is available.

◆ stopTimer()

void ObjectBase::stopTimer ( int  timerId)

Stops a timer previously started with startTimer().

Parameters
timerIdThe timer ID returned by startTimer().

◆ timerEvent()

virtual void ObjectBase::timerEvent ( TimerEvent e)
protectedvirtual

Called when a timer fires for this object.

Override this in derived classes to handle timer events. The default implementation does nothing.

Parameters
eThe timer event.

Reimplemented in TuiStatusBar.

Member Data Documentation

◆ aboutToDestroySignalName

constexpr const char* ObjectBase::aboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")"
staticconstexpr

Object is about to be destroyed This signal is emitted when the object is about to be destroyed.

NOTE: when this is emitted the object has mostly already been torn down so you'll not be able to cast it to a derived object.

Signal:

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