OpenWalnut
1.4.0
|
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, const 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 * The maximal value the property should have 00084 */ 00085 T m_max; 00086 }; 00087 00088 template < typename T > 00089 WPropertyConstraintMax< T >::WPropertyConstraintMax( T max ): 00090 m_max( max ) 00091 { 00092 } 00093 00094 template < typename T > 00095 WPropertyConstraintMax< T >::~WPropertyConstraintMax() 00096 { 00097 } 00098 00099 template < typename T > 00100 bool WPropertyConstraintMax< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, const T& value ) 00101 { 00102 return value <= m_max; 00103 } 00104 00105 template < typename T > 00106 T WPropertyConstraintMax< T >::getMax() 00107 { 00108 return m_max; 00109 } 00110 00111 template < typename T > 00112 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMax< T >::getType() 00113 { 00114 return PC_MAX; 00115 } 00116 00117 template < typename T > 00118 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMax< T >::clone() 00119 { 00120 return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMax< T >( *this ) ); 00121 } 00122 00123 #endif // WPROPERTYCONSTRAINTMAX_H