OpenWalnut  1.4.0
WPropertyConstraintMin.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROPERTYCONSTRAINTMIN_H
26 #define WPROPERTYCONSTRAINTMIN_H
27 
28 #include "../WPropertyTypes.h"
29 #include "WPropertyConstraintTypes.h"
30 
31 /**
32  * This class allows constraining properties using a minimum value and the corresponding >= operator.
33  */
34 template< typename T >
36 {
37 public:
38  /**
39  * Constructor.
40  *
41  * \param min the minimum value which the new property value should have.
42  */
43  explicit WPropertyConstraintMin( T min );
44 
45  /**
46  * Destructor.
47  */
48  virtual ~WPropertyConstraintMin();
49 
50  /**
51  * Checks whether the specified new value is larger or equal to the specified min value.
52  *
53  * \param property the property whose new value should be set.
54  * \param value the new value to check
55  *
56  * \return true if value >= m_min
57  */
58  virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, const T& value );
59 
60  /**
61  * Returns the current min value.
62  *
63  * \return the min value.
64  */
65  T getMin();
66 
67  /**
68  * Allows simple identification of the real constraint type.
69  *
70  * \return the type
71  */
72  virtual PROPERTYCONSTRAINT_TYPE getType();
73 
74  /**
75  * Method to clone the constraint and create a new one with the correct dynamic type.
76  *
77  * \return the constraint.
78  */
79  virtual boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone();
80 
81 private:
82  /**
83  * The minimal value the property should have
84  */
85  T m_min;
86 };
87 
88 template < typename T >
90  m_min( min )
91 {
92 }
93 
94 template < typename T >
96 {
97 }
98 
99 template < typename T >
100 bool WPropertyConstraintMin< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
101 {
102  return value >= m_min;
103 }
104 
105 template < typename T >
107 {
108  return m_min;
109 }
110 
111 template < typename T >
112 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMin< T >::getType()
113 {
114  return PC_MIN;
115 }
116 
117 template < typename T >
118 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMin< T >::clone()
119 {
120  return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMin< T >( *this ) );
121 }
122 
123 #endif // WPROPERTYCONSTRAINTMIN_H
124 
virtual boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone()
Method to clone the constraint and create a new one with the correct dynamic type.
WPropertyConstraintMin(T min)
Constructor.
virtual PROPERTYCONSTRAINT_TYPE getType()
Allows simple identification of the real constraint type.
A named property class with a concrete type.
virtual bool accept(boost::shared_ptr< WPropertyVariable< T > > property, const T &value)
Checks whether the specified new value is larger or equal to the specified min value.
virtual ~WPropertyConstraintMin()
Destructor.
T m_min
The minimal value the property should have.
This class allows constraining properties using a minimum value and the corresponding >= operator...
T getMin()
Returns the current min value.