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

Conditional Expression. More...

Inheritance diagram for guit::GCond:
guit::GProp guit::GObject guit::GGuard guit::GOtherwise

Public Types

using Specif = int32_t
 Specificity of Properties.
 
using GType = GPropType
 Returns prop's meta-class. More...
 

Public Member Functions

bool isEquivalent (const GProp &) const override
 Returns true if these props are equivalent. More...
 
GCondclone (bool copy_value) const override
 can't be cloned.
 
GString stringValue () const override
 Returns the value of the prop as a string. More...
 
bool onAdd (Gadget *) override
 Called when the property is added to an object. More...
 
void onRemove (Gadget *) override
 Called when the property is removed from an object. More...
 
virtual bool isMutable () const
 Returns true if the prop is mutable. More...
 
virtual void setImmutable ()
 Makes the prop immutable. More...
 
virtual float floatValue () const
 Returns the value of the prop as a float. More...
 
virtual bool boolValue () const
 Returns the value as a bool. 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.
 
virtual void removeNotifiers (void *obj)
 [Implementation] Notifies this object that it must no longer refer obj.
 
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.
 
virtual class GVarProptoVarProp ()
 Type conversions.
 
template<class Subclass >
Subclass * to ()
 Class conversions.
 
void ignoreSmartPointers ()
 Checks/sets whether this object can be auto-deleted by smart pointers. More...
 

Detailed Description

Conditional Expression.

A Conditional Expressions has the following form:

action
trigger / action
trigger / action1 / action2 / etc.
trigger / transition / action1 /action2 / etc.

The trigger specifies when the action is executed. Several actions can be specified, and they will be executed in this order. Optionally, there can be a state transition between the trigger and the first action.

A trigger can be (see details and examples below):

An action can be:

A transition is a state transition such as: (state1 >> state2). See GState.

functions

auto& btn = Button("Do It")
<< [this]{doThis();}
<< on::action / [this]{doThat();}
<< on::mousedown / [this]{doDown();}
<< on::mouseup / [this]{doUp();};

The left part is the trigger, the right part is a lambda that is executed when the trigger is fired. The trigger can be omitted, in which case the default on::action trigger is used (see below). The trigger can also be a boolean Active Expression, as explained in a later section.

Supposing that doIt(), doDown() and doUp() are methods:

The meaning of the default trigger depends on the gadget it is added to, e.g. it is equivalent to:

Lambdas capture this, as in this example. They can also capture variables by value (using [=]) or by reference (using [&]). C++ references must be captured by reference, and pointers by value.

The lambdas can have an optional GEvent& argument:

auto& btn = HBox()
<< on::paint / [this](auto& e) {doPaint(e);}
<< on::mousedown / [this](auto& e) {doDown(asMouseEvent(e));}
<< on::mouseup / [this](auto& e) {doUp(asMouseEvent(e));};
<< on::mousedrag / [this](auto& e) {doDrag(asMouseEvent(e));};

The GEvent argument is the event that fired the trigger. In this example, this alllows doPaint() to draw graphics and doDown() etc. to retreive the position of the mouse

Active Expressions

auto& btn = Button
<< on::checked / "selected" / Color("red")
<< on::unchecked / "idle" / Color("blue");

The left part is the trigger, the right part is a Prop that is activated when the trigger is fired. Thus, the button will display "selected" in red color when it is checked, and "idle" in blue color when it is unchecked.

When the trigger has a counterpart (e.g. on::checked vs. on::unchecked), the Prop is deactivated when the counterpart is fired. Thus, the previous example is equivalent to: ///

auto& btn = Button
<< "idle" / GColor::blue;
<< on::checked / "selected" / GColor::red;

Note that attributed text could also have been used:

auto& btn = Button
<< on::checked / "<color=red>selected"
<< on::unchecked / "<color=blue>idle";

Active Expressions

auto& euros = Float(100); // 100 Euros
auto& rate = Float(1.2); // Euro => Dollar conversion rate
auto& btn = Button
<< on::checked / "The value is " + (~euros * ~rate) + "$"
<< on::unchecked / "The value is " + ~euros + "€"

The right part is an Active Expression that is evaluated dynamically. It is automatically updated when the value of one of its variables (which must be preceeded by a ~) is changed. Active Expressions are activated/deactivated in the same way as Props.

Triggers (Boolean Active Expressions)

The trigger can also be a boolean Active Expression, which is reevaluated when the value of one of its variables is changed:

and State Transitions

Guards and State Transitions can also be part of conditional expressions: see GGuard, on::guard, and GState, GHState, GStateChart.

See Also
GExpr for examples and more info on Active Expressions.

Member Typedef Documentation

using guit::GProp::GType = GPropType
inherited

Returns prop's meta-class.

Both functions return the prop's type, but Type() is a static method and type() a virtual method.

Member Function Documentation

bool guit::GCond::isEquivalent ( const GProp other) const
inlineoverridevirtual

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 from guit::GProp.

GString guit::GCond::stringValue ( ) const
overridevirtual

Returns the value of the prop as a string.

Returns "" if the prop has no value of its value cannot be converted to a string.

Reimplemented from guit::GProp.

Reimplemented in guit::GOtherwise, and guit::GGuard.

bool guit::GCond::onAdd ( Gadget g)
overridevirtual

Called when the property is added to an object.

note: must call addModes().

Reimplemented from guit::GProp.

void guit::GCond::onRemove ( Gadget g)
overridevirtual

Called when the property is removed from an object.

note: must call removeModes().

Reimplemented from guit::GProp.

virtual bool guit::GProp::isMutable ( ) const
inlinevirtualinherited

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 in guit::GVarProp.

virtual void guit::GProp::setImmutable ( )
inlinevirtualinherited

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 in guit::GVarProp.

virtual float guit::GProp::floatValue ( ) const
inlinevirtualinherited

Returns the value of the prop as a float.

Returns 0.f if the prop has no value of its value cannot be converted to a float.

Reimplemented in guit::GNumExpr, guit::GTextExpr, guit::GBoolExpr, guit::GExpr, guit::GState, guit::GText, and guit::GBool.

virtual bool guit::GProp::boolValue ( ) const
inlinevirtualinherited

Returns the value as a bool.

Returns false if the prop has no value of its value cannot be converted to a bool.

Reimplemented in guit::GNumExpr, guit::GTextExpr, guit::GBoolExpr, guit::GExpr, and guit::GBool.

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: