guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
Public Types | Public Member Functions | List of all members
guit::GTimer Class Reference

Timer object. More...

Inheritance diagram for guit::GTimer:
guit::GInt

Public Types

using Specif = int32_t
 Specificity of Properties.
 

Public Member Functions

void restart ()
 Restarts without setting the value to 0.
 
GTimeroperator= (int value)
 changes the number of repetitions.
 
GTimeroperator<< (GCond &c)
 Adds a callback or a conditional prop or expression to the timer (see GCond).
 
GTimeroperator<< (class GStateTransition &)
 Adds a state transition to the timer (see GState).
 
int repetitions () const
 How many times the timer is fired. More...
 
GIntclone (bool copy_value) const override
 Clones the prop (when applicable). More...
 
auto operator~ ()
 Future value in an Active Expression (see GExpr).
 
GIntoperator<<= (GNumExpr &)
 Binds this prop to an active expression (see GExpr).
 
GIntsetRange (int min, int max)
 Specifies range.
 
GIntsetCycles (bool)
 Specifies whether the int cycles between min() and max() If cycles is true, operator++ sets the value to min() if it becomes >= to max() (same thing the other way with operator–). More...
 
GVarProptoVarProp () override
 Type conversions.
 
bool isMutable () const override
 Returns true if the prop is mutable. More...
 
void setImmutable () override
 Makes the prop immutable. More...
 
void blink (GString const &msg="", GTime duration=500)
 Blinks gadget parents of the prop. More...
 
void update ()
 updates gadget parents of the prop.
 
void perform (std::function< void(Gadget &)> fun)
 performs this function on gadget parents.
 
GPropList const & props () const
 Returns callbacks and bound props.
 
virtual void removeNotifiers (void *object) override
 [Implementation] Notifies this object that it must no longer refer obj.
 
virtual void removeAll ()
 Removes callbacks and notifiers.
 
virtual bool isEquivalent (GProp const &other) const
 Returns true if these props are equivalent. More...
 
virtual bool onAdd (Gadget *)
 Called when the property is added to an object. More...
 
virtual void onRemove (Gadget *)
 Called when the property is removed from an object. More...
 
virtual void error (GString const &funname, GString const &message) const
 Prints an error message. More...
 
void operator delete (void *)
 delete does nothing, see GObject class.
 
void forgetSmartPointers ()
 Forgets all smart pointers pointing this object. More...
 
unsigned int useCount () const
 Returns the numbers of smart pointers referencing the object.
 
void start (bool yes=true)
 Starts or stops the timer. More...
 
GIntaddBeat (int timer_count, int max_value)
 Adds a beat counter to the timer. More...
 
T const & value () const
 Returns the value.
 
bool boolValue () const override
 Returns the value converted to a different type.
 
min () const
 Returns the range (see setRange()).
 
bool read (GString const &filename)
 Reads the value of the prop from a file or a stream.
 
void unbind (GVarProp &sender)
 Unbinds this prop. More...
 
GString typeName () const override
 Returns the name and role of the prop's type.
 
GProptoProp () override
 Class conversions.
 
bool write (GString const &filename) const
 Writes the value of the prop on a file or a stream.
 
template<class Subclass >
Subclass * to ()
 Class conversions.
 
void ignoreSmartPointers ()
 Checks/sets whether this object can be auto-deleted by smart pointers. More...
 
static T lowest ()
 Returns the lowest/highest possible values.
 

Detailed Description

Timer object.

A timer fires callbacks after a certain delay. A timer can fire callbacks one time, N times (each time after waiting for the specifed delay) or indefinitively.

A timer has a value (returned by value() or operator(), which are inherited from GIntt), which is the number of the current repetition. This feature can be useful for animations.

A timer repeating indefinitively, or 3 times. doIt() is called every 1000ms:

auto& timer1 = Timer(1000) << [this]{doIt();}; // fired every 1000ms, indefinitively
auto& timer2 = Timer(1000,3) << [this]{doIt();}; // fired every 1000ms, 3 times

When adding a callback function without specifying a trigger (as in this example), the default on::action trigger is used, which means that the function is called after each repetition. The right-hand part could contain one or several callback(s), conditional prop(s) or conditional expression(s): see GCond.

A One Shot timer is auto-deleted after the first repetition:

auto& timer = Timer(1000, GTimer::OneShot) << [&]{doIt();}; // one-shot (auto-deleted)

More precisely, the timer is auto-deleted only if it is not gptr-pointed elsewhere.

The on::done trigger allows executing callbacks after the last repetition:

auto& timer = Timer(1000,3)
<< [this]{doIt();}
<< on::done / [this]{doDone();};

A timer can have 'beat counters'. Below, timer.addBeat(var, n, max) returns a GInt that is increased by 1 when timer has been fired 'n' times and that it is reset to 0 when it reaches 'max' (so that 'seconds' will count the seconds, 'minut's the minutes and 'hours' the hours);

auto &timer = Timer(1000)
auto& seconds = timer.addBeat(1, 60);
auto& minutes = timer.addBeat(60, 60);
auto& hours = timer.addBeat(60*60, 24);
auto& display = HBox()
<< hours << minutes << seconds; // displays each value in a TextField
// callback function that is called every minute
minutes << [&]{ std::cout << "minutes: " << minutes << std::endl; }
See Also
GAnim for creating animations.

Member Function Documentation

void guit::GTimer::start ( bool  yes = true)

Starts or stops the timer.

starts(true) sets the timer value to 0 (use reset() for not setting the value to 0).

GInt & guit::GTimer::addBeat ( int  timer_count,
int  max_value 
)

Adds a beat counter to the timer.

See GTimer doc for an example. Both versions return the 'beat', the only difference is that the first version creates the beat (a new GInt), while the second version uses a preexisting GInt.

int guit::GTimer::repetitions ( ) const
inline

How many times the timer is fired.

A value of -1 or GTimer::Infinite means that the timer is fired indefinitively.

GInt * guit::GInt::clone ( bool  copy_value) const
overridevirtualinherited

Clones the prop (when applicable).

Mutable props (i.e. deriving from GVarProp) can be cloned, otherwise this method returns null. The value is copied if copy_value is used, the default value is used otherwise.

Reimplemented from guit::GProp.

GInt & guit::GInt::setCycles ( bool  cycles)
inherited

Specifies whether the int cycles between min() and max() If cycles is true, operator++ sets the value to min() if it becomes >= to max() (same thing the other way with operator–).

bool guit::GVarProp::isMutable ( ) const
inlineoverridevirtualinherited

Returns true if the prop is mutable.

Returns true only if the prop derives from GVarProp and setImmutable() was not called. Props with another type than GVarProp are always immutable.

Reimplemented from guit::GProp.

void guit::GVarProp::setImmutable ( )
inlineoverridevirtualinherited

Makes the prop immutable.

Affects only GVarProp props (other props are always immutable). A prop cannot be made mutable again after this method has been called.

Reimplemented from guit::GProp.

void guit::GVarProp::unbind ( GVarProp sender)
inherited

Unbinds this prop.

  • the first version unbinds another prop (note that it doesn't unbind Prop fields).
  • the second version unbinds bindings according to its bindtag argument:

    if bindtag is >= 0, unbinds bindings performed with the same bindtag (default by 0, see bind())

if bindtag is < 0, unbinds all bindings with a value >= bindtag

Importantly, these methods unbinds props both ways if the binding was done both ways (e.g. by using sync())

void guit::GVarProp::blink ( GString const &  msg = "",
GTime  duration = 500 
)
inherited

Blinks gadget parents of the prop.

Shows a warning if msg is not empty.

bool guit::GProp::isEquivalent ( GProp const &  other) const
virtualinherited

Returns true if these props are equivalent.

Adding a prop to a gadget replaces the equivalent prop it contains (if it contains any). In all other cases, the prop is added to the gadget proplist. NOTE: props with a negative role are never equivalent!

Reimplemented in guit::GExpr, guit::GCond, guit::GState, and guit::GAnim.

bool guit::GProp::onAdd ( Gadget g)
virtualinherited

Called when the property is added to an object.

note: must call addModes().

Reimplemented in guit::GTextData, guit::GTip, guit::GCond, guit::GDragPos, guit::GDragSize, guit::GPos, guit::GText, guit::GSize, guit::GFlex, guit::GFlow, guit::GItems, and guit::GValue.

void guit::GProp::onRemove ( Gadget g)
virtualinherited

Called when the property is removed from an object.

note: must call removeModes().

Reimplemented in guit::GTextData, guit::GTip, guit::GCond, guit::GDragPos, guit::GDragSize, guit::GPos, guit::GText, guit::GSize, guit::GFlex, and guit::GHotkey.

void guit::GObject::error ( GString const &  funname,
GString const &  message 
) const
virtualinherited

Prints an error message.

See Also
GApp::onError() to change error management.
void guit::GObject::ignoreSmartPointers ( )
inlineinherited

Checks/sets whether this object can be auto-deleted by smart pointers.

ignoreSmartPointers() has a permanent effect, contrary to forgetSmartPointers(). Objects not created by calling new are never auto-deleted by smart pointers.

void guit::GObject::forgetSmartPointers ( )
inlineinherited

Forgets all smart pointers pointing this object.

The smart pointers that are currently pointing to the object won't auto-delete it. forgetSmartPointers() has a temporary effect, contrary to ignoreSmartPointers().


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