guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
guit::GExpr Class Referenceabstract

Active Expression. More...

Inheritance diagram for guit::GExpr:
guit::GProp guit::GObject guit::GBoolExpr guit::GNumExpr guit::GTextExpr

Classes

class  NumVectArg
 Numerical vector element. More...
 
class  VectArg
 Vector element. More...
 

Public Types

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

Public Member Functions

bool boolValue () const override=0
 Returns the value as a bool. More...
 
float floatValue () const override=0
 Returns the value of the prop as a float. More...
 
GString stringValue () const override=0
 Returns the value of the prop as a string. More...
 
GExprclone (bool) const override
 can't be cloned.
 
virtual bool isMutable () const
 Returns true if the prop is mutable. More...
 
virtual void setImmutable ()
 Makes the prop immutable. 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.
 
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...
 

Protected Member Functions

bool isEquivalent (const GProp &other) const override
 Returns true if these props are equivalent. More...
 

Detailed Description

Active Expression.

Active Expression are reified and automatically reevaluated when the value of one of their mutable props changes. Such expressions can be:

1) Added to a gadget. For instance, to convert from Euros to Dollars:

auto& euros = Float(1);
auto& rate = Float(1.12);
auto& box = VBox
<< (TextField << euros)
<< (TextField << rate)
<< ("Result: " + (~euros * ~rate) + "$"); // reactive expression
euros = 100;

The last line is a textual reactive expression, which displays "Result: 112$" (i.e. 100 euros * a rate of 1.12)

It will be automatically updated each time the value of 'euros' or 'rate' is changed. 'euros' or 'rate' must be preceded by a ~. This indicates that the expr depends on these variables

2) Serve as a condition in conditional statements. The action will be fired if the RExpr becomes true when the value of its variables changes:

auto& status = Int(0); // integer prop
auto& label = Label
<< (~status == 0) / "<color=green>OK"
<< (~status == 1) / "<color=orange>Warning"
<< (~status == 2) / "<color=red>DANGER!!!"
status = 2;

The Label will display "DANGER!!!" in red color. As above, it will be changed if the value of 'status' is changed.

The active expression can contain variables (mutable props or states) of various types provided that it is syntactically correct and returns a bool. It can contain && and || conjonctors.

See Also
CondProp.

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::GExpr::boolValue ( ) const
overridepure virtual

Returns the value as a bool.

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

Reimplemented from guit::GProp.

Implemented in guit::GNumExpr, guit::GTextExpr, and guit::GBoolExpr.

float guit::GExpr::floatValue ( ) const
overridepure virtual

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

Implemented in guit::GNumExpr, guit::GTextExpr, and guit::GBoolExpr.

GString guit::GExpr::stringValue ( ) const
overridepure virtual

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.

Implemented in guit::GNumExpr, guit::GTextExpr, and guit::GBoolExpr.

bool guit::GExpr::isEquivalent ( const GProp other) const
inlineoverrideprotectedvirtual

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.

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.

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: