OpenWalnut  1.5.0dev
WPropertyConstraintMax.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 WPROPERTYCONSTRAINTMAX_H
26 #define WPROPERTYCONSTRAINTMAX_H
27 
28 #include <memory>
29 
30 #include "../WPropertyTypes.h"
31 #include "WPropertyConstraintTypes.h"
32 
33 /**
34  * This class allows constraining properties using a maximum value and the corresponding <= operator.
35  */
36 template< typename T >
38 {
39 public:
40  /**
41  * Constructor.
42  *
43  * \param max the maximum value which the new property value should have.
44  */
45  explicit WPropertyConstraintMax( T max );
46 
47  /**
48  * Destructor.
49  */
50  virtual ~WPropertyConstraintMax();
51 
52  /**
53  * Checks whether the specified new value is smaller or equal to the specified max value.
54  *
55  * \param property the property whose new value should be set.
56  * \param value the new value to check
57  *
58  * \return true if value <= m_max
59  */
60  virtual bool accept( std::shared_ptr< WPropertyVariable< T > > property, const T& value );
61 
62  /**
63  * Returns the current max value.
64  *
65  * \return the max value.
66  */
67  T getMax();
68 
69  /**
70  * Allows simple identification of the real constraint type.
71  *
72  * \return the type
73  */
74  virtual PROPERTYCONSTRAINT_TYPE getType();
75 
76  /**
77  * Method to clone the constraint and create a new one with the correct dynamic type.
78  *
79  * \return the constraint.
80  */
81  virtual std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone();
82 
83 private:
84  /**
85  * The maximal value the property should have
86  */
87  T m_max;
88 };
89 
90 template < typename T >
92  m_max( max )
93 {
94 }
95 
96 template < typename T >
98 {
99 }
100 
101 template < typename T >
102 bool WPropertyConstraintMax< T >::accept( std::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
103 {
104  return value <= m_max;
105 }
106 
107 template < typename T >
109 {
110  return m_max;
111 }
112 
113 template < typename T >
114 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMax< T >::getType()
115 {
116  return PC_MAX;
117 }
118 
119 template < typename T >
120 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMax< T >::clone()
121 {
122  return std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMax< T >( *this ) );
123 }
124 
125 #endif // WPROPERTYCONSTRAINTMAX_H
This class allows constraining properties using a maximum value and the corresponding <= operator.
T getMax()
Returns the current max value.
T m_max
The maximal value the property should have.
virtual PROPERTYCONSTRAINT_TYPE getType()
Allows simple identification of the real constraint type.
virtual ~WPropertyConstraintMax()
Destructor.
virtual bool accept(std::shared_ptr< WPropertyVariable< T > > property, const T &value)
Checks whether the specified new value is smaller or equal to the specified max value.
virtual std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone()
Method to clone the constraint and create a new one with the correct dynamic type.
WPropertyConstraintMax(T max)
Constructor.
A named property class with a concrete type.