Commit 06d449f3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - selection properties now work, some constraints added....

[CHANGE] - selection properties now work, some constraints added. WPropertyVariable updated to meet requirements
parent 8e1d30a5
...@@ -63,7 +63,7 @@ WItemSelector WItemSelector::newSelector( const std::string asString ) const ...@@ -63,7 +63,7 @@ WItemSelector WItemSelector::newSelector( const std::string asString ) const
return newSelector( l ); return newSelector( l );
} }
std::ostream& WItemSelector::operator<<( std::ostream& out ) std::ostream& WItemSelector::operator<<( std::ostream& out ) const
{ {
for ( WItemSelector::IndexList::const_iterator iter = m_selected.begin(); iter != m_selected.end(); ++iter ) for ( WItemSelector::IndexList::const_iterator iter = m_selected.begin(); iter != m_selected.end(); ++iter )
{ {
...@@ -78,8 +78,7 @@ std::ostream& WItemSelector::operator<<( std::ostream& out ) ...@@ -78,8 +78,7 @@ std::ostream& WItemSelector::operator<<( std::ostream& out )
std::ostream& operator<<( std::ostream& out, const WItemSelector& other ) std::ostream& operator<<( std::ostream& out, const WItemSelector& other )
{ {
out << other; return other.operator<<( out );
return out;
} }
bool WItemSelector::operator==( const WItemSelector& other ) const bool WItemSelector::operator==( const WItemSelector& other ) const
...@@ -107,3 +106,8 @@ WItemSelection::Item WItemSelector::at( size_t index ) const ...@@ -107,3 +106,8 @@ WItemSelection::Item WItemSelector::at( size_t index ) const
return m_selection->at( m_selected.at( index ) ); return m_selection->at( m_selected.at( index ) );
} }
bool WItemSelector::empty() const
{
return ( size() == 0 );
}
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
* *
* \return the output stream extended by the information of this selector * \return the output stream extended by the information of this selector
*/ */
std::ostream& operator<<( std::ostream& out ); std::ostream& operator<<( std::ostream& out ) const;
/** /**
* Gives the count of elements in the set of selectable items. This is \ref size + number of unselected items. * Gives the count of elements in the set of selectable items. This is \ref size + number of unselected items.
...@@ -113,6 +113,13 @@ public: ...@@ -113,6 +113,13 @@ public:
*/ */
virtual size_t size() const; virtual size_t size() const;
/**
* True if the selection is empty.
*
* \return true if nothing is selected.
*/
virtual bool empty() const;
/** /**
* Gets the item with the given index from the WItemSelection. This index does not equal the index of the same item for \ref at. This method * Gets the item with the given index from the WItemSelection. This index does not equal the index of the same item for \ref at. This method
* is useful to go through the list of ALL items (not only the selected). * is useful to go through the list of ALL items (not only the selected).
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "exceptions/WPropertyUnknown.h" #include "exceptions/WPropertyUnknown.h"
#include "exceptions/WPropertyNotUnique.h" #include "exceptions/WPropertyNotUnique.h"
#include "WPropertyHelper.h"
#include "WProperties.h" #include "WProperties.h"
WProperties::WProperties( std::string name, std::string description ): WProperties::WProperties( std::string name, std::string description ):
...@@ -239,7 +241,7 @@ WPropString WProperties::addProperty( std::string name, std::string description, ...@@ -239,7 +241,7 @@ WPropString WProperties::addProperty( std::string name, std::string description,
WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial, bool hide ) WPropFilename WProperties::addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial, bool hide )
{ {
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, hide ); WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) ); WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p; return p;
} }
...@@ -304,7 +306,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio ...@@ -304,7 +306,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
boost::shared_ptr< WCondition > condition, bool hide ) boost::shared_ptr< WCondition > condition, bool hide )
{ {
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, hide ); WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) ); WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p; return p;
} }
...@@ -373,7 +375,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio ...@@ -373,7 +375,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
WPropertyBase::PropertyChangeNotifierType notifier, bool hide ) WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{ {
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, notifier, hide ); WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, notifier, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) ); WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p; return p;
} }
...@@ -448,7 +450,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio ...@@ -448,7 +450,7 @@ WPropFilename WProperties::addProperty( std::string name, std::string descriptio
WPropertyBase::PropertyChangeNotifierType notifier, bool hide ) WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
{ {
WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, notifier, hide ); WPropFilename p = addProperty< WPVBaseTypes::PV_PATH >( name, description, initial, condition, notifier, hide );
p->addConstraint( WPVFilename::PropertyConstraint::create( PC_NOTEMPTY ) ); WPropertyHelper::PC_NOTEMPTY::addTo( p );
return p; return p;
} }
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WPropertyHelper.h"
namespace WPropertyHelper
{
namespace PC_SELECTONLYONE
{
void addTo( WPropSelection prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintSelectOnlyOne< WPVBaseTypes::PV_SELECTION > >(
new WPropertyConstraintSelectOnlyOne< WPVBaseTypes::PV_SELECTION >
) );
}
}
namespace PC_NOTEMPTY
{
void addTo( WPropSelection prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_SELECTION > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_SELECTION >
) );
}
void addTo( WPropString prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_STRING > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_STRING >
) );
}
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintNotEmpty< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintNotEmpty< WPVBaseTypes::PV_PATH >
) );
}
}
namespace PC_PATHEXISTS
{
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintPathExists< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintPathExists< WPVBaseTypes::PV_PATH >()
) );
}
}
namespace PC_ISDIRECTORY
{
void addTo( WPropFilename prop )
{
prop->addConstraint( boost::shared_ptr< WPropertyConstraintIsDirectory< WPVBaseTypes::PV_PATH > >(
new WPropertyConstraintIsDirectory< WPVBaseTypes::PV_PATH >()
) );
}
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WPROPERTYHELPER_H
#define WPROPERTYHELPER_H
#include <boost/shared_ptr.hpp>
#include "WPropertyVariable.h"
#include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
/**
* This namespace contains several utility functions to handle properties. Especially constraint helper to easily create constraints.
*/
namespace WPropertyHelper
{
/**
* Contains functions for easily adding constraints of type PC_SELECTONLYONE to properties compatible with this constraint.
*/
namespace PC_SELECTONLYONE
{
/**
* Add the PC_SELECTONLYONE constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropSelection prop );
}
/**
* Contains functions for easily adding constraints of type PC_NOTEMPTY to properties compatible with this constraint.
*/
namespace PC_NOTEMPTY
{
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropSelection prop );
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropString prop );
/**
* Add the PC_NOTEMPTY constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
/**
* Contains functions for easily adding constraints of type PC_PATHEXISTS to properties compatible with this constraint.
*/
namespace PC_PATHEXISTS
{
/**
* Add the PC_PATHEXISTS constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
/**
* Contains functions for easily adding constraints of type PC_ISDIRECTORY to properties compatible with this constraint.
*/
namespace PC_ISDIRECTORY
{
/**
* Add the PC_PATHEXISTS constraint to the property.
*
* \param prop the property where to add the constraint.
*/
void addTo( WPropFilename prop );
}
}
#endif // WPROPERTYHELPER_H
...@@ -22,5 +22,12 @@ ...@@ -22,5 +22,12 @@
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "constraints/WPropertyConstraintMin.h"
#include "constraints/WPropertyConstraintMax.h"
#include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
#include "WPropertyVariable.h" #include "WPropertyVariable.h"
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "WFlag.h" #include "WFlag.h"
#include "WPropertyBase.h" #include "WPropertyBase.h"
#include "WCondition.h"
#include "WSharedAssociativeContainer.h" #include "WSharedAssociativeContainer.h"
#include "constraints/WPropertyConstraintTypes.h" #include "constraints/WPropertyConstraintTypes.h"
...@@ -50,8 +51,8 @@ ...@@ -50,8 +51,8 @@
#include "constraints/WPropertyConstraintNotEmpty.h" #include "constraints/WPropertyConstraintNotEmpty.h"
#include "constraints/WPropertyConstraintPathExists.h" #include "constraints/WPropertyConstraintPathExists.h"
#include "constraints/WPropertyConstraintIsDirectory.h" #include "constraints/WPropertyConstraintIsDirectory.h"
#include "constraints/WPropertyConstraintSelectOnlyOne.h"
#include "WCondition.h"
/** /**
* A named property class with a concrete type. * A named property class with a concrete type.
...@@ -230,19 +231,10 @@ public: ...@@ -230,19 +231,10 @@ public:
void addConstraint( boost::shared_ptr< PropertyConstraint > constraint ); void addConstraint( boost::shared_ptr< PropertyConstraint > constraint );
/** /**
* Add a new constraint. It creates one for your with the specified type. * Returns all the current constraints of a WPropertyVariable. They can be iterated using the provided access object.
*
* \param constraint the type of constraint.
* *
* \return the constraint created and added. * \return the constraint access object
*/ */
boost::shared_ptr< PropertyConstraint > addConstraint( PROPERTYCONSTRAINT_TYPE constraint );
/**
* Returns all the current constraints of a WPropertyVariable. They can be iterated using the provided access object.
*
* \return the constraint access object
*/
ConstraintAccess getConstraints(); ConstraintAccess getConstraints();
/** /**
...@@ -558,15 +550,6 @@ void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstrain ...@@ -558,15 +550,6 @@ void WPropertyVariable< T >::addConstraint( boost::shared_ptr< PropertyConstrain
m_constraintsChanged->notify(); m_constraintsChanged->notify();
} }
template < typename T >
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyVariable< T >::addConstraint( PROPERTYCONSTRAINT_TYPE constraint )
{
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > c = PropertyConstraint::create( constraint );
addConstraint( c );
return c;
}
template < typename T > template < typename T >
boost::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition() boost::shared_ptr< WCondition > WPropertyVariable< T >::getContraintsChangedCondition()
{ {
...@@ -748,38 +731,5 @@ PROPERTYCONSTRAINT_TYPE WPropertyVariable< T >::PropertyConstraint::getType() ...@@ -748,38 +731,5 @@ PROPERTYCONSTRAINT_TYPE WPropertyVariable< T >::PropertyConstraint::getType()
return PC_UNKNOWN; return PC_UNKNOWN;
} }
template < typename T >
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyVariable< T >::PropertyConstraint::create( PROPERTYCONSTRAINT_TYPE type )
{
typename WPropertyVariable< T >::PropertyConstraint* c = NULL;
// simply create a new instance for all those constraints.
switch( type )
{
case PC_MIN: // min and max constraints can't be created this way since they need a construction parameter
WLogger::getLogger()->addLogMessage( "Minimum property constraints can't be created this way. Use setMin() instead.",
"PropertyConstraint::create", LL_WARNING );
break;
case PC_MAX:
WLogger::getLogger()->addLogMessage( "Maximum property constraints can't be created this way. Use setMax() instead.",
"PropertyConstraint::create", LL_WARNING );
break;
case PC_NOTEMPTY:
c = new WPropertyConstraintNotEmpty< T >();
break;
case PC_PATHEXISTS:
c = new WPropertyConstraintPathExists< T >();
break;
case PC_ISDIRECTORY:
c = new WPropertyConstraintIsDirectory< T >();
break;
default:
WLogger::getLogger()->addLogMessage( "The property constraint is unknown.", "PropertyConstraint::create", LL_WARNING );
break;
}
return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( c );
}
#endif // WPROPERTYVARIABLE_H #endif // WPROPERTYVARIABLE_H
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "../WPropertyTypes.h" #include "../WPropertyTypes.h"
#include "WPropertyConstraintTypes.h" #include "WPropertyConstraintTypes.h"
template< typename T > template < typename T >
class WPropertyVariable; class WPropertyVariable;
/** /**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WPropertyConstraintSelectOnlyOne.h"
#include "../WPropertyVariable.h"
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WPROPERTYCONSTRAINTSELECTONLYONE_H
#define WPROPERTYCONSTRAINTSELECTONLYONE_H
#include "../WPropertyTypes.h"
#include "WPropertyConstraintTypes.h"
template< typename T >
class WPropertyVariable;
/**
* This class allows constraining selection properties to not allow selection of multiple items.
*/
template < typename T >
class WPropertyConstraintSelectOnlyOne: public WPropertyVariable< T >::PropertyConstraint
{
public:
/**
* Constructor.
*/
explicit WPropertyConstraintSelectOnlyOne();
/**
* Destructor.
*/
virtual ~WPropertyConstraintSelectOnlyOne();
/**
* Checks whether the specified value is a directory or not.
*
* \param property the property whose new value should be set.
* \param value the new value to check
*
* \return true if the file/path is a directory
*/
virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, T value );
/**
* Allows simple identification of the real constraint type.
*
* \return the type
*/
virtual PROPERTYCONSTRAINT_TYPE getType();
private:
};
template < typename T >
WPropertyConstraintSelectOnlyOne< T >::WPropertyConstraintSelectOnlyOne()
{
}
template < typename T >
WPropertyConstraintSelectOnlyOne< T >::~WPropertyConstraintSelectOnlyOne()
{
}
template < typename T >
bool WPropertyConstraintSelectOnlyOne< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
{
return ( value.size() <= 1 );
}
template < typename T >
PROPERTYCONSTRAINT_TYPE WPropertyConstraintSelectOnlyOne< T >::getType()
{
return PC_SELECTONLYONE;
}
#endif // WPROPERTYCONSTRAINTSELECTONLYONE_H
...@@ -31,12 +31,14 @@ ...@@ -31,12 +31,14 @@
*/ */
typedef enum typedef enum
{ {
PC_UNKNOWN, // type ID for arbitrary WPropertyConstraint PC_UNKNOWN, // type ID for arbitrary WPropertyConstraint
PC_MIN, // type ID for WPropertyConstraintMin PC_MIN, // type ID for WPropertyConstraintMin
PC_MAX, // type ID for WPropertyConstraintMax PC_MAX, // type ID for WPropertyConstraintMax