25 #ifndef WPROPERTYVARIABLE_H
26 #define WPROPERTYVARIABLE_H
35 #include <boost/shared_ptr.hpp>
38 #include <boost/signals2.hpp>
41 #include "constraints/WPropertyConstraintIsDirectory.h"
42 #include "constraints/WPropertyConstraintMax.h"
43 #include "constraints/WPropertyConstraintMin.h"
44 #include "constraints/WPropertyConstraintNotEmpty.h"
45 #include "constraints/WPropertyConstraintPathExists.h"
46 #include "constraints/WPropertyConstraintSelectOnlyOne.h"
47 #include "constraints/WPropertyConstraintTypes.h"
48 #include "WCondition.h"
50 #include "WPropertyBase.h"
51 #include "WSharedAssociativeContainer.h"
52 #include "WSharedObjectTicketRead.h"
53 #include "WSharedObjectTicketWrite.h"
58 template<
typename T >
67 typedef boost::shared_ptr< WPropertyVariable< T > >
SPtr;
72 typedef boost::shared_ptr< const WPropertyVariable< T > >
ConstSPtr;
92 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition );
123 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition,
151 virtual boost::shared_ptr< WPropertyBase >
clone();
160 virtual bool accept(
const T& newValue );
173 virtual bool ensureValidity(
const T& newValidValue,
bool suppressNotification =
false );
206 virtual PROPERTYCONSTRAINT_TYPE
getType();
216 static boost::shared_ptr< PropertyConstraint >
create( PROPERTYCONSTRAINT_TYPE type );
223 virtual boost::shared_ptr< PropertyConstraint >
clone() = 0;
247 void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
289 PropertyConstraintMin
setMin(
const T& min );
298 PropertyConstraintMax
setMax(
const T& max );
305 PropertyConstraintMin
getMin();
312 PropertyConstraintMax
getMax();
320 void replaceConstraint( boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type );
329 boost::shared_ptr< PropertyConstraint >
replaceConstraint( PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type );
343 void removeConstraint( boost::shared_ptr< PropertyConstraint > constraint );
352 boost::shared_ptr< PropertyConstraint >
getFirstConstraint( PROPERTYCONSTRAINT_TYPE type );
390 virtual bool set( boost::shared_ptr< WPropertyBase > value,
bool recommendedOnly =
false );
403 virtual bool set(
const T& value,
bool suppressNotification =
false );
454 template <
typename T >
458 m_constraints( new ConstraintContainerType() ),
468 template <
typename T >
470 WFlag< T >( condition, initial ),
472 m_constraints( new ConstraintContainerType() ),
482 template <
typename T >
487 m_constraints( new ConstraintContainerType() ),
503 template <
typename T >
506 WFlag< T >( condition, initial ),
508 m_constraints( new ConstraintContainerType() ),
524 template <
typename T >
528 m_constraints( new ConstraintContainerType() ),
529 m_notYetSet( from.m_notYetSet )
544 w->
get().insert( ( *iter )->clone() );
552 template <
typename T >
556 m_updateCondition->remove( m_constraints->getChangeCondition() );
559 m_notifierConnection.disconnect();
566 template <
typename T >
572 template <
typename T >
576 signal_PropertyChange( shared_from_this() );
579 template <
typename T >
589 acceptable &= ( *it )->accept( boost::static_pointer_cast<
WPropertyVariable< T > >( shared_from_this() ), newValue );
595 template <
typename T >
604 catch(
const std::exception &e )
610 template <
typename T >
621 template <
typename T >
625 boost::shared_ptr< WPropertyVariable< T > > v = boost::dynamic_pointer_cast<
WPropertyVariable< T > >( value );
628 if( recommendedOnly )
630 return setRecommendedValue( v->get() );
634 return set( v->get() );
643 template <
typename T >
650 template <
typename T >
656 bool ret = set( value );
666 template <
typename T >
679 template <
typename T >
684 l->
get().insert( constraint );
690 template <
typename T >
693 return m_constraints->getChangeCondition();
696 template <
typename T >
703 template <
typename T >
709 template <
typename T >
715 template <
typename T >
718 boost::shared_ptr< WPropertyConstraintMin< T > > c = minConstraint( min );
719 replaceConstraint( c, PC_MIN );
723 template <
typename T >
726 boost::shared_ptr< WPropertyConstraintMax< T > > c = maxConstraint( max );
727 replaceConstraint( c, PC_MAX );
731 template <
typename T >
737 removeConstraints( type, l );
738 l->
get().insert( constraint );
741 template <
typename T >
742 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
745 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
746 replaceConstraint( c, type );
750 template <
typename T >
751 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
760 if( ( *it )->getType() == type )
766 return boost::shared_ptr< PropertyConstraint >();
769 template <
typename T >
779 if( ( *it )->getType() == type )
788 template <
typename T >
792 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MIN );
796 return boost::shared_ptr< WPropertyConstraintMin< T > >();
803 template <
typename T >
807 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MAX );
811 return boost::shared_ptr< WPropertyConstraintMax< T > >();
818 template<
typename T >
821 return m_constraints;
824 template <
typename T >
830 bool useLock = !ticket;
836 l = m_constraints->getWriteTicket();
842 if( ( *it )->getType() == type )
844 l->
get().erase( it++ );
859 l->suppressUnlockCondition();
867 template <
typename T >
874 template <
typename T >
880 if( l->
get().erase( constraint ) == 0 )
883 l->suppressUnlockCondition();
887 template <
typename T >
892 template <
typename T >
897 template <
typename T >
903 #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.