OpenWalnut
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
core
common
constraints
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 >
35
class
WPropertyConstraintMax
:
public
WPropertyVariable
< T >
::PropertyConstraint
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,
const
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
* The maximal value the property should have
84
*/
85
T
m_max
;
86
};
87
88
template
<
typename
T >
89
WPropertyConstraintMax< T >::WPropertyConstraintMax
( T max ):
90
m_max( max )
91
{
92
}
93
94
template
<
typename
T >
95
WPropertyConstraintMax< T >::~WPropertyConstraintMax
()
96
{
97
}
98
99
template
<
typename
T >
100
bool
WPropertyConstraintMax< T >::accept
( boost::shared_ptr<
WPropertyVariable< T >
>
/* property */
,
const
T& value )
101
{
102
return
value <= m_max;
103
}
104
105
template
<
typename
T >
106
T
WPropertyConstraintMax< T >::getMax
()
107
{
108
return
m_max;
109
}
110
111
template
<
typename
T >
112
PROPERTYCONSTRAINT_TYPE
WPropertyConstraintMax< T >::getType
()
113
{
114
return
PC_MAX;
115
}
116
117
template
<
typename
T >
118
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyConstraintMax< T >::clone
()
119
{
120
return
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >(
new
WPropertyConstraintMax< T >
( *this ) );
121
}
122
123
#endif // WPROPERTYCONSTRAINTMAX_H
Generated by
1.8.1.2