OpenWalnut 1.2.5

WPropertyConstraintMax.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 WPROPERTYCONSTRAINTMAX_H
00026 #define WPROPERTYCONSTRAINTMAX_H
00027 
00028 #include "../WPropertyTypes.h"
00029 #include "WPropertyConstraintTypes.h"
00030 
00031 /**
00032  * This class allows constraining properties using a maximum value and the corresponding <= operator.
00033  */
00034 template< typename T >
00035 class WPropertyConstraintMax: public WPropertyVariable< T >::PropertyConstraint
00036 {
00037 public:
00038     /**
00039      * Constructor.
00040      *
00041      * \param max the maximum value which the new property value should have.
00042      */
00043     explicit WPropertyConstraintMax( T max );
00044 
00045     /**
00046      * Destructor.
00047      */
00048     virtual ~WPropertyConstraintMax();
00049 
00050     /**
00051      * Checks whether the specified new value is smaller or equal to the specified max 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_max
00057      */
00058     virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, T value );
00059 
00060     /**
00061      * Returns the current max value.
00062      *
00063      * \return the max value.
00064      */
00065     T getMax();
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 maximal value the property should have
00085      */
00086     T m_max;
00087 };
00088 
00089 template < typename T >
00090 WPropertyConstraintMax< T >::WPropertyConstraintMax( T max ):
00091     m_max( max )
00092 {
00093 }
00094 
00095 template < typename T >
00096 WPropertyConstraintMax< T >::~WPropertyConstraintMax()
00097 {
00098 }
00099 
00100 template < typename T >
00101 bool WPropertyConstraintMax< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
00102 {
00103     return value <= m_max;
00104 }
00105 
00106 template < typename T >
00107 T WPropertyConstraintMax< T >::getMax()
00108 {
00109     return m_max;
00110 }
00111 
00112 template < typename T >
00113 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMax< T >::getType()
00114 {
00115     return PC_MAX;
00116 }
00117 
00118 template < typename T >
00119 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMax< T >::clone()
00120 {
00121     return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMax< T >( *this ) );
00122 }
00123 
00124 #endif  // WPROPERTYCONSTRAINTMAX_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends