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