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 WPROPERTYCONSTRAINTISVALID_H 00026 #define WPROPERTYCONSTRAINTISVALID_H 00027 00028 #include "../WPropertyTypes.h" 00029 #include "WPropertyConstraintTypes.h" 00030 00031 /** 00032 * This class allows constraining properties to only be set if a isValid method returns true. This constraint is especially useful for class-type 00033 * typenames T providing a isValid method. 00034 */ 00035 template< typename T > 00036 class WPropertyConstraintIsValid: public WPropertyVariable< T >::PropertyConstraint 00037 { 00038 public: 00039 /** 00040 * Constructor. 00041 */ 00042 WPropertyConstraintIsValid(); 00043 00044 /** 00045 * Destructor. 00046 */ 00047 virtual ~WPropertyConstraintIsValid(); 00048 00049 /** 00050 * Checks whether the specified new value is a valid, using T::isValid. 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.isValid() 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 WPropertyConstraintIsValid< T >::WPropertyConstraintIsValid() 00078 { 00079 } 00080 00081 template < typename T > 00082 WPropertyConstraintIsValid< T >::~WPropertyConstraintIsValid() 00083 { 00084 } 00085 00086 template < typename T > 00087 bool WPropertyConstraintIsValid< T >::accept( boost::shared_ptr< WPropertyVariable< T > > /* property */, const T& value ) 00088 { 00089 return value.isValid(); 00090 } 00091 00092 template < typename T > 00093 PROPERTYCONSTRAINT_TYPE WPropertyConstraintIsValid< T >::getType() 00094 { 00095 return PC_ISVALID; 00096 } 00097 00098 template < typename T > 00099 boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint > WPropertyConstraintIsValid< T >::clone() 00100 { 00101 return boost::shared_ptr< typename WPropertyVariable< T >::PropertyConstraint >( new WPropertyConstraintIsValid< T >( *this ) ); 00102 } 00103 00104 #endif // WPROPERTYCONSTRAINTISVALID_H 00105