Commit 96a6dbd7 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - cleaned up some typedef mess in WPropertyVariable

parent dc958dec
......@@ -216,35 +216,10 @@ public:
virtual boost::shared_ptr< PropertyConstraint > clone() = 0;
};
/**
* For shortening: a type defining a shared set of WModule pointers.
*/
typedef std::set< boost::shared_ptr< PropertyConstraint > > ConstraintContainerType;
/**
* Const iterator for the prototype set.
*/
typedef typename ConstraintContainerType::const_iterator ConstraintContainerConstIteratorType;
/**
* Iterator for the prototype set.
*/
typedef typename ConstraintContainerType::iterator ConstraintContainerIteratorType;
/**
* The alias for a shared container.
*/
typedef WSharedAssociativeContainer< ConstraintContainerType > ConstraintSharedContainerType;
/**
* Alias for proper accessing the object. Read ticket.
*/
typedef typename ConstraintSharedContainerType::ReadTicket ReadTicket;
/**
* Alias for proper accessing the object. Write ticket.
*/
typedef typename ConstraintSharedContainerType::WriteTicket WriteTicket;
typedef WSharedAssociativeContainer< std::set< boost::shared_ptr< PropertyConstraint > > > ConstraintContainerType;
/**
* Alias for min constraints. It is an alias for convenience.
......@@ -269,7 +244,7 @@ public:
*
* \return the constraint access object
*/
ConstraintSharedContainerType getConstraints();
ConstraintContainerType getConstraints();
/**
* Gets the condition, which gets notified whenever the list of constraints changes. It is notified AFTER the write lock has been released so
......@@ -438,8 +413,8 @@ protected:
* \param ticket the write ticket if already existent.
*/
void removeConstraints( PROPERTYCONSTRAINT_TYPE type,
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket ticket
= ConstraintSharedContainerType::WriteTicket() );
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket ticket
= ConstraintContainerType::WriteTicket() );
/**
* This method gets called by WFlag whenever the value of the property changes. It re-emits the signal with a this pointer
......@@ -449,7 +424,7 @@ protected:
/**
* A set of constraints applied on this property.
*/
ConstraintSharedContainerType m_constraints;
boost::shared_ptr< ConstraintContainerType > m_constraints;
private:
};
......@@ -458,12 +433,12 @@ template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial ):
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description ),
m_constraints()
m_constraints( new ConstraintContainerType() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraints.getChangeCondition() );
m_updateCondition->add( m_constraints->getChangeCondition() );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
}
......@@ -471,12 +446,12 @@ template < typename T >
WPropertyVariable< T >::WPropertyVariable( std::string name, std::string description, const T& initial, boost::shared_ptr< WCondition > condition ):
WFlag< T >( condition, initial ),
WPropertyBase( name, description ),
m_constraints()
m_constraints( new ConstraintContainerType() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraints.getChangeCondition() );
m_updateCondition->add( m_constraints->getChangeCondition() );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
}
......@@ -485,12 +460,12 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
PropertyChangeNotifierType notifier ):
WFlag< T >( new WCondition(), initial ),
WPropertyBase( name, description ),
m_constraints()
m_constraints( new ConstraintContainerType() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraints.getChangeCondition() );
m_updateCondition->add( m_constraints->getChangeCondition() );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
// set custom notifier
......@@ -503,12 +478,12 @@ WPropertyVariable< T >::WPropertyVariable( std::string name, std::string descrip
PropertyChangeNotifierType notifier ):
WFlag< T >( condition, initial ),
WPropertyBase( name, description ),
m_constraints()
m_constraints( new ConstraintContainerType() )
{
updateType();
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraints.getChangeCondition() );
m_updateCondition->add( m_constraints->getChangeCondition() );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
// set custom notifier
......@@ -520,26 +495,26 @@ template < typename T >
WPropertyVariable< T >::WPropertyVariable( const WPropertyVariable< T >& from ):
WFlag< T >( from ),
WPropertyBase( from ),
m_constraints()
m_constraints( new ConstraintContainerType() )
{
// copy the constraints
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::ReadTicket l =
const_cast< WPropertyVariable< T >& >( from ).m_constraints.getReadTicket();
typename WPropertyVariable< T >::ConstraintContainerType::ReadTicket l =
const_cast< WPropertyVariable< T >& >( from ).m_constraints->getReadTicket();
// get write ticket too
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket w = m_constraints.getWriteTicket();
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket w = m_constraints->getWriteTicket();
// we need to make a deep copy here.
for ( ConstraintContainerIteratorType iter = l->get().begin(); iter != l->get().end(); ++iter )
for ( typename ConstraintContainerType::Iterator iter = l->get().begin(); iter != l->get().end(); ++iter )
{
// clone them to keep dynamic type
w->get().insert( ( *iter )->clone() );
}
// set constraint and change condition to update condition set of WPropertyBase
m_updateCondition->add( m_constraints.getChangeCondition() );
m_updateCondition->add( m_constraints->getChangeCondition() );
m_updateCondition->add( WFlag< T >::getValueChangeCondition() );
}
......@@ -547,13 +522,13 @@ template < typename T >
WPropertyVariable< T >::~WPropertyVariable()
{
// clean up
m_updateCondition->remove( m_constraints.getChangeCondition() );
m_updateCondition->remove( m_constraints->getChangeCondition() );
m_updateCondition->remove( WFlag< T >::getValueChangeCondition() );
m_notifierConnection.disconnect();
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket l = m_constraints.getWriteTicket();
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket l = m_constraints->getWriteTicket();
l->get().clear();
}
......@@ -574,11 +549,11 @@ template < typename T >
bool WPropertyVariable< T >::accept( T newValue )
{
// lock, lock vanishes if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::ReadTicket l = m_constraints.getReadTicket();
typename WPropertyVariable< T >::ConstraintContainerType::ReadTicket l = m_constraints->getReadTicket();
// iterate through the set
bool acceptable = WFlag< T >::accept( newValue );
for ( ConstraintContainerConstIteratorType it = l->get().begin(); it != l->get().end(); ++it )
for ( typename ConstraintContainerType::ConstIterator it = l->get().begin(); it != l->get().end(); ++it )
{
acceptable &= ( *it )->accept( boost::shared_static_cast< WPropertyVariable< T > >( shared_from_this() ), newValue );
}
......@@ -651,7 +626,7 @@ template < typename T >
void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstraint > constraint )
{
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket l = m_constraints.getWriteTicket();
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket l = m_constraints->getWriteTicket();
l->get().insert( constraint );
// unlock by hand
......@@ -661,7 +636,7 @@ void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstrain
template < typename T >
boost::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition()
{
return m_constraints.getChangeCondition();
return m_constraints->getChangeCondition();
}
template < typename T >
......@@ -703,7 +678,7 @@ template < typename T >
void WPropertyVariable< T >::replaceConstraint( boost::shared_ptr< PropertyConstraint > constraint, PROPERTYCONSTRAINT_TYPE type )
{
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket l = m_constraints.getWriteTicket();
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket l = m_constraints->getWriteTicket();
removeConstraints( type, l );
l->get().insert( constraint );
......@@ -723,10 +698,10 @@ boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyVariable< T >::getFirstConstraint( PROPERTYCONSTRAINT_TYPE type )
{
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::ReadTicket l = m_constraints.getReadTicket();
typename WPropertyVariable< T >::ConstraintContainerType::ReadTicket l = m_constraints->getReadTicket();
// search first appearance of a constraint of the specified type
for ( ConstraintContainerConstIteratorType it = l->get().begin(); it != l->get().end(); ++it )
for ( typename ConstraintContainerType::ConstIterator it = l->get().begin(); it != l->get().end(); ++it )
{
if ( ( *it )->getType() == type )
{
......@@ -741,11 +716,11 @@ template < typename T >
int WPropertyVariable< T >::countConstraint( PROPERTYCONSTRAINT_TYPE type )
{
// lock, unlocked if l looses focus
typename WPropertyVariable< T >::ConstraintSharedContainerType::ReadTicket l = m_constraints.getReadTicket();
typename WPropertyVariable< T >::ConstraintContainerType::ReadTicket l = m_constraints->getReadTicket();
int i = 0;
// search first appearance of a constraint of the specified type
for ( ConstraintContainerConstIteratorType it = l->get().begin(); it != l->get().end(); ++it )
for ( typename ConstraintContainerType::ConstIterator it = l->get().begin(); it != l->get().end(); ++it )
{
if ( ( *it )->getType() == type )
{
......@@ -787,16 +762,16 @@ boost::shared_ptr< WPropertyConstraintMax< T > > WPropertyVariable< T >::getMax(
}
template< typename T >
typename WPropertyVariable<T>::ConstraintSharedContainerType WPropertyVariable<T>::getConstraints()
typename WPropertyVariable<T>::ConstraintContainerType WPropertyVariable<T>::getConstraints()
{
return m_constraints;
}
template < typename T >
void WPropertyVariable< T >::removeConstraints( PROPERTYCONSTRAINT_TYPE type,
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket ticket )
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket ticket )
{
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket l = ticket;
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket l = ticket;
bool useLock = !ticket;
......@@ -804,11 +779,11 @@ void WPropertyVariable< T >::removeConstraints( PROPERTYCONSTRAINT_TYPE type,
if ( useLock )
{
// lock, unlocked if l looses focus
l = m_constraints.getWriteTicket();
l = m_constraints->getWriteTicket();
}
size_t nbErased = 0; // count how much items have been removed
for ( ConstraintContainerConstIteratorType it = l->get().begin(); it != l->get().end(); )
for ( typename ConstraintContainerType::ConstIterator it = l->get().begin(); it != l->get().end(); )
{
if ( ( *it )->getType() == type )
{
......@@ -839,14 +814,14 @@ template < typename T >
void WPropertyVariable< T >::removeConstraint( PROPERTYCONSTRAINT_TYPE type )
{
// simply forward the call
removeConstraints( type, typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket() );
removeConstraints( type, typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket() );
}
template < typename T >
void WPropertyVariable< T >::removeConstraint( boost::shared_ptr< PropertyConstraint > constraint )
{
// lock released automatically
typename WPropertyVariable< T >::ConstraintSharedContainerType::WriteTicket l = m_constraints.getWriteTicket();
typename WPropertyVariable< T >::ConstraintContainerType::WriteTicket l = m_constraints->getWriteTicket();
if ( l->get().erase( constraint ) == 0 )
{
......
......@@ -36,6 +36,17 @@ template < typename T >
class WSharedAssociativeContainer: public WSharedObject< T >
{
public:
// Some helpful typedefs
/**
* A typedef for the correct const iterator useful to traverse this sequence container.
*/
typedef typename T::const_iterator ConstIterator;
/**
* A typedef for the correct iterator to traverse this sequence container.
*/
typedef typename T::iterator Iterator;
/**
* Default constructor.
......
......@@ -37,6 +37,18 @@ class WSharedSequenceContainer: public WSharedObject< S >
{
public:
// Some helpful typedefs
/**
* A typedef for the correct const iterator useful to traverse this sequence container.
*/
typedef typename S::const_iterator ConstIterator;
/**
* A typedef for the correct iterator to traverse this sequence container.
*/
typedef typename S::iterator Iterator;
/**
* Default constructor.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment