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