25 #ifndef WPROPERTYVARIABLE_H
26 #define WPROPERTYVARIABLE_H
37 #ifndef BOOST_FILESYSTEM_VERSION
38 #define BOOST_FILESYSTEM_VERSION 2
40 #include <boost/filesystem.hpp>
41 #include <boost/lexical_cast.hpp>
42 #include <boost/thread.hpp>
44 #include "constraints/WPropertyConstraintIsDirectory.h"
45 #include "constraints/WPropertyConstraintMax.h"
46 #include "constraints/WPropertyConstraintMin.h"
47 #include "constraints/WPropertyConstraintNotEmpty.h"
48 #include "constraints/WPropertyConstraintPathExists.h"
49 #include "constraints/WPropertyConstraintSelectOnlyOne.h"
50 #include "constraints/WPropertyConstraintTypes.h"
51 #include "WCondition.h"
54 #include "WPropertyBase.h"
55 #include "WSharedAssociativeContainer.h"
56 #include "WSharedObjectTicketRead.h"
57 #include "WSharedObjectTicketWrite.h"
62 template<
typename T >
71 typedef boost::shared_ptr< WPropertyVariable< T > >
SPtr;
76 typedef boost::shared_ptr< const WPropertyVariable< T > >
ConstSPtr;
96 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition );
127 WPropertyVariable( std::string name, std::string description,
const T& initial, boost::shared_ptr< WCondition > condition,
155 virtual boost::shared_ptr< WPropertyBase >
clone();
164 virtual bool accept( T newValue );
177 virtual bool ensureValidity( T newValidValue,
bool suppressNotification =
false );
211 virtual PROPERTYCONSTRAINT_TYPE
getType();
221 static boost::shared_ptr< PropertyConstraint >
create( PROPERTYCONSTRAINT_TYPE type );
228 virtual boost::shared_ptr< PropertyConstraint >
clone() = 0;
252 void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
325 void replaceConstraint( boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type );
334 boost::shared_ptr< PropertyConstraint >
replaceConstraint( PROPERTYCONSTRAINT_TYPE constraint, PROPERTYCONSTRAINT_TYPE type );
348 void removeConstraint( boost::shared_ptr< PropertyConstraint > constraint );
357 boost::shared_ptr< PropertyConstraint >
getFirstConstraint( PROPERTYCONSTRAINT_TYPE type );
394 virtual bool set( boost::shared_ptr< WPropertyBase > value );
407 virtual bool set( T value,
bool suppressNotification = false );
460 template <
typename T >
474 template <
typename T >
476 WFlag< T >( condition, initial ),
488 template <
typename T >
509 template <
typename T >
512 WFlag< T >( condition, initial ),
530 template <
typename T >
535 m_notYetSet( from.m_notYetSet )
550 w->
get().insert( ( *iter )->clone() );
558 template <
typename T >
562 m_updateCondition->remove( m_constraints->getChangeCondition() );
565 m_notifierConnection.disconnect();
572 template <
typename T >
578 template <
typename T >
582 signal_PropertyChange( shared_from_this() );
585 template <
typename T >
595 acceptable &= ( *it )->accept( boost::shared_static_cast<
WPropertyVariable< T > >( shared_from_this() ), newValue );
601 template <
typename T >
610 catch(
const boost::bad_lexical_cast &e )
616 template <
typename T >
627 template <
typename T >
631 boost::shared_ptr< WPropertyVariable< T > > v = boost::shared_dynamic_cast<
WPropertyVariable< T > >( value );
634 return set( v->get() );
642 template <
typename T >
649 template <
typename T >
655 bool ret =
set( value );
665 template <
typename T >
678 template <
typename T >
683 l->
get().insert( constraint );
689 template <
typename T >
692 return m_constraints->getChangeCondition();
695 template <
typename T >
702 template <
typename T >
708 template <
typename T >
714 template <
typename T >
717 boost::shared_ptr< WPropertyConstraintMin< T > > c = minConstraint( min );
718 replaceConstraint( c, PC_MIN );
722 template <
typename T >
725 boost::shared_ptr< WPropertyConstraintMax< T > > c = maxConstraint( max );
726 replaceConstraint( c, PC_MAX );
730 template <
typename T >
736 removeConstraints( type, l );
737 l->
get().insert( constraint );
740 template <
typename T >
741 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
744 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
745 replaceConstraint( c, type );
749 template <
typename T >
750 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
759 if( ( *it )->getType() == type )
765 return boost::shared_ptr< PropertyConstraint >();
768 template <
typename T >
778 if( ( *it )->getType() == type )
787 template <
typename T >
791 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MIN );
795 return boost::shared_ptr< WPropertyConstraintMin< T > >();
802 template <
typename T >
806 boost::shared_ptr< PropertyConstraint > c = getFirstConstraint( PC_MAX );
810 return boost::shared_ptr< WPropertyConstraintMax< T > >();
817 template<
typename T >
820 return m_constraints;
823 template <
typename T >
829 bool useLock = !ticket;
835 l = m_constraints->getWriteTicket();
841 if( ( *it )->getType() == type )
843 l->
get().erase( it++ );
858 l->suppressUnlockCondition();
866 template <
typename T >
873 template <
typename T >
879 if( l->
get().erase( constraint ) == 0 )
882 l->suppressUnlockCondition();
886 template <
typename T >
891 template <
typename T >
896 template <
typename T >
902 #endif // WPROPERTYVARIABLE_H