OpenWalnut 1.2.5

WPropertyConstraintMin.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WPROPERTYCONSTRAINTMIN_H
00026 #define WPROPERTYCONSTRAINTMIN_H
00027 
00028 #include "../WPropertyTypes.h"
00029 #include "WPropertyConstraintTypes.h"
00030 
00031 /**
00032  * This class allows constraining properties using a minimum value and the corresponding >= operator.
00033  */
00034 template< typename T >
00035 class WPropertyConstraintMin: public WPropertyVariable< T >::PropertyConstraint
00036 {
00037 public:
00038     /**
00039      * Constructor.
00040      *
00041      * \param min the minimum value which the new property value should have.
00042      */
00043     explicit WPropertyConstraintMin( T min );
00044 
00045     /**
00046      * Destructor.
00047      */
00048     virtual ~WPropertyConstraintMin();
00049 
00050     /**
00051      * Checks whether the specified new value is larger or equal to the specified min value.
00052      *
00053      * \param property the property whose new value should be set.
00054      * \param value the new value to check
00055      *
00056      * \return true if value >= m_min
00057      */
00058     virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, T value );
00059 
00060     /**
00061      * Returns the current min value.
00062      *
00063      * \return the min value.
00064      */
00065     T getMin();
00066 
00067     /**
00068      * Allows simple identification of the real constraint type.
00069      *
00070      * \return the type
00071      */
00072     virtual PROPERTYCONSTRAINT_TYPE getType();
00073 
00074     /**
00075      * Method to clone the constraint and create a new one with the correct dynamic type.
00076      *
00077      * \return the constraint.
00078      */
00079     virtual boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone();
00080 
00081 private:
00082 
00083     /**
00084      * The minimal value the property should have
00085      */
00086     T m_min;
00087 };
00088 
00089 template < typename T >
00090 WPropertyConstraintMin< T >::WPropertyConstraintMin( T min ):
00091     m_min( min )
00092 {
00093 }
00094 
00095 template < typename T >
00096 WPropertyConstraintMin< T >::~WPropertyConstraintMin()
00097 {
00098 }
00099 
00100 template < typename T >
00101 bool WPropertyConstraintMin< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
00102 {
00103     return value >= m_min;
00104 }
00105 
00106 template < typename T >
00107 T WPropertyConstraintMin< T >::getMin()
00108 {
00109     return m_min;
00110 }
00111 
00112 template < typename T >
00113 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMin< T >::getType()
00114 {
00115     return PC_MIN;
00116 }
00117 
00118 template < typename T >
00119 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMin< T >::clone()
00120 {
00121     return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMin< T >( *this ) );
00122 }
00123 
00124 #endif  // WPROPERTYCONSTRAINTMIN_H
00125 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends