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 boost::shared_ptr < WPropertyVariable< T > > | SPtr |
Convenience typedef for a shared_ptr of WPropertyVariable. | |
typedef boost::shared_ptr < const WPropertyVariable< T > > | ConstSPtr |
Convenience typedef for a shared_ptr of const WPropertyVariable. | |
typedef WSharedAssociativeContainer < std::set< boost::shared_ptr < PropertyConstraint > > > | ConstraintContainerType |
The alias for a shared container. | |
typedef boost::shared_ptr < WPropertyConstraintMin< T > > | PropertyConstraintMin |
Alias for min constraints. | |
typedef boost::shared_ptr < WPropertyConstraintMax< T > > | PropertyConstraintMax |
Alias for max constraints. | |
Public Member Functions | |
WPropertyVariable (std::string name, std::string description, const T &initial) | |
Create an empty instance just containing a name. | |
WPropertyVariable (std::string name, std::string description, const T &initial, boost::shared_ptr< WCondition > condition) | |
Create an empty instance just containing a name. | |
WPropertyVariable (std::string name, std::string description, const T &initial, PropertyChangeNotifierType notifier) | |
Create an empty instance just containing a name. | |
WPropertyVariable (std::string name, std::string description, const T &initial, boost::shared_ptr< WCondition > condition, PropertyChangeNotifierType notifier) | |
Create an empty instance just containing a name. | |
WPropertyVariable (const WPropertyVariable< T > &from) | |
Copy constructor. | |
virtual | ~WPropertyVariable () |
Destructor. | |
virtual boost::shared_ptr < WPropertyBase > | clone () |
This method clones a property and returns the clone. | |
virtual bool | accept (T newValue) |
Determines whether the specified value is acceptable. | |
virtual bool | ensureValidity (T newValidValue, bool suppressNotification=false) |
This method is useful to ensure, that there is a valid value in the property. | |
void | addConstraint (boost::shared_ptr< PropertyConstraint > constraint) |
Add a new constraint. | |
ConstraintContainerType | getConstraints () |
Returns all the current constraints of a WPropertyVariable. | |
boost::shared_ptr< WCondition > | getContraintsChangedCondition () |
Gets the condition, which gets notified whenever the list of constraints changes. | |
PropertyConstraintMin | setMin (T min) |
Set a minimum constraint. | |
PropertyConstraintMax | setMax (T max) |
Set a maximum constraint. | |
PropertyConstraintMin | getMin () |
Gets the current minimum constraint value. | |
PropertyConstraintMax | getMax () |
Gets the current maximum constraint value. | |
void | replaceConstraint (boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type) |
This replaces all existing constraints of a certain type by a new specified constraint. | |
boost::shared_ptr < PropertyConstraint > | replaceConstraint (PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type) |
This replaces all existing constraints of a certain type by a new specified constraint. | |
void | removeConstraint (PROPERTYCONSTRAINT_TYPE type) |
Cleans list of constraints from all existing constrains of the specified type. | |
void | removeConstraint (boost::shared_ptr< PropertyConstraint > constraint) |
Removes the specified constraint if existent. | |
boost::shared_ptr < PropertyConstraint > | getFirstConstraint (PROPERTYCONSTRAINT_TYPE type) |
Method searching the first appearance of a constrained with the specified type. | |
int | countConstraint (PROPERTYCONSTRAINT_TYPE type) |
Method searching the first appearance of a constrained with the specified type. | |
virtual bool | setAsString (std::string value) |
This methods allows properties to be set by a string value. | |
virtual std::string | getAsString () |
Returns the current value as a string. | |
virtual bool | set (boost::shared_ptr< WPropertyBase > value) |
Sets the value from the specified property to this one. | |
virtual bool | set (T value, bool suppressNotification=false) |
Sets the new value for this flag. | |
virtual bool | setRecommendedValue (T value) |
Sets the specified value as recommended value. | |
Static Public Member Functions | |
static PropertyConstraintMin | minConstraint (T min) |
Creates a new WPropertyConstraintMin for this WPropertyVariable. | |
static PropertyConstraintMax | maxConstraint (T max) |
Creates a new WPropertyConstraintMax for this WPropertyVariable. | |
Protected Member Functions | |
virtual void | updateType () |
Uses typeid() to set the proper type constant. | |
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. | |
void | propertyChangeNotifier () |
This method gets called by WFlag whenever the value of the property changes. | |
Protected Attributes | |
boost::signals2::connection | m_notifierConnection |
The connection used for notification. | |
boost::shared_ptr < ConstraintContainerType > | m_constraints |
A set of constraints applied on this property. | |
Private Attributes | |
bool | m_notYetSet |
This is true, if the user did not set a value until now using set. | |
Friends | |
class | WPropertyVariableTest |
A named property class with a concrete type.
Definition at line 63 of file WPropertyVariable.h.
typedef WSharedAssociativeContainer< std::set< boost::shared_ptr< PropertyConstraint > > > WPropertyVariable< T >::ConstraintContainerType |
The alias for a shared container.
Definition at line 234 of file WPropertyVariable.h.
typedef boost::shared_ptr< const WPropertyVariable< T > > WPropertyVariable< T >::ConstSPtr |
Convenience typedef for a shared_ptr of const WPropertyVariable.
Reimplemented from WPropertyBase.
Definition at line 76 of file WPropertyVariable.h.
typedef boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::PropertyConstraintMax |
Alias for max constraints.
It is an alias for convenience.
Definition at line 244 of file WPropertyVariable.h.
typedef boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::PropertyConstraintMin |
Alias for min constraints.
It is an alias for convenience.
Definition at line 239 of file WPropertyVariable.h.
typedef boost::shared_ptr< WPropertyVariable< T > > WPropertyVariable< T >::SPtr |
Convenience typedef for a shared_ptr of WPropertyVariable.
Reimplemented from WPropertyBase.
Definition at line 71 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 461 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, | |||
boost::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 475 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 489 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, | |||
boost::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 510 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 | ( | const WPropertyVariable< T > & | from | ) | [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 531 of file WPropertyVariable.h.
References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, and WPropertyBase::m_updateCondition.
WPropertyVariable< T >::~WPropertyVariable | ( | ) | [virtual] |
Destructor.
Definition at line 559 of file WPropertyVariable.h.
References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, WPropertyVariable< T >::m_notifierConnection, and WPropertyBase::m_updateCondition.
bool WPropertyVariable< T >::accept | ( | T | newValue | ) | [virtual] |
Determines whether the specified value is acceptable.
newValue | the new value. |
Definition at line 586 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
Referenced by WPropertyVariable< T >::ensureValidity().
void WPropertyVariable< T >::addConstraint | ( | boost::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 679 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
boost::shared_ptr< WPropertyBase > WPropertyVariable< T >::clone | ( | ) | [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 573 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 769 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
bool WPropertyVariable< T >::ensureValidity | ( | T | newValidValue, | |
bool | suppressNotification = false | |||
) | [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 666 of file WPropertyVariable.h.
References WPropertyVariable< T >::accept(), and WPropertyVariable< T >::set().
std::string WPropertyVariable< T >::getAsString | ( | ) | [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 617 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 818 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_constraints.
boost::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 690 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_constraints.
boost::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 751 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
Referenced by WPropertyVariable< T >::getMax(), WPropertyVariable< T >::getMin(), and WPropertyVariableTest::testConstraintManagement().
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::getMax | ( | ) |
Gets the current maximum constraint value.
Definition at line 803 of file WPropertyVariable.h.
References WPropertyVariable< T >::getFirstConstraint().
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::getMin | ( | ) |
Gets the current minimum constraint value.
Definition at line 788 of file WPropertyVariable.h.
References WPropertyVariable< T >::getFirstConstraint().
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::maxConstraint | ( | T | max | ) | [static] |
Creates a new WPropertyConstraintMax for this WPropertyVariable.
max | the maximum value of the property |
Definition at line 709 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::setMax().
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::minConstraint | ( | T | min | ) | [static] |
Creates a new WPropertyConstraintMin for this WPropertyVariable.
min | the minimum value. |
Definition at line 703 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::setMin().
void WPropertyVariable< T >::propertyChangeNotifier | ( | ) | [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 579 of file WPropertyVariable.h.
References WPropertyBase::signal_PropertyChange.
void WPropertyVariable< T >::removeConstraint | ( | boost::shared_ptr< PropertyConstraint > | constraint | ) |
Removes the specified constraint if existent.
constraint | the constraint to remove. |
Definition at line 874 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
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 867 of file WPropertyVariable.h.
References WPropertyVariable< T >::removeConstraints().
void WPropertyVariable< T >::removeConstraints | ( | PROPERTYCONSTRAINT_TYPE | type, | |
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket | ticket = ConstraintContainerType::WriteTicket() | |||
) | [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 824 of file WPropertyVariable.h.
References WFlag< T >::get(), and WPropertyVariable< T >::m_constraints.
Referenced by WPropertyVariable< T >::removeConstraint(), and WPropertyVariable< T >::replaceConstraint().
void WPropertyVariable< T >::replaceConstraint | ( | boost::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 731 of file WPropertyVariable.h.
References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, and WPropertyVariable< T >::removeConstraints().
Referenced by WPropertyVariable< T >::replaceConstraint(), WPropertyVariable< T >::setMax(), and WPropertyVariable< T >::setMin().
boost::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 742 of file WPropertyVariable.h.
References WPropertyVariable< T >::PropertyConstraint::create(), and WPropertyVariable< T >::replaceConstraint().
bool WPropertyVariable< T >::set | ( | T | value, | |
bool | suppressNotification = false | |||
) | [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. |
Definition at line 643 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_notYetSet, and WPropertyVariable< T >::set().
bool WPropertyVariable< T >::set | ( | boost::shared_ptr< WPropertyBase > | value | ) | [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. |
Implements WPropertyBase.
Definition at line 628 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::ensureValidity(), and WPropertyVariable< T >::set().
bool WPropertyVariable< T >::setAsString | ( | std::string | value | ) | [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 602 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WStringConversion< T >::create().
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::setMax | ( | T | max | ) |
Set a maximum constraint.
max | the maximum value allowed. |
Definition at line 723 of file WPropertyVariable.h.
References WPropertyVariable< T >::maxConstraint(), and WPropertyVariable< T >::replaceConstraint().
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::setMin | ( | T | min | ) |
Set a minimum constraint.
min | the minimum value allowed. |
Definition at line 715 of file WPropertyVariable.h.
References WPropertyVariable< T >::minConstraint(), and WPropertyVariable< T >::replaceConstraint().
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
bool WPropertyVariable< T >::setRecommendedValue | ( | T | value | ) | [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 650 of file WPropertyVariable.h.
References WPropertyVariable< T >::m_notYetSet.
void WPropertyVariable< T >::updateType | ( | ) | [protected, virtual] |
Uses typeid() to set the proper type constant.
Reimplemented from WPropertyBase.
Definition at line 696 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WTypeIdentifier< T >::getType(), and WPropertyBase::m_type.
Referenced by WPropertyVariable< T >::WPropertyVariable().
boost::shared_ptr< ConstraintContainerType > WPropertyVariable< T >::m_constraints [protected] |
A set of constraints applied on this property.
Definition at line 450 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::accept(), WPropertyVariable< T >::addConstraint(), WPropertyVariable< T >::countConstraint(), WPropertyVariable< T >::getConstraints(), WPropertyVariable< T >::getContraintsChangedCondition(), WPropertyVariable< T >::getFirstConstraint(), WPropertyVariable< T >::removeConstraint(), WPropertyVariable< T >::removeConstraints(), WPropertyVariable< T >::replaceConstraint(), WPropertyVariable< T >::WPropertyVariable(), and WPropertyVariable< T >::~WPropertyVariable().
boost::signals2::connection WPropertyVariable< T >::m_notifierConnection [protected] |
The connection used for notification.
Definition at line 425 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::WPropertyVariable(), and WPropertyVariable< T >::~WPropertyVariable().
bool WPropertyVariable< T >::m_notYetSet [private] |
This is true, if the user did not set a value until now using set.
Definition at line 457 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::set(), and WPropertyVariable< T >::setRecommendedValue().