25 #ifndef WPROPERTYVARIABLE_H
26 #define WPROPERTYVARIABLE_H
34 #include <boost/signals2.hpp>
36 #include "WCondition.h"
38 #include "WPropertyBase.h"
39 #include "WSharedAssociativeContainer.h"
40 #include "WSharedObjectTicketRead.h"
41 #include "WSharedObjectTicketWrite.h"
42 #include "constraints/WPropertyConstraintIsDirectory.h"
43 #include "constraints/WPropertyConstraintMax.h"
44 #include "constraints/WPropertyConstraintMin.h"
45 #include "constraints/WPropertyConstraintNotEmpty.h"
46 #include "constraints/WPropertyConstraintPathExists.h"
47 #include "constraints/WPropertyConstraintSelectOnlyOne.h"
48 #include "constraints/WPropertyConstraintTypes.h"
53 template<
typename T >
62 typedef std::shared_ptr< WPropertyVariable< T > >
SPtr;
67 typedef std::shared_ptr< const WPropertyVariable< T > >
ConstSPtr;
90 WPropertyVariable( std::string name, std::string description,
const T& initial, std::shared_ptr< WCondition > condition );
121 WPropertyVariable( std::string name, std::string description,
const T& initial, std::shared_ptr< WCondition > condition,
149 virtual std::shared_ptr< WPropertyBase >
clone();
158 virtual bool accept(
const T& newValue );
171 virtual bool ensureValidity(
const T& newValidValue,
bool suppressNotification =
false );
204 virtual PROPERTYCONSTRAINT_TYPE
getType();
214 static std::shared_ptr< PropertyConstraint >
create( PROPERTYCONSTRAINT_TYPE type );
221 virtual std::shared_ptr< PropertyConstraint >
clone() = 0;
245 void addConstraint( std::shared_ptr< PropertyConstraint > constraint );
318 void replaceConstraint( std::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type );
327 std::shared_ptr< PropertyConstraint >
replaceConstraint( PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type );
350 std::shared_ptr< PropertyConstraint >
getFirstConstraint( PROPERTYCONSTRAINT_TYPE type );
388 virtual bool set( std::shared_ptr< WPropertyBase > value,
bool recommendedOnly =
false );
401 virtual bool set(
const T& value,
bool suppressNotification =
false );
452 template <
typename T >
466 template <
typename T >
468 WFlag< T >( condition, initial ),
480 template <
typename T >
501 template <
typename T >
504 WFlag< T >( condition, initial ),
522 template <
typename T >
527 m_notYetSet( from.m_notYetSet )
542 w->
get().insert( ( *iter )->clone() );
550 template <
typename T >
554 m_updateCondition->remove( m_constraints->getChangeCondition() );
557 m_notifierConnection.disconnect();
564 template <
typename T >
570 template <
typename T >
574 signal_PropertyChange( shared_from_this() );
577 template <
typename T >
587 acceptable &= ( *it )->accept( std::static_pointer_cast<
WPropertyVariable< T > >( shared_from_this() ), newValue );
593 template <
typename T >
602 catch(
const std::exception &e )
608 template <
typename T >
619 template <
typename T >
623 std::shared_ptr< WPropertyVariable< T > > v = std::dynamic_pointer_cast< WPropertyVariable< T > >( value );
626 if( recommendedOnly )
628 return setRecommendedValue( v->get() );
632 return set( v->get() );
641 template <
typename T >
648 template <
typename T >
654 bool ret = set( value );
664 template <
typename T >
677 template <
typename T >
682 l->
get().insert( constraint );
688 template <
typename T >
691 return m_constraints->getChangeCondition();
694 template <
typename T >
701 template <
typename T >
707 template <
typename T >
713 template <
typename T >
716 std::shared_ptr< WPropertyConstraintMin< T > > c = minConstraint( min );
717 replaceConstraint( c, PC_MIN );
721 template <
typename T >
724 std::shared_ptr< WPropertyConstraintMax< T > > c = maxConstraint( max );
725 replaceConstraint( c, PC_MAX );
729 template <
typename T >
735 removeConstraints( type, l );
736 l->
get().insert( constraint );
739 template <
typename T >
740 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
743 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
744 replaceConstraint( c, type );
748 template <
typename T >
749 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
758 if( ( *it )->getType() == type )
764 return std::shared_ptr< PropertyConstraint >();
767 template <
typename T >
777 if( ( *it )->getType() == type )
786 template <
typename T >
790 std::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MIN );
794 return std::shared_ptr< WPropertyConstraintMin< T > >();
798 return std::static_pointer_cast< WPropertyConstraintMin< T > >( c );
801 template <
typename T >
805 std::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MAX );
809 return std::shared_ptr< WPropertyConstraintMax< T > >();
813 return std::static_pointer_cast< WPropertyConstraintMax< T > >( c );
816 template<
typename T >
819 return m_constraints;
822 template <
typename T >
828 bool useLock = !ticket;
834 l = m_constraints->getWriteTicket();
840 if( ( *it )->getType() == type )
842 l->
get().erase( it++ );
857 l->suppressUnlockCondition();
865 template <
typename T >
872 template <
typename T >
878 if( l->
get().erase( constraint ) == 0 )
881 l->suppressUnlockCondition();
885 template <
typename T >
890 template <
typename T >
895 template <
typename T >
Class helping to create a new instance of the property content from an old one.
T create(const T &, const std::string str)
Creates a new instance of the type from a given string.
std::string asString(const T &v)
Creates a string from the specified value.
Class helping to adapt types specified as template parameter into an enum.
PROPERTY_TYPE getType()
Get type identifier of the template type T.
Class to encapsulate boost::condition_variable_any.
Class to have a simple notification/condition system for simple flags.
virtual bool accept(const T &newValue)
Determines whether the specified value is acceptable.
virtual const T & get(bool resetChangeState=false)
Operator returns value of the flag.
std::shared_ptr< WCondition > getValueChangeCondition()
Returns the condition denoting a value change.
virtual bool set(const T &value, bool suppressNotification=false)
Sets the new value for this flag.
Abstract base class for all properties.
std::shared_ptr< WConditionSet > m_updateCondition
Condition notified whenever something changes.
PropertyChangeSignalType signal_PropertyChange
Signal getting fired whenever the property changes.
boost::function< void(std::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
This class allows constraining properties using a maximum value and the corresponding <= operator.
This class allows constraining properties using a minimum value and the corresponding >= operator.
Class building the base for user defined constraints on a property instance.
virtual PROPERTYCONSTRAINT_TYPE getType()
Allows simple identification of the real constraint type.
virtual bool accept(std::shared_ptr< WPropertyVariable< T > > property, const T &value)=0
This method decides whether the specified value is valid for a specific property.
PropertyConstraint()
Default constructor.
virtual std::shared_ptr< PropertyConstraint > clone()=0
Method to clone the constraint and create a new one with the correct dynamic type.
virtual ~PropertyConstraint()
Destructor.
static std::shared_ptr< PropertyConstraint > create(PROPERTYCONSTRAINT_TYPE type)
This method creates a constraint using the specified type.
A named property class with a concrete type.
virtual bool setRecommendedValue(const T &value)
Sets the specified value as recommended value.
virtual bool setAsString(std::string value)
This methods allows properties to be set by a string value.
void addConstraint(std::shared_ptr< PropertyConstraint > constraint)
Add a new constraint.
PropertyConstraintMin setMin(const T &min)
Set a minimum constraint.
virtual ~WPropertyVariable()
Destructor.
virtual bool ensureValidity(const T &newValidValue, bool suppressNotification=false)
This method is useful to ensure, that there is a valid value in the property.
virtual std::shared_ptr< WPropertyBase > clone()
This method clones a property and returns the clone.
PropertyConstraintMax setMax(const T &max)
Set a maximum constraint.
boost::signals2::connection m_notifierConnection
The connection used for notification.
std::shared_ptr< WPropertyConstraintMin< T > > PropertyConstraintMin
Alias for min constraints.
std::shared_ptr< WPropertyConstraintMax< T > > PropertyConstraintMax
Alias for max constraints.
PropertyConstraintMin getMin()
Gets the current minimum constraint value.
bool m_notYetSet
This is true, if the user did not set a value until now using set.
void replaceConstraint(std::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type)
This replaces all existing constraints of a certain type by a new specified constraint.
void propertyChangeNotifier()
This method gets called by WFlag whenever the value of the property changes.
virtual std::string getAsString()
Returns the current value as a string.
T DataType
The type of the data of this property.
PropertyConstraintMax getMax()
Gets the current maximum constraint value.
ConstraintContainerType getConstraints()
Returns all the current constraints of a WPropertyVariable.
WSharedAssociativeContainer< std::set< std::shared_ptr< PropertyConstraint > > > ConstraintContainerType
The alias for a shared container.
static PropertyConstraintMin minConstraint(const T &min)
Creates a new WPropertyConstraintMin for this WPropertyVariable.
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 removeConstraint(PROPERTYCONSTRAINT_TYPE type)
Cleans list of constraints from all existing constrains of the specified type.
std::shared_ptr< const WPropertyVariable< T > > ConstSPtr
Convenience typedef for a shared_ptr of const WPropertyVariable.
std::shared_ptr< PropertyConstraint > getFirstConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.
static PropertyConstraintMax maxConstraint(const T &max)
Creates a new WPropertyConstraintMax for this WPropertyVariable.
virtual void updateType()
Uses typeid() to set the proper type constant.
virtual bool accept(const T &newValue)
Determines whether the specified value is acceptable.
virtual bool set(std::shared_ptr< WPropertyBase > value, bool recommendedOnly=false)
Sets the value from the specified property to this one.
WPropertyVariable(std::string name, std::string description, const T &initial)
Create an empty instance just containing a name.
std::shared_ptr< WCondition > getContraintsChangedCondition()
Gets the condition, which gets notified whenever the list of constraints changes.
std::shared_ptr< WPropertyVariable< T > > SPtr
Convenience typedef for a shared_ptr of WPropertyVariable.
int countConstraint(PROPERTYCONSTRAINT_TYPE type)
Method searching the first appearance of a constrained with the specified type.
std::shared_ptr< ConstraintContainerType > m_constraints
A set of constraints applied on this property.
This class provides a common interface for thread-safe access to associative containers (set,...
T::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.