25 #ifndef WPROPERTYVARIABLE_H
26 #define WPROPERTYVARIABLE_H
36 #include <boost/shared_ptr.hpp>
37 #include <boost/signals2.hpp>
39 #include "constraints/WPropertyConstraintIsDirectory.h"
40 #include "constraints/WPropertyConstraintMax.h"
41 #include "constraints/WPropertyConstraintMin.h"
42 #include "constraints/WPropertyConstraintNotEmpty.h"
43 #include "constraints/WPropertyConstraintPathExists.h"
44 #include "constraints/WPropertyConstraintSelectOnlyOne.h"
45 #include "constraints/WPropertyConstraintTypes.h"
46 #include "WCondition.h"
48 #include "WPropertyBase.h"
49 #include "WSharedAssociativeContainer.h"
50 #include "WSharedObjectTicketRead.h"
51 #include "WSharedObjectTicketWrite.h"
56 template<
typename T >
65 typedef boost::shared_ptr< WPropertyVariable< T > >
SPtr;
70 typedef boost::shared_ptr< const WPropertyVariable< T > >
ConstSPtr;
90 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition );
121 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition,
149 virtual boost::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 boost::shared_ptr< PropertyConstraint >
create( PROPERTYCONSTRAINT_TYPE type );
221 virtual boost::shared_ptr< PropertyConstraint >
clone() = 0;
245 void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
318 void replaceConstraint( boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type );
327 boost::shared_ptr< PropertyConstraint >
replaceConstraint( PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type );
341 void removeConstraint( boost::shared_ptr< PropertyConstraint > constraint );
350 boost::shared_ptr< PropertyConstraint >
getFirstConstraint( PROPERTYCONSTRAINT_TYPE type );
388 virtual bool set( boost::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( boost::shared_static_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 boost::shared_ptr< WPropertyVariable< T > > v = boost::shared_dynamic_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 boost::shared_ptr< WPropertyConstraintMin< T > > c = minConstraint( min );
717 replaceConstraint( c, PC_MIN );
721 template <
typename T >
724 boost::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 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
743 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
744 replaceConstraint( c, type );
748 template <
typename T >
749 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
758 if( ( *it )->getType() == type )
764 return boost::shared_ptr< PropertyConstraint >();
767 template <
typename T >
777 if( ( *it )->getType() == type )
786 template <
typename T >
790 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MIN );
794 return boost::shared_ptr< WPropertyConstraintMin< T > >();
801 template <
typename T >
805 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MAX );
809 return boost::shared_ptr< WPropertyConstraintMax< T > >();
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 >
901 #endif // WPROPERTYVARIABLE_H