OpenWalnut  1.5.0dev
WPropertyConstraintSelectOnlyOne.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 WPROPERTYCONSTRAINTSELECTONLYONE_H
26 #define WPROPERTYCONSTRAINTSELECTONLYONE_H
27 
28 #include <memory>
29 
30 #include "../WPropertyTypes.h"
31 #include "WPropertyConstraintTypes.h"
32 
33 /**
34  * This class allows constraining selection properties to not allow selection of multiple items.
35  */
36 template < typename T >
38 {
39 public:
40  /**
41  * Constructor.
42  */
44 
45  /**
46  * Destructor.
47  */
49 
50  /**
51  * Checks whether the specified value is a directory or not.
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 the file/path is a directory
57  */
58  virtual bool accept( std::shared_ptr< WPropertyVariable< T > > property, const T& value );
59 
60  /**
61  * Allows simple identification of the real constraint type.
62  *
63  * \return the type
64  */
65  virtual PROPERTYCONSTRAINT_TYPE getType();
66 
67  /**
68  * Method to clone the constraint and create a new one with the correct dynamic type.
69  *
70  * \return the constraint.
71  */
72  virtual std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone();
73 
74 private:
75 };
76 
77 template < typename T >
79 {
80 }
81 
82 template < typename T >
84 {
85 }
86 
87 template < typename T >
88 bool WPropertyConstraintSelectOnlyOne< T >::accept( std::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
89 {
90  return ( value.size() <= 1 );
91 }
92 
93 template < typename T >
95 {
96  return PC_SELECTONLYONE;
97 }
98 
99 template < typename T >
100 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintSelectOnlyOne< T >::clone()
101 {
102  return std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintSelectOnlyOne< T >( *this ) );
103 }
104 
105 #endif // WPROPERTYCONSTRAINTSELECTONLYONE_H
106 
This class allows constraining selection properties to not allow selection of multiple items.
virtual bool accept(std::shared_ptr< WPropertyVariable< T > > property, const T &value)
Checks whether the specified value is a directory or not.
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.
A named property class with a concrete type.