OpenWalnut  1.4.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends
WPropertyVariable< T > Class Template Reference

A named property class with a concrete type. More...

#include <WPropertyVariable.h>

+ Inheritance diagram for WPropertyVariable< T >:

List of all members.

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< WConditiongetContraintsChangedCondition ()
 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

Detailed Description

template<typename T>
class WPropertyVariable< T >

A named property class with a concrete type.

Definition at line 55 of file WPropertyVariable.h.


Member Typedef Documentation

template<typename T>
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.

template<typename T>
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.

template<typename T>
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.

template<typename T>
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.

template<typename T>
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.


Constructor & Destructor Documentation

template<typename T >
WPropertyVariable< T >::WPropertyVariable ( std::string  name,
std::string  description,
const T &  initial 
)

Create an empty instance just containing a name.

Parameters:
namethe property name
descriptionthe property description
initialthe initial value

Definition at line 451 of file WPropertyVariable.h.

References WPropertyVariable< T >::m_constraints, WPropertyBase::m_updateCondition, and WPropertyVariable< T >::updateType().

template<typename T >
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.

Parameters:
namethe property name
descriptionthe property description
initialthe initial value
conditionuse 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().

template<typename T >
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.

Parameters:
namethe property name
descriptionthe property description
initialthe initial value
notifieruse this notifier for change callbacks.
Notes:
: instead of setting another notifier, you should consider using the callbacks the condition offers.
Notes:
: the notifiers gets connected to the notification callback of the internal condition. So be careful when using the condition ( getCondition() ) for other properties, since they would also share the 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().

template<typename T >
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.

Parameters:
namethe property name
descriptionthe property description
initialthe initial value
notifieruse this notifier for change callbacks.
conditionuse this external condition for notification
Notes:
: instead of setting another notifier, you should consider using the callbacks the condition offers.
Notes:
: the notifiers gets connected to the notification callback of the internal condition. So be careful when using the condition ( getCondition() ) for other properties, since they would also share the callbacks

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().

template<typename T >
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).

Parameters:
fromthe instance to copy.

Definition at line 521 of file WPropertyVariable.h.

References WFlag< T >::get(), WPropertyVariable< T >::m_constraints, and WPropertyBase::m_updateCondition.

template<typename T >
WPropertyVariable< T >::~WPropertyVariable ( ) [virtual]

Destructor.

Definition at line 549 of file WPropertyVariable.h.

References WFlag< T >::get().


Member Function Documentation

template<typename T >
bool WPropertyVariable< T >::accept ( const T &  newValue) [virtual]

Determines whether the specified value is acceptable.

Parameters:
newValuethe new value.
Returns:
true if it is a valid/acceptable value.

Reimplemented from WFlag< T >.

Definition at line 576 of file WPropertyVariable.h.

References WFlag< T >::accept(), and WFlag< T >::get().

template<typename T >
void WPropertyVariable< T >::addConstraint ( boost::shared_ptr< PropertyConstraint constraint)

Add a new constraint.

This is useful to disallow several (custom) values for this property.

Parameters:
constraintthe new constraint.

Definition at line 676 of file WPropertyVariable.h.

References WFlag< T >::get().

template<typename T >
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.

Notes:
this simply ensures the copy constructor of the runtime type is issued.
Returns:
the deep clone of this property.

Implements WPropertyBase.

Definition at line 563 of file WPropertyVariable.h.

template<typename T >
int WPropertyVariable< T >::countConstraint ( PROPERTYCONSTRAINT_TYPE  type)

Method searching the first appearance of a constrained with the specified type.

Parameters:
typethe type of the searched constraint
Returns:
the constraint, or NULL if none.

Definition at line 766 of file WPropertyVariable.h.

References WFlag< T >::get().

template<typename T >
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.

Parameters:
newValidValuethe new value to set.
suppressNotificationtrue to avoid a firing condition.
Returns:
true if the new value has been accepted ( if it was valid ) - for short true if the property NOW is valid

Definition at line 663 of file WPropertyVariable.h.

References WFlag< T >::set().

template<typename T >
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.

Returns:
the value as a string.

Implements WPropertyBase.

Definition at line 607 of file WPropertyVariable.h.

References PROPERTY_TYPE_HELPER::WStringConversion< T >::asString().

Returns all the current constraints of a WPropertyVariable.

They can be iterated using the provided access object.

Returns:
the constraint access object

