OpenWalnut
1.5.0dev
|
A named property class with a concrete type. More...
#include <WPropertyVariable.h>
Classes | |
class | PropertyConstraint |
Class building the base for user defined constraints on a property instance. More... | |
Public Types | |
typedef std::shared_ptr< WPropertyVariable< T > > | SPtr |
Convenience typedef for a shared_ptr of WPropertyVariable. More... | |
typedef std::shared_ptr< const WPropertyVariable< T > > | ConstSPtr |
Convenience typedef for a shared_ptr of const WPropertyVariable. More... | |
typedef T | DataType |
The type of the data of this property. More... | |
typedef WSharedAssociativeContainer< std::set< std::shared_ptr< PropertyConstraint > > > | ConstraintContainerType |
The alias for a shared container. More... | |
typedef std::shared_ptr< WPropertyConstraintMin< T > > | PropertyConstraintMin |
Alias for min constraints. More... | |
typedef std::shared_ptr< WPropertyConstraintMax< T > > | PropertyConstraintMax |
Alias for max constraints. More... | |
Public Types inherited from WFlag< T > | |
typedef T | ValueType |
The type for later access. More... | |
typedef std::shared_ptr< WFlag< T > > | SPtr |
Convenience typedef for a std::shared_ptr. More... | |
typedef std::shared_ptr< const WFlag< T > > | ConstSPtr |
Convenience typedef for a std::shared_ptr. More... | |
Public Types inherited from WPropertyBase | |
typedef std::shared_ptr< WPropertyBase > | SPtr |
Convenience typedef for a std::shared_ptr< WPropertyBase > More... | |
typedef std::shared_ptr< const WPropertyBase > | ConstSPtr |
Convenience typedef for a std::shared_ptr< const WPropertyBase > More... | |
typedef boost::function< void(std::shared_ptr< WPropertyBase >)> | PropertyChangeNotifierType |
Signal signature emitted during set operations. More... | |
Public Member Functions | |
WPropertyVariable (std::string name, std::string description, const T &initial) | |
Create an empty instance just containing a name. More... | |
WPropertyVariable (std::string name, std::string description, const T &initial, std::shared_ptr< WCondition > condition) | |
Create an empty instance just containing a name. More... | |
WPropertyVariable (std::string name, std::string description, const T &initial, PropertyChangeNotifierType notifier) | |
Create an empty instance just containing a name. More... | |
WPropertyVariable (std::string name, std::string description, const T &initial, std::shared_ptr< WCondition > condition, PropertyChangeNotifierType notifier) | |
Create an empty instance just containing a name. More... | |
WPropertyVariable (const WPropertyVariable< T > &from) | |
Copy constructor. More... | |
virtual | ~WPropertyVariable () |
Destructor. More... | |
virtual std::shared_ptr< WPropertyBase > | clone () |
This method clones a property and returns the clone. More... | |
virtual bool | accept (const T &newValue) |
Determines whether the specified value is acceptable. More... | |
virtual bool | ensureValidity (const T &newValidValue, bool suppressNotification=false) |
This method is useful to ensure, that there is a valid value in the property. More... | |
void | addConstraint (std::shared_ptr< PropertyConstraint > constraint) |
Add a new constraint. More... | |
ConstraintContainerType | getConstraints () |
Returns all the current constraints of a WPropertyVariable. More... | |
std::shared_ptr< WCondition > | getContraintsChangedCondition () |
Gets the condition, which gets notified whenever the list of constraints changes. More... | |
PropertyConstraintMin | setMin (const T &min) |
Set a minimum constraint. More... | |
PropertyConstraintMax | setMax (const T &max) |
Set a maximum constraint. More... | |
PropertyConstraintMin | getMin () |
Gets the current minimum constraint value. More... | |
PropertyConstraintMax | getMax () |
Gets the current maximum constraint value. More... | |
void | replaceConstraint (std::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type) |
This replaces all existing constraints of a certain type by a new specified constraint. More... | |
std::shared_ptr< PropertyConstraint > | replaceConstraint (PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type) |
This replaces all existing constraints of a certain type by a new specified constraint. More... | |
void | removeConstraint (PROPERTYCONSTRAINT_TYPE type) |
Cleans list of constraints from all existing constrains of the specified type. More... | |
void | removeConstraint (std::shared_ptr< PropertyConstraint > constraint) |
Removes the specified constraint if existent. More... | |
std::shared_ptr< PropertyConstraint > | getFirstConstraint (PROPERTYCONSTRAINT_TYPE type) |
Method searching the first appearance of a constrained with the specified type. More... | |
int | countConstraint (PROPERTYCONSTRAINT_TYPE type) |
Method searching the first appearance of a constrained with the specified type. More... | |
virtual bool | setAsString (std::string value) |
This methods allows properties to be set by a string value. More... | |
virtual std::string | getAsString () |
Returns the current value as a string. More... | |
virtual bool | set (std::shared_ptr< WPropertyBase > value, bool recommendedOnly=false) |
Sets the value from the specified property to this one. More... | |
virtual bool | set (const T &value, bool suppressNotification=false) |
Sets the new value for this flag. More... | |
virtual bool | setRecommendedValue (const T &value) |
Sets the specified value as recommended value. More... | |
Public Member Functions inherited from WFlag< T > | |
WFlag (WCondition *condition, const T &initial) | |
Constructor. More... | |
WFlag (std::shared_ptr< WCondition > condition, const T &initial) | |
Constructor. More... | |
WFlag (const WFlag &from) | |
Copy constructor. More... | |
virtual | ~WFlag () |
Destructor. More... | |
virtual const T & | get (bool resetChangeState=false) |
Operator returns value of the flag. More... | |
virtual const T & | get () const |
Operator returns value of the flag. More... | |
virtual const T & | operator() () const |
Operator returns value of the flag. More... | |
virtual | operator T () const |
Operator returns value of the flag. More... | |
virtual void | wait () const |
Wait for the flag to change its value. More... | |
virtual void | operator() (const T &value) |
Sets the new value for this flag. More... | |
std::shared_ptr< WCondition > | getCondition () |
Returns the condition that is used by this flag. More... | |
std::shared_ptr< WCondition > | getValueChangeCondition () |
Returns the condition denoting a value change. More... | |
virtual bool | isValid () |
Tests whether a flag is currently valid. More... | |
virtual bool | changed (bool reset=false) |
True whenever the value inside this flag has changed since the last reset. More... | |
Public Member Functions inherited from WPropertyBase | |
WPropertyBase (std::string name, std::string description) | |
Create an empty named property. More... | |
WPropertyBase (const WPropertyBase &from) | |
Copy constructor. More... | |
virtual | ~WPropertyBase () |
Destructor. More... | |
std::string | getName () const |
Gets the name of the class. More... | |
std::string | getDescription () const |
Gets the description of the property. More... | |
bool | isHidden () const |
Determines whether the property is hidden or not. More... | |
void | setHidden (bool hidden=true) |
Sets the property hidden. More... | |
virtual PROPERTY_TYPE | getType () const |
Gets the real WPropertyVariable type of this instance. More... | |
virtual PROPERTY_PURPOSE | getPurpose () const |
Gets the purpose of a property. More... | |
virtual void | setPurpose (PROPERTY_PURPOSE purpose) |
Sets the purpose of the property. More... | |
template<typename T > | |
bool | set (const T &value) |
Shortcut to set a property with a given value. More... | |
virtual std::shared_ptr< WCondition > | getUpdateCondition () const |
This method returns a condition which gets fired whenever the property changes somehow. More... | |
WPropInt | toPropInt () |
Helper converts this instance to its native type. More... | |
WPropDouble | toPropDouble () |
Helper converts this instance to its native type. More... | |
WPropBool | toPropBool () |
Helper converts this instance to its native type. More... | |
WPropString | toPropString () |
Helper converts this instance to its native type. More... | |
WPropFilename | toPropFilename () |
Helper converts this instance to its native type. More... | |
WPropSelection | toPropSelection () |
Helper converts this instance to its native type. More... | |
WPropColor | toPropColor () |
Helper converts this instance to its native type. More... | |
WPropPosition | toPropPosition () |
Helper converts this instance to its native type. More... | |
WPropTrigger | toPropTrigger () |
Helper converts this instance to its native type. More... | |
WPropMatrix4X4 | toPropMatrix4X4 () |
Helper converts this instance to its native type. More... | |
WPropTransferFunction | toPropTransferFunction () |
Helper converts this instance to its native type. More... | |
WPropGroup | toPropGroup () |
Helper converts this instance to its native type. More... | |
WPropInterval | toPropInterval () |
Helper converts this instance to its native type. More... | |
std::shared_ptr< WPropertyGroupBase > | toPropGroupBase () |
Convert the property to a WPropertyGroupBase. More... | |
template<typename T > | |
std::shared_ptr< WPropertyVariable< T > > | toPropertyVariable () |
Helper converts this instance to an arbitrary type. More... | |
Static Public Member Functions | |
static PropertyConstraintMin | minConstraint (const T &min) |
Creates a new WPropertyConstraintMin for this WPropertyVariable. More... | |
static PropertyConstraintMax | maxConstraint (const T &max) |
Creates a new WPropertyConstraintMax for this WPropertyVariable. More... | |
Protected Member Functions | |
virtual void | updateType () |
Uses typeid() to set the proper type constant. More... | |
void | removeConstraints (PROPERTYCONSTRAINT_TYPE type, typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket ticket=ConstraintContainerType::WriteTicket()) |
Cleans list of constraints from all existing constrains of the specified type. More... | |
void | propertyChangeNotifier () |
This method gets called by WFlag whenever the value of the property changes. More... | |
Protected Attributes | |
boost::signals2::connection | m_notifierConnection |
The connection used for notification. More... | |
std::shared_ptr< ConstraintContainerType > | m_constraints |
A set of constraints applied on this property. More... | |
Protected Attributes inherited from WFlag< T > | |
std::shared_ptr< WCondition > | m_condition |
The condition to be used for waiting/notifying. More... | |
std::shared_ptr< WCondition > | m_valueChangeCondition |
This condition is fired whenever the value changes. More... | |
T | m_flag |
The flag value. More... | |
bool | m_changed |
Denotes whether the value has changed since the last reset. More... | |
Protected Attributes inherited from WPropertyBase | |
std::string | m_name |
Name of the property. More... | |
std::string | m_description |
Description of the property. More... | |
bool | m_hidden |
Flag denoting whether the property is hidden or not. More... | |
PROPERTY_TYPE | m_type |
Type of the PropertyVariable instance. More... | |
PROPERTY_PURPOSE | m_purpose |
The purpose of this property. More... | |
PropertyChangeSignalType | signal_PropertyChange |
Signal getting fired whenever the property changes. More... | |
std::shared_ptr< WConditionSet > | m_updateCondition |
Condition notified whenever something changes. More... | |
Private Attributes | |
bool | m_notYetSet |
This is true, if the user did not set a value until now using set. More... | |
Friends | |
class | WPropertyVariableTest |
Access for test class. More... | |
Additional Inherited Members | |
Protected Types inherited from WPropertyBase | |
typedef boost::signals2::signal< void(std::shared_ptr< WPropertyBase >)> | PropertyChangeSignalType |
Signal used for firing change signals. More... | |
A named property class with a concrete type.
Definition at line 54 of file WPropertyVariable.h.
typedef WSharedAssociativeContainer< std::set< std::shared_ptr< PropertyConstraint > > > WPropertyVariable< T >::ConstraintContainerType |
The alias for a shared container.
Definition at line 227 of file WPropertyVariable.h.
typedef std::shared_ptr< const WPropertyVariable< T > > WPropertyVariable< T >::ConstSPtr |
Convenience typedef for a shared_ptr of const WPropertyVariable.
Definition at line 67 of file WPropertyVariable.h.
typedef T WPropertyVariable< T >::DataType |
The type of the data of this property.
Definition at line 70 of file WPropertyVariable.h.
typedef std::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::PropertyConstraintMax |
Alias for max constraints.
It is an alias for convenience.
Definition at line 237 of file WPropertyVariable.h.
typedef std::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::PropertyConstraintMin |
Alias for min constraints.
It is an alias for convenience.
Definition at line 232 of file WPropertyVariable.h.
typedef std::shared_ptr< WPropertyVariable< T > > WPropertyVariable< T >::SPtr |
Convenience typedef for a shared_ptr of WPropertyVariable.
Definition at line 62 of file WPropertyVariable.h.
WPropertyVariable< T >::WPropertyVariable | ( | std::string | name, |
std::string | description, | ||
const T & | initial | ||
) |
Create an empty instance just containing a name.
name | the property name |
description | the property description |
initial | the initial value |
Definition at line 453 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_constraints, WPropertyBase::m_updateCondition, and WPropertyVariable< T >::updateType().
WPropertyVariable< T >::WPropertyVariable | ( | std::string | name, |
std::string | description, | ||
const T & | initial, | ||
std::shared_ptr< WCondition > | condition | ||
) |
Create an empty instance just containing a name.
This constructor allows an external condition to be used for notifiaction. This is practical if one would like to share a condition among several properties.
name | the property name |
description | the property description |
initial | the initial value |
condition | use this external condition for notification. |
Definition at line 467 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_constraints, WPropertyBase::m_updateCondition, and WPropertyVariable< T >::updateType().
WPropertyVariable< T >::WPropertyVariable | ( | std::string | name, |
std::string | description, | ||
const T & | initial, | ||
PropertyChangeNotifierType | notifier | ||
) |
Create an empty instance just containing a name.
This constructor allows an external callback to be used for notification.
name | the property name |
description | the property description |
initial | the initial value |
notifier | use this notifier for change callbacks. |
Definition at line 481 of file WPropertyVariable.h.
References WFlag< T >::getValueChangeCondition(), WPropertyVariable< T >::m_constraints, WPropertyVariable< T >::m_notifierConnection, WPropertyBase::m_updateCondition, WPropertyBase::signal_PropertyChange, and WPropertyVariable< T >::updateType().
WPropertyVariable< T >::WPropertyVariable | ( | std::string | name, |
std::string | description, | ||
const T & | initial, | ||
std::shared_ptr< WCondition > | condition, | ||
PropertyChangeNotifierType | notifier | ||
) |
Create an empty instance just containing a name.
This constructor allows an external callback and condition to be used for notification.
name | the property name |
description | the property description |
initial | the initial value |
notifier | use this notifier for change callbacks. |
condition | use this external condition for notification |
Definition at line 502 of file WPropertyVariable.h.
References WFlag< T >::getValueChangeCondition(), WPropertyVariable< T >::m_constraints, WPropertyVariable< T >::m_notifierConnection, WPropertyBase::m_updateCondition, WPropertyBase::signal_PropertyChange, and WPropertyVariable< T >::updateType().
|
explicit |
Copy constructor.
Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get created. The subscriptions to a signal are LOST as well as all listeners to a condition. The conditions you can grab using getValueChangeConditon and getCondition are not the same as in the original! This is because the class corresponds to the observer/observable pattern. You won't expect a clone to fire a condition if a original variable is changed (which after cloning is completely decoupled from the clone).
from | the instance to copy. |
Definition at line 523 of file WPropertyVariable.h.
References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, and WPropertyBase::m_updateCondition.
|
virtual |
Destructor.
Definition at line 551 of file WPropertyVariable.h.
References WFlag< T >::get().
|
virtual |
Determines whether the specified value is acceptable.
newValue | the new value. |
Reimplemented from WFlag< T >.
Definition at line 578 of file WPropertyVariable.h.
References WFlag< T >::accept(), and WFlag< T >::get().
void WPropertyVariable< T >::addConstraint | ( | std::shared_ptr< PropertyConstraint > | constraint | ) |
Add a new constraint.
This is useful to disallow several (custom) values for this property.
constraint | the new constraint. |
Definition at line 678 of file WPropertyVariable.h.
References WFlag< T >::get().
|
virtual |
This method clones a property and returns the clone.
It does a deep copy and, in contrast to a copy constructor, creates property with the correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls subscribed signal handlers are NOT copied.
Implements WPropertyBase.
Definition at line 565 of file WPropertyVariable.h.
int WPropertyVariable< T >::countConstraint | ( | PROPERTYCONSTRAINT_TYPE | type | ) |
Method searching the first appearance of a constrained with the specified type.
type | the type of the searched constraint |
Definition at line 768 of file WPropertyVariable.h.
References WFlag< T >::get().
|
virtual |
This method is useful to ensure, that there is a valid value in the property.
Assume the following situation. The property p got a min value of 10. p->setMin( 10 ). Now, p gets set by the GUI to 11. Now your module sets another min value: p->setMin( 15 ). As the property already has been set, the property can't decide what to do; it simply stays invalid. To ensure a valid value, you can use this method. It only sets the new value if the old value is invalid.
newValidValue | the new value to set. |
suppressNotification | true to avoid a firing condition. |
Definition at line 665 of file WPropertyVariable.h.
References WFlag< T >::set().
|
virtual |
Returns the current value as a string.
This is useful for debugging or project files. It is not implemented as << operator, since the << should also print min/max constraints and so on. This simply is the value.
Implements WPropertyBase.
Definition at line 609 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WStringConversion< T >::asString().
WPropertyVariable< T >::ConstraintContainerType WPropertyVariable< T >::getConstraints |
Returns all the current constraints of a WPropertyVariable.
They can be iterated using the provided access object.
Definition at line 817 of file WPropertyVariable.h.
std::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition |
Gets the condition, which gets notified whenever the list of constraints changes.
It is notified AFTER the write lock has been released so a read lock can be acquired in the callback.
Definition at line 689 of file WPropertyVariable.h.
std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyVariable< T >::getFirstConstraint | ( | PROPERTYCONSTRAINT_TYPE | type | ) |
Method searching the first appearance of a constrained with the specified type.
type | the type of the searched constraint |
Definition at line 750 of file WPropertyVariable.h.
References WFlag< T >::get().
Referenced by WPropertyVariableTest::testConstraintManagement().
std::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::getMax |
Gets the current maximum constraint value.
Definition at line 802 of file WPropertyVariable.h.
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
std::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::getMin |
Gets the current minimum constraint value.
Definition at line 787 of file WPropertyVariable.h.
|
static |
Creates a new WPropertyConstraintMax for this WPropertyVariable.
max | the maximum value of the property |
Definition at line 708 of file WPropertyVariable.h.
|
static |
Creates a new WPropertyConstraintMin for this WPropertyVariable.
min | the minimum value. |
Definition at line 702 of file WPropertyVariable.h.
|
protected |
This method gets called by WFlag whenever the value of the property changes.
It re-emits the signal with a this pointer
Definition at line 571 of file WPropertyVariable.h.
void WPropertyVariable< T >::removeConstraint | ( | PROPERTYCONSTRAINT_TYPE | type | ) |
Cleans list of constraints from all existing constrains of the specified type.
type | the type to remove. |
Definition at line 866 of file WPropertyVariable.h.
void WPropertyVariable< T >::removeConstraint | ( | std::shared_ptr< PropertyConstraint > | constraint | ) |
Removes the specified constraint if existent.
constraint | the constraint to remove. |
Definition at line 873 of file WPropertyVariable.h.
References WFlag< T >::get().
|
protected |
Cleans list of constraints from all existing constrains of the specified type.
type | the type to remove. |
ticket | the write ticket if already existent. |
Definition at line 823 of file WPropertyVariable.h.
References WFlag< T >::get().
std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyVariable< T >::replaceConstraint | ( | PROPERTYCONSTRAINT_TYPE | constraint, |
PROPERTYCONSTRAINT_TYPE | type | ||
) |
This replaces all existing constraints of a certain type by a new specified constraint.
constraint | the new constraint |
type | the type of constraints to replace |
Definition at line 741 of file WPropertyVariable.h.
void WPropertyVariable< T >::replaceConstraint | ( | std::shared_ptr< PropertyConstraint > | constraint, |
PROPERTYCONSTRAINT_TYPE | type | ||
) |
This replaces all existing constraints of a certain type by a new specified constraint.
constraint | the new constraint |
type | the type of constraints to replace |
Definition at line 730 of file WPropertyVariable.h.
References WFlag< T >::get().
|
virtual |
Sets the new value for this flag.
Also notifies waiting threads. After setting a value, changed() will be true.
value | the new value |
suppressNotification | true to avoid a firing condition. This is useful for resetting values. |
Reimplemented from WFlag< T >.
Definition at line 642 of file WPropertyVariable.h.
References WFlag< T >::set().
|
virtual |
Sets the value from the specified property to this one.
This is especially useful to copy a value without explicitly casting/knowing the dynamic type of the property.
value | the new value. |
recommendedOnly | if true, property types which support recommended values apply the given value as recommendation. |
Implements WPropertyBase.
Definition at line 620 of file WPropertyVariable.h.
|
virtual |
This methods allows properties to be set by a string value.
This is especially useful when a property is only available as string and the real type of the property is unknown. This is a shortcut for casting the property and then setting the lexically casted value.
value | the new value to set. |
Implements WPropertyBase.
Definition at line 594 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WStringConversion< T >::create().
std::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::setMax | ( | const T & | max | ) |
Set a maximum constraint.
max | the maximum value allowed. |
Definition at line 722 of file WPropertyVariable.h.
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
std::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::setMin | ( | const T & | min | ) |
Set a minimum constraint.
min | the minimum value allowed. |
Definition at line 714 of file WPropertyVariable.h.
|
virtual |
Sets the specified value as recommended value.
The difference to set is simple. If some value was set using the method set earlier, the setRecommendedValue call is ignored. This is very useful in modules, where incoming data yields some useful default values but you do not want to overwrite a user-value which might have been set.
value | the new value to set if the user did not yet set the value |
Definition at line 649 of file WPropertyVariable.h.
|
protectedvirtual |
Uses typeid() to set the proper type constant.
Reimplemented from WPropertyBase.
Definition at line 695 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WTypeIdentifier< T >::getType().
Referenced by WPropertyVariable< T >::WPropertyVariable().
|
friend |
Access for test class.
Definition at line 57 of file WPropertyVariable.h.
|
protected |
A set of constraints applied on this property.
Definition at line 443 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::WPropertyVariable().
|
protected |
The connection used for notification.
Definition at line 418 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::WPropertyVariable().
|
private |
This is true, if the user did not set a value until now using set.
Definition at line 449 of file WPropertyVariable.h.