OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPROPERTYCONSTRAINTNOTEMPTY_H 00026 #define WPROPERTYCONSTRAINTNOTEMPTY_H 00027 00028 #include "../WPropertyTypes.h" 00029 #include "WPropertyConstraintTypes.h" 00030 00031 /** 00032 * This class allows constraining properties to be not empty. This is especially useful for strings. This works on all types 00033 * providing an empty() member function (as std::string and boost::filesystem::path do). 00034 */ 00035 template< typename T > 00036 class WPropertyConstraintNotEmpty: public WPropertyVariable< T >::PropertyConstraint 00037 { 00038 public: 00039 /** 00040 * Constructor. 00041 */ 00042 explicit WPropertyConstraintNotEmpty(); 00043 00044 /** 00045 * Destructor. 00046 */ 00047 virtual ~WPropertyConstraintNotEmpty(); 00048 00049 /** 00050 * Checks whether the specified new value is larger or equal to the specified min value. 00051 * 00052 * \param property the property whose new value should be set. 00053 * \param value the new value to check 00054 * 00055 * \return true if value >= m_min 00056 */ 00057 virtual bool accept( boost::shared_ptr< WPropertyVariable< T > > property, const T& value ); 00058 00059 /** 00060 * Allows simple identification of the real constraint type. 00061 * 00062 * \return the type 00063 */ 00064 virtual PROPERTYCONSTRAINT_TYPE getType(); 00065 00066 /** 00067 * Method to clone the constraint and create a new one with the correct dynamic type. 00068 * 00069 * \return the constraint. 00070 */ 00071 virtual boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > clone(); 00072 00073 private: 00074 }; 00075 00076 template < typename T > 00077 WPropertyConstraintNotEmpty< T >::WPropertyConstraintNotEmpty() 00078 { 00079 } 00080 00081 template < typename T > 00082 WPropertyConstraintNotEmpty< T >::~WPropertyConstraintNotEmpty() 00083 { 00084 } 00085 00086 template < typename T > 00087 bool WPropertyConstraintNotEmpty< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, const T& value ) 00088 { 00089 return !value.empty(); 00090 } 00091 00092 template < typename T > 00093 PROPERTYCONSTRAINT_TYPE WPropertyConstraintNotEmpty< T >::getType() 00094 { 00095 return PC_NOTEMPTY; 00096 } 00097 00098 template < typename T > 00099 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintNotEmpty< T >::clone() 00100 { 00101 return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintNotEmpty< T >( *this ) ); 00102 } 00103 00104 #endif // WPROPERTYCONSTRAINTNOTEMPTY_H 00105