OpenWalnut
1.2.5
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
core
common
constraints
WPropertyConstraintIsValid.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 WPROPERTYCONSTRAINTISVALID_H
26
#define WPROPERTYCONSTRAINTISVALID_H
27
28
#include "../WPropertyTypes.h"
29
#include "WPropertyConstraintTypes.h"
30
31
/**
32
* This class allows constraining properties to only be set if a isValid method returns true. This constraint is especially useful for class-type
33
* typenames T providing a isValid method.
34
*/
35
template
<
typename
T >
36
class
WPropertyConstraintIsValid
:
public
WPropertyVariable
< T >
::PropertyConstraint
37
{
38
public
:
39
/**
40
* Constructor.
41
*/
42
WPropertyConstraintIsValid
();
43
44
/**
45
* Destructor.
46
*/
47
virtual
~WPropertyConstraintIsValid
();
48
49
/**
50
* Checks whether the specified new value is a valid, using T::isValid.
51
*
52
* \param property the property whose new value should be set.
53
* \param value the new value to check
54
*
55
* \return true if value.isValid()
56
*/
57
virtual
bool
accept
( boost::shared_ptr<
WPropertyVariable< T >
> property, T value );
58
59
/**
60
* Allows simple identification of the real constraint type.
61
*
62
* \return the type
63
*/
64
virtual
PROPERTYCONSTRAINT_TYPE
getType
();
65
66
/**
67
* Method to clone the constraint and create a new one with the correct dynamic type.
68
*
69
* \return the constraint.
70
*/
71
virtual
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
clone
();
72
73
private
:
74
};
75
76
template
<
typename
T >
77
WPropertyConstraintIsValid< T >::WPropertyConstraintIsValid
()
78
{
79
}
80
81
template
<
typename
T >
82
WPropertyConstraintIsValid< T >::~WPropertyConstraintIsValid
()
83
{
84
}
85
86
template
<
typename
T >
87
bool
WPropertyConstraintIsValid< T >::accept
( boost::shared_ptr<
WPropertyVariable< T >
>
/* property */
, T value )
88
{
89
return
value.isValid();
90
}
91
92
template
<
typename
T >
93
PROPERTYCONSTRAINT_TYPE
WPropertyConstraintIsValid< T >::getType
()
94
{
95
return
PC_ISVALID;
96
}
97
98
template
<
typename
T >
99
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >
WPropertyConstraintIsValid< T >::clone
()
100
{
101
return
boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >(
new
WPropertyConstraintIsValid< T >
( *this ) );
102
}
103
104
#endif // WPROPERTYCONSTRAINTISVALID_H
105
Generated by
1.8.1