OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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, 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  /**
84  * The minimal value the property should have
85  */
86  T m_min;
87 };
88 
89 template < typename T >
91  m_min( min )
92 {
93 }
94 
95 template < typename T >
97 {
98 }
99 
100 template < typename T >
101 bool WPropertyConstraintMin< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
102 {
103  return value >= m_min;
104 }
105 
106 template < typename T >
108 {
109  return m_min;
110 }
111 
112 template < typename T >
113 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMin< T >::getType()
114 {
115  return PC_MIN;
116 }
117 
118 template < typename T >
119 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMin< T >::clone()
120 {
121  return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMin< T >( *this ) );
122 }
123 
124 #endif // WPROPERTYCONSTRAINTMIN_H
125