OpenWalnut
1.4.0
|
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 (const T &newValue) |
Determines whether the specified value is acceptable. | |
virtual bool | ensureValidity (const 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 (const T &min) |
Set a minimum constraint. | |
PropertyConstraintMax | setMax (const 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, bool recommendedOnly=false) |
Sets the value from the specified property to this one. | |
virtual bool | set (const T &value, bool suppressNotification=false) |
Sets the new value for this flag. | |
virtual bool | setRecommendedValue (const T &value) |
Sets the specified value as recommended value. | |
Static Public Member Functions | |
static PropertyConstraintMin | minConstraint (const T &min) |
Creates a new WPropertyConstraintMin for this WPropertyVariable. | |
static PropertyConstraintMax | maxConstraint (const 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 55 of file WPropertyVariable.h.
typedef WSharedAssociativeContainer< std::set< boost::shared_ptr< PropertyConstraint > > > WPropertyVariable< T >::ConstraintContainerType |
The alias for a shared container.
Definition at line 225 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 WFlag< T >.
Definition at line 68 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 235 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 230 of file WPropertyVariable.h.
typedef boost::shared_ptr< WPropertyVariable< T > > WPropertyVariable< T >::SPtr |
Convenience typedef for a shared_ptr of WPropertyVariable.
Reimplemented from WFlag< T >.
Definition at line 63 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 451 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 465 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 479 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 500 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 521 of file WPropertyVariable.h.
References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, and WPropertyBase::m_updateCondition.
WPropertyVariable< T >::~WPropertyVariable | ( | ) | [virtual] |
bool WPropertyVariable< T >::accept | ( | const T & | newValue | ) | [virtual] |
Determines whether the specified value is acceptable.
newValue | the new value. |
Reimplemented from WFlag< T >.
Definition at line 576 of file WPropertyVariable.h.
References WFlag< T >::accept(), and WFlag< T >::get().
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 676 of file WPropertyVariable.h.
References WFlag< T >::get().
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 563 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 766 of file WPropertyVariable.h.
References WFlag< T >::get().
bool WPropertyVariable< T >::ensureValidity | ( | const 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 663 of file WPropertyVariable.h.
References WFlag< 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 607 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 815 of file WPropertyVariable.h.
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 687 of file WPropertyVariable.h.
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 748 of file WPropertyVariable.h.
References WFlag< T >::get().
Referenced by WPropertyVariableTest::testConstraintManagement().
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::getMax | ( | ) |
Gets the current maximum constraint value.
Definition at line 800 of file WPropertyVariable.h.
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::getMin | ( | ) |
Gets the current minimum constraint value.
Definition at line 785 of file WPropertyVariable.h.
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::maxConstraint | ( | const T & | max | ) | [static] |
Creates a new WPropertyConstraintMax for this WPropertyVariable.
max | the maximum value of the property |
Definition at line 706 of file WPropertyVariable.h.
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::minConstraint | ( | const T & | min | ) | [static] |
Creates a new WPropertyConstraintMin for this WPropertyVariable.
min | the minimum value. |
Definition at line 700 of file WPropertyVariable.h.
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 569 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 864 of file WPropertyVariable.h.
void WPropertyVariable< T >::removeConstraint | ( | boost::shared_ptr< PropertyConstraint > | constraint | ) |
Removes the specified constraint if existent.
constraint | the constraint to remove. |
Definition at line 871 of file WPropertyVariable.h.
References WFlag< T >::get().
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 821 of file WPropertyVariable.h.
References WFlag< T >::get().
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 728 of file WPropertyVariable.h.
References WFlag< T >::get().
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 739 of file WPropertyVariable.h.
bool WPropertyVariable< T >::set | ( | boost::shared_ptr< WPropertyBase > | value, |
bool | recommendedOnly = false |
||
) | [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 618 of file WPropertyVariable.h.
bool WPropertyVariable< T >::set | ( | const 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. |
Reimplemented from WFlag< T >.
Definition at line 640 of file WPropertyVariable.h.
References WFlag< 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 592 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WStringConversion< T >::create().
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::setMax | ( | const T & | max | ) |
Set a maximum constraint.
max | the maximum value allowed. |
Definition at line 720 of file WPropertyVariable.h.
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::setMin | ( | const T & | min | ) |
Set a minimum constraint.
min | the minimum value allowed. |
Definition at line 712 of file WPropertyVariable.h.
Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().
bool WPropertyVariable< T >::setRecommendedValue | ( | const 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 647 of file WPropertyVariable.h.
void WPropertyVariable< T >::updateType | ( | ) | [protected, virtual] |
Uses typeid() to set the proper type constant.
Reimplemented from WPropertyBase.
Definition at line 693 of file WPropertyVariable.h.
References PROPERTY_TYPE_HELPER::WTypeIdentifier< T >::getType().
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 441 of file WPropertyVariable.h.
Referenced by WPropertyVariable< T >::WPropertyVariable().
boost::signals2::connection WPropertyVariable< T >::m_notifierConnection [protected] |
The connection used for notification.
Definition at line 416 of file WPropertyVariable.h.
Referenced by 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 447 of file WPropertyVariable.h.