Definition at line 815 of file WPropertyVariable.h.

template<typename T >
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.

Returns:
the condition.

Definition at line 687 of file WPropertyVariable.h.

template<typename T >
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.

Parameters:
typethe type of the searched constraint
Returns:
the constraint, or NULL if none.

Definition at line 748 of file WPropertyVariable.h.

References WFlag< T >::get().

Referenced by WPropertyVariableTest::testConstraintManagement().

template<typename T >
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::getMax ( )

Gets the current maximum constraint value.

Returns:
the maximum constraint, or NULL if none.

Definition at line 800 of file WPropertyVariable.h.

Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().

template<typename T >
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::getMin ( )

Gets the current minimum constraint value.

Returns:
the minimum constraint, or NULL if none.

Definition at line 785 of file WPropertyVariable.h.

template<typename T >
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::maxConstraint ( const T &  max) [static]

Creates a new WPropertyConstraintMax for this WPropertyVariable.

Parameters:
maxthe maximum value of the property
Returns:
the new constraint.

Definition at line 706 of file WPropertyVariable.h.

template<typename T >
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::minConstraint ( const T &  min) [static]

Creates a new WPropertyConstraintMin for this WPropertyVariable.

Parameters:
minthe minimum value.
Returns:
the new constraint.

Definition at line 700 of file WPropertyVariable.h.

template<typename T >
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.

template<typename T >
void WPropertyVariable< T >::removeConstraint ( PROPERTYCONSTRAINT_TYPE  type)

Cleans list of constraints from all existing constrains of the specified type.

Parameters:
typethe type to remove.

Definition at line 864 of file WPropertyVariable.h.

template<typename T >
void WPropertyVariable< T >::removeConstraint ( boost::shared_ptr< PropertyConstraint constraint)

Removes the specified constraint if existent.

Parameters:
constraintthe constraint to remove.

Definition at line 871 of file WPropertyVariable.h.

References WFlag< T >::get().

template<typename T >
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.

Parameters:
typethe type to remove.
ticketthe write ticket if already existent.

Definition at line 821 of file WPropertyVariable.h.

References WFlag< T >::get().

template<typename T >
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.

Parameters:
constraintthe new constraint
typethe type of constraints to replace

Definition at line 728 of file WPropertyVariable.h.

References WFlag< T >::get().

template<typename T >
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.

Parameters:
constraintthe new constraint
typethe type of constraints to replace
Returns:
the constraint created

Definition at line 739 of file WPropertyVariable.h.

template<typename T >
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.

Parameters:
valuethe new value.
recommendedOnlyif true, property types which support recommended values apply the given value as recommendation.
Returns:
true if the value has been accepted.

Implements WPropertyBase.

Definition at line 618 of file WPropertyVariable.h.

template<typename T >
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.

Parameters:
valuethe new value
suppressNotificationtrue to avoid a firing condition. This is useful for resetting values.
Returns:
true if the value has been set successfully.
Notes:
set( get() ) == true
Notes:
this is defined here to help the compiler to disambiguate between WFlag::set and the WPropertyBase::set.

Reimplemented from WFlag< T >.

Definition at line 640 of file WPropertyVariable.h.

References WFlag< T >::set().

template<typename T >
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.

Parameters:
valuethe new value to set.
Returns:
true if value could be set.

Implements WPropertyBase.

Definition at line 592 of file WPropertyVariable.h.

References PROPERTY_TYPE_HELPER::WStringConversion< T >::create().

template<typename T >
boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::setMax ( const T &  max)

Set a maximum constraint.

Parameters:
maxthe maximum value allowed.
Returns:
the newly created constraint.

Definition at line 720 of file WPropertyVariable.h.

Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().

template<typename T >
boost::shared_ptr< WPropertyConstraintMin< T > > WPropertyVariable< T >::setMin ( const T &  min)

Set a minimum constraint.

Parameters:
minthe minimum value allowed.
Returns:
the newly created constraint.

Definition at line 712 of file WPropertyVariable.h.

Referenced by WPropertyVariableTest::testMinMaxWithSetAndAccept().

template<typename T >
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.

Parameters:
valuethe new value to set if the user did not yet set the value
Returns:
true if value has been set successfully.

Definition at line 647 of file WPropertyVariable.h.

template<typename T >
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().


Member Data Documentation

template<typename T>
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().

template<typename T>
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().

template<typename T>
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.


The documentation for this class was generated from the following file: