OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 "../WPropertyTypes.h"
29 #include "WPropertyConstraintTypes.h"
30 
31 /**
32  * This class allows constraining properties using a maximum value and the corresponding <= operator.
33  */
34 template< typename T >
36 {
37 public:
38  /**
39  * Constructor.
40  *
41  * \param max the maximum value which the new property value should have.
42  */
43  explicit WPropertyConstraintMax( T max );
44 
45  /**
46  * Destructor.
47  */
48  virtual ~WPropertyConstraintMax();
49 
50  /**
51  * Checks whether the specified new value is smaller or equal to the specified max 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_max
57  */
58  virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, T value );
59 
60  /**
61  * Returns the current max value.
62  *
63  * \return the max value.
64  */
65  T getMax();
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 maximal value the property should have
85  */
86  T m_max;
87 };
88 
89 template < typename T >
91  m_max( max )
92 {
93 }
94 
95 template < typename T >
97 {
98 }
99 
100 template < typename T >
101 bool WPropertyConstraintMax< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, T value )
102 {
103  return value <= m_max;
104 }
105 
106 template < typename T >
108 {
109  return m_max;
110 }
111 
112 template < typename T >
113 PROPERTYCONSTRAINT_TYPE WPropertyConstraintMax< T >::getType()
114 {
115  return PC_MAX;
116 }
117 
118 template < typename T >
119 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintMax< T >::clone()
120 {
121  return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintMax< T >( *this ) );
122 }
123 
124 #endif // WPROPERTYCONSTRAINTMAX_H