OpenWalnut  1.3.1
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 "../WPropertyTypes.h"
29 #include "WPropertyConstraintTypes.h"
30 
31 /**
32  * This class allows constraining properties to be not empty. This is especially useful for strings. This works on all types
33  * providing an empty() member function (as std::string and boost::filesystem::path do).
34  */
35 template< typename T >
37 {
38 public:
39  /**
40  * Constructor.
41  */
42  explicit WPropertyConstraintNotEmpty();
43 
44  /**
45  * Destructor.
46  */
48 
49  /**
50  * Checks whether the specified new value is larger or equal to the specified min value.
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 >= m_min
56  */
57  virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, const 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 >
78 {
79 }
80 
81 template < typename T >
83 {
84 }
85 
86 template < typename T >
87 bool WPropertyConstraintNotEmpty< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, const T& value )
88 {
89  return !value.empty();
90 }
91 
92 template < typename T >
94 {
95  return PC_NOTEMPTY;
96 }
97 
98 template < typename T >
99 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintNotEmpty< T >::clone()
100 {
101  return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintNotEmpty< T >( *this ) );
102 }
103 
104 #endif // WPROPERTYCONSTRAINTNOTEMPTY_H
105