OpenWalnut  1.5.0dev
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 <memory>
29 
30 #include "../WPropertyTypes.h"
31 #include "WPropertyConstraintTypes.h"
32 
33 /**
34  * This class allows constraining properties to only be set if a isValid method returns true. This constraint is especially useful for class-type
35  * typenames T providing a isValid method.
36  */
37 template< typename T >
39 {
40 public:
41  /**
42  * Constructor.
43  */
45 
46  /**
47  * Destructor.
48  */
50 
51  /**
52  * Checks whether the specified new value is a valid, using T::isValid.
53  *
54  * \param property the property whose new value should be set.
55  * \param value the new value to check
56  *
57  * \return true if value.isValid()
58  */
59  virtual bool accept( std::shared_ptr< WPropertyVariable< T > > property, const T& value );
60 
61  /**
62  * Allows simple identification of the real constraint type.
63  *
64  * \return the type
65  */
66  virtual PROPERTYCONSTRAINT_TYPE getType();
67 
68  /**
69  * Method to clone the constraint and create a new one with the correct dynamic type.
70  *
71  * \return the constraint.
72  */
73  virtual std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone();
74 
75 private:
76 };
77 
78 template < typename T >
80 {
81 }
82 
83 template < typename T >
85 {
86 }
87 
88 template < typename T >
89 bool WPropertyConstraintIsValid< T >::accept( std::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
90 {
91  return value.isValid();
92 }
93 
94 template < typename T >
96 {
97  return PC_ISVALID;
98 }
99 
100 template < typename T >
101 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintIsValid< T >::clone()
102 {
103  return std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintIsValid< T >( *this ) );
104 }
105 
106 #endif // WPROPERTYCONSTRAINTISVALID_H
107 
This class allows constraining properties to only be set if a isValid method returns true.
virtual std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone()
Method to clone the constraint and create a new one with the correct dynamic type.
virtual PROPERTYCONSTRAINT_TYPE getType()
Allows simple identification of the real constraint type.
virtual bool accept(std::shared_ptr< WPropertyVariable< T > > property, const T &value)
Checks whether the specified new value is a valid, using T::isValid.
virtual ~WPropertyConstraintIsValid()
Destructor.
A named property class with a concrete type.