25 #ifndef WPROPERTYVARIABLE_H
26 #define WPROPERTYVARIABLE_H
34 #include <boost/shared_ptr.hpp>
35 #include <boost/signals2.hpp>
37 #include "constraints/WPropertyConstraintIsDirectory.h"
38 #include "constraints/WPropertyConstraintMax.h"
39 #include "constraints/WPropertyConstraintMin.h"
40 #include "constraints/WPropertyConstraintNotEmpty.h"
41 #include "constraints/WPropertyConstraintPathExists.h"
42 #include "constraints/WPropertyConstraintSelectOnlyOne.h"
43 #include "constraints/WPropertyConstraintTypes.h"
44 #include "WCondition.h"
46 #include "WPropertyBase.h"
47 #include "WSharedAssociativeContainer.h"
48 #include "WSharedObjectTicketRead.h"
49 #include "WSharedObjectTicketWrite.h"
54 template<
typename T >
63 typedef boost::shared_ptr< WPropertyVariable< T > >
SPtr;
68 typedef boost::shared_ptr< const WPropertyVariable< T > >
ConstSPtr;
88 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition );
119 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition,
147 virtual boost::shared_ptr< WPropertyBase >
clone();
156 virtual bool accept(
const T& newValue );
169 virtual bool ensureValidity(
const T& newValidValue,
bool suppressNotification =
false );
202 virtual PROPERTYCONSTRAINT_TYPE
getType();
212 static boost::shared_ptr< PropertyConstraint >
create( PROPERTYCONSTRAINT_TYPE type );
219 virtual boost::shared_ptr< PropertyConstraint >
clone() = 0;
243 void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
316 void replaceConstraint( boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type );
325 boost::shared_ptr< PropertyConstraint >
replaceConstraint( PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type );
339 void removeConstraint( boost::shared_ptr< PropertyConstraint > constraint );
348 boost::shared_ptr< PropertyConstraint >
getFirstConstraint( PROPERTYCONSTRAINT_TYPE type );
386 virtual bool set( boost::shared_ptr< WPropertyBase > value,
bool recommendedOnly =
false );
399 virtual bool set(
const T& value,
bool suppressNotification =
false );
450 template <
typename T >
464 template <
typename T >
466 WFlag< T >( condition, initial ),
478 template <
typename T >
499 template <
typename T >
502 WFlag< T >( condition, initial ),
520 template <
typename T >
525 m_notYetSet( from.m_notYetSet )
540 w->
get().insert( ( *iter )->clone() );
548 template <
typename T >
552 m_updateCondition->remove( m_constraints->getChangeCondition() );
555 m_notifierConnection.disconnect();
562 template <
typename T >
568 template <
typename T >
572 signal_PropertyChange( shared_from_this() );
575 template <
typename T >
585 acceptable &= ( *it )->accept( boost::static_pointer_cast<
WPropertyVariable< T > >( shared_from_this() ), newValue );
591 template <
typename T >
600 catch(
const std::exception &e )
606 template <
typename T >
617 template <
typename T >
621 boost::shared_ptr< WPropertyVariable< T > > v = boost::dynamic_pointer_cast<
WPropertyVariable< T > >( value );
624 if( recommendedOnly )
626 return setRecommendedValue( v->get() );
630 return set( v->get() );
639 template <
typename T >
646 template <
typename T >
652 bool ret = set( value );
662 template <
typename T >
675 template <
typename T >
680 l->
get().insert( constraint );
686 template <
typename T >
689 return m_constraints->getChangeCondition();
692 template <
typename T >
699 template <
typename T >
705 template <
typename T >
711 template <
typename T >
714 boost::shared_ptr< WPropertyConstraintMin< T > > c = minConstraint( min );
715 replaceConstraint( c, PC_MIN );
719 template <
typename T >
722 boost::shared_ptr< WPropertyConstraintMax< T > > c = maxConstraint( max );
723 replaceConstraint( c, PC_MAX );
727 template <
typename T >
733 removeConstraints( type, l );
734 l->
get().insert( constraint );
737 template <
typename T >
738 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
741 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
742 replaceConstraint( c, type );
746 template <
typename T >
747 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
756 if( ( *it )->getType() == type )
762 return boost::shared_ptr< PropertyConstraint >();
765 template <
typename T >
775 if( ( *it )->getType() == type )
784 template <
typename T >
788 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MIN );
792 return boost::shared_ptr< WPropertyConstraintMin< T > >();
799 template <
typename T >
803 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MAX );
807 return boost::shared_ptr< WPropertyConstraintMax< T > >();
814 template<
typename T >
817 return m_constraints;
820 template <
typename T >
826 bool useLock = !ticket;
832 l = m_constraints->getWriteTicket();
838 if( ( *it )->getType() == type )
840 l->
get().erase( it++ );
855 l->suppressUnlockCondition();
863 template <
typename T >
870 template <
typename T >
876 if( l->
get().erase( constraint ) == 0 )
879 l->suppressUnlockCondition();
883 template <
typename T >
888 template <
typename T >
893 template <
typename T >
899 #endif // WPROPERTYVARIABLE_H
bool m_notYetSet
This is true, if the user did not set a value until now using set.
boost::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
Class to have a simple notification/condition system for simple flags.
This class allows constraining properties using a maximum value and the corresponding <= operator...
boost::shared_ptr< WPropertyVariable< T > > SPtr
Convenience typedef for a shared_ptr of WPropertyVariable.
virtual bool accept(boost::shared_ptr< WPropertyVariable< T > > property, const T &value)=0
This method decides whether the specified value is valid for a specific property. ...
boost::shared_ptr< ConstraintContainerType > m_constraints
A set of constraints applied on this property.
boost::shared_ptr< WPropertyConstraintMax< T > > PropertyConstraintMax
Alias for max constraints.
void replaceConstraint(boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type)
This replaces all existing constraints of a certain type by a new specified constraint.
virtual boost::shared_ptr< WPropertyBase > clone()
This method clones a property and returns the clone.
std::string asString(const T &v)
Creates a string from the specified value.
virtual bool setAsString(std::string value)
This methods allows properties to be set by a string value.
virtual ~PropertyConstraint()
Destructor.
ConstraintContainerType getConstraints()
Returns all the current constraints of a WPropertyVariable.
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 propertyChangeNotifier()
This method gets called by WFlag whenever the value of the property changes.
static PropertyConstraintMin minConstraint(const T &min)
Creates a new WPropertyConstraintMin for this WPropertyVariable.
T create(const T &, const std::string str)
Creates a new instance of the type from a given string.
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.
virtual bool accept(const T &newValue)
Determines whether the specified value is acceptable.
A named property class with a concrete type.
boost::function< void(boost::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
boost::shared_ptr< WPropertyConstraintMin< T > > PropertyConstraintMin
Alias for min constraints.
PROPERTY_TYPE getType()
Get type identifier of the template type T.
virtual ~WPropertyVariable()
Destructor.
virtual PROPERTYCONSTRAINT_TYPE getType()
Allows simple identification of the real constraint type.
T::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
PropertyConstraintMin getMin()
Gets the current minimum constraint value.
PropertyConstraintMax setMax(const T &max)
Set a maximum constraint.
boost::shared_ptr< const WPropertyVariable< T > > ConstSPtr
Convenience typedef for a shared_ptr of const WPropertyVariable.
PropertyConstraintMax getMax()
Gets the current maximum constraint value.
boost::shared_ptr< WConditionSet > m_updateCondition
Condition notified whenever something changes.
boost::shared_ptr< PropertyConstraint > getFirstConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.
virtual void updateType()
Uses typeid() to set the proper type constant.
boost::shared_ptr< WCondition > getContraintsChangedCondition()
Gets the condition, which gets notified whenever the list of constraints changes. ...
boost::signals2::connection m_notifierConnection
The connection used for notification.
static PropertyConstraintMax maxConstraint(const T &max)
Creates a new WPropertyConstraintMax for this WPropertyVariable.
PropertyConstraintMin setMin(const T &min)
Set a minimum constraint.
PropertyChangeSignalType signal_PropertyChange
Signal getting fired whenever the property changes.
Abstract base class for all properties.
Class to encapsulate boost::condition_variable_any.
This class allows constraining properties using a minimum value and the corresponding >= operator...
virtual bool set(boost::shared_ptr< WPropertyBase > value, bool recommendedOnly=false)
Sets the value from the specified property to this one.
void addConstraint(boost::shared_ptr< PropertyConstraint > constraint)
Add a new constraint.
Class helping to create a new instance of the property content from an old one.
WSharedAssociativeContainer< std::set< boost::shared_ptr< PropertyConstraint > > > ConstraintContainerType
The alias for a shared container.
virtual bool set(const T &value, bool suppressNotification=false)
Sets the new value for this flag.
virtual const T & get(bool resetChangeState=false)
Operator returns value of the flag.
void removeConstraint(PROPERTYCONSTRAINT_TYPE type)
Cleans list of constraints from all existing constrains of the specified type.
This class provides a common interface for thread-safe access to associative containers (set...
virtual bool accept(const T &newValue)
Determines whether the specified value is acceptable.
static boost::shared_ptr< PropertyConstraint > create(PROPERTYCONSTRAINT_TYPE type)
This method creates a constraint using the specified type.
virtual bool setRecommendedValue(const T &value)
Sets the specified value as recommended value.
WPropertyVariable(std::string name, std::string description, const T &initial)
Create an empty instance just containing a name.
Class helping to adapt types specified as template parameter into an enum.
Class building the base for user defined constraints on a property instance.
virtual boost::shared_ptr< PropertyConstraint > clone()=0
Method to clone the constraint and create a new one with the correct dynamic type.
boost::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
boost::shared_ptr< WCondition > getValueChangeCondition()
Returns the condition denoting a value change.
virtual std::string getAsString()
Returns the current value as a string.
int countConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.
PropertyConstraint()
Default constructor.