Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::Signal< TArgs > Class Template Reference

A Signal object, designed to emit signals matching some data signature to be received by all the SignalObservers subscribed to it. More...

#include <signals.hpp>

Public Member Functions

 Signal (SignalTracker &owningTracker, const std::string &name)
 Constructs a Signal object and associates it with its SignalTracker.
 
 Signal (const Signal &other)=delete
 
 Signal (Signal &&other)=delete
 
Signaloperator= (const Signal &other)=delete
 
Signaloperator= (Signal &&other)=delete
 
void emit (TArgs...args)
 A method on the signal which causes the signal to be sent to all of its subscribers (aka SignalObservers).
 
void resetSignal (SignalTracker &owningTracker, const std::string &name)
 Reinitializes the tracker with a new owning SignalTracker.
 

Private Member Functions

void registerObserver (SignalObserver< TArgs... > &observer)
 Registers a compatible SignalObserver as a subscriber of this Signal.
 

Private Attributes

std::shared_ptr< Signal_< TArgs... > > mSignal_
 The actual object connected with this Signal's signal tracker, hidden from users of Signal.
 

Friends

class SignalObserver< TArgs... >
 

Detailed Description

template<typename ... TArgs>
class ToyMaker::Signal< TArgs >

A Signal object, designed to emit signals matching some data signature to be received by all the SignalObservers subscribed to it.

It is essentially a wrapper over Signal_<T>

Usage

class SomeClass : public ToyMaker::SignalTracker {
// ...
public:
ToyMaker::Signal<> mSigViewUpdateStarted { *this, "ViewUpdateStarted" };
ToyMaker::Signal<GameScoreData> mSigScoreUpdated { *this, "ScoreUpdated" };
// ...
};
A signal tracker, the main interface between an object and the signal system.
Definition signals.hpp:161
A Signal object, designed to emit signals matching some data signature to be received by all the Sign...
Definition signals.hpp:323

Here we see two signals declared, one that sends no data, and one that sends GameScoreData, named "ViewUpdateStarted" and "ScoreUpdated" respectively.

When a SignalObserver (with the correct signature) wishes to connect to these signals, a function call resembling the one below should be made:

signalTo.connect(
"ViewUpdateStarted",
"ObserveViewUpdateStarted",
signalFrom
);

Where:

Template Parameters
TArgsA list of data types this Signal is expected to send when a signal is emitted.
See also
SignalTracker
SignalObserver

Constructor & Destructor Documentation

◆ Signal()

template<typename ... TArgs>
ToyMaker::Signal< TArgs >::Signal ( SignalTracker & owningTracker,
const std::string & name )

Constructs a Signal object and associates it with its SignalTracker.

Parameters
owningTrackerThe tracker responsible for advertising this signal.
nameThe name of this signal.

Member Function Documentation

◆ emit()

template<typename ... TArgs>
void ToyMaker::Signal< TArgs >::emit ( TArgs... args)

A method on the signal which causes the signal to be sent to all of its subscribers (aka SignalObservers).

Parameters
argsA list of values sent along with this signal.

◆ registerObserver()

template<typename ... TArgs>
void ToyMaker::Signal< TArgs >::registerObserver ( SignalObserver< TArgs... > & observer)
private

Registers a compatible SignalObserver as a subscriber of this Signal.

Parameters
observerThe observer requesting subscription.

◆ resetSignal()

template<typename ... TArgs>
void ToyMaker::Signal< TArgs >::resetSignal ( SignalTracker & owningTracker,
const std::string & name )

Reinitializes the tracker with a new owning SignalTracker.

Useful for copy and move operations on the object this signal may be a member of.

Parameters
owningTrackerA reference to this Signal's new owning tracker.
nameThe (possibly new) name of this signal, per its owner.
Todo
Investigate the behaviour of this method.

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