OpenWalnut  1.5.0dev
WPropertyConstraintNotEmpty.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 WPROPERTYCONSTRAINTNOTEMPTY_H
26 #define WPROPERTYCONSTRAINTNOTEMPTY_H
27 
28 #include <memory>
29 
30 #include "../WPropertyTypes.h"
31 #include "WPropertyConstraintTypes.h"
32 
33 /**
34  * This class allows constraining properties to be not empty. This is especially useful for strings. This works on all types
35  * providing an empty() member function (as std::string and boost::filesystem::path do).
36  */
37 template< typename T >
39 {
40 public:
41  /**
42  * Constructor.
43  */
44  explicit WPropertyConstraintNotEmpty();
45 
46  /**
47  * Destructor.
48  */
50 
51  /**
52  * Checks whether the specified new value is larger or equal to the specified min value.
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 >= m_min
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 WPropertyConstraintNotEmpty< T >::accept( std::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
90 {
91  return !value.empty();
92 }
93 
94 template < typename T >
96 {
97  return PC_NOTEMPTY;
98 }
99 
100 template < typename T >
101 std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintNotEmpty< T >::clone()
102 {
103  return std::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintNotEmpty< T >( *this ) );
104 }
105 
106 #endif // WPROPERTYCONSTRAINTNOTEMPTY_H
107 
This class allows constraining properties to be not empty.
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 ~WPropertyConstraintNotEmpty()
Destructor.
virtual bool accept(std::shared_ptr< WPropertyVariable< T > > property, const T &value)
Checks whether the specified new value is larger or equal to the specified min value.
A named property class with a concrete type.