00001 #ifndef _PROPERTYVALUECONSTRAINTRANGE_H_ 00002 #define _PROPERTYVALUECONSTRAINTRANGE_H_ 00003 00004 // 00005 // Copyright (C) 2004-2006 Autodesk, Inc. 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of version 2.1 of the GNU Lesser 00009 // General Public License as published by the Free Software Foundation. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 // 00020 00021 #ifdef _WIN32 00022 #pragma once 00023 #endif 00024 00025 #include <FdoStd.h> 00026 #include <Fdo/Schema/PropertyValueConstraint.h> 00027 #include <Fdo/Expression/DataValue.h> 00028 00029 /// \brief 00030 /// FdoPropertyValueConstraintRange is used to specify minimum and / or maximum allowed values for a particular property. 00031 /// It can be used for all data property types except for Boolean, BLOB, or CLOB. 00032 /// One or the other or both of MinValue and MaxValue must be specified. If both are specified, then MaxValue must be greater 00033 /// than or equal to MinValue and if either MinInclusive or MaxInclusive are false, then MaxValue must be greater than MinValue. 00034 /// MinValue and MaxValue if specified must be valid values for the property type. E.g. if the property is decimal(4,0), 00035 /// then the maximum possible MaxValue is 9999. 00036 /// If the data property definition includes a non-null default value, then this constraint is applied to that value as well. 00037 /// If the data property definition allows nulls, a null value is considered as being valid regardless of the range constraint. 00038 class FdoPropertyValueConstraintRange : public FdoPropertyValueConstraint 00039 { 00040 protected: 00041 /// Constructs a default instance of a FdoPropertyValueConstraintRange. 00042 FdoPropertyValueConstraintRange(); 00043 00044 /// Constructs an instance of a FdoPropertyValueConstraintRange using the specified 00045 /// arguments. 00046 FdoPropertyValueConstraintRange(FdoDataValue *minValue, FdoDataValue* maxValue); 00047 00048 virtual ~FdoPropertyValueConstraintRange(); 00049 00050 virtual void Dispose() 00051 { 00052 delete this; 00053 } 00054 public: 00055 00056 /// \brief 00057 /// Constructs an empty instance of an FdoPropertyValueConstraintRange. 00058 /// 00059 /// \return 00060 /// Returns an FdoPropertyValueConstraintRange 00061 /// 00062 FDO_API static FdoPropertyValueConstraintRange* Create( ); 00063 00064 /// \brief 00065 /// Constructs and populates an instance of an FdoPropertyValueConstraintRange. 00066 /// 00067 /// \param minValue 00068 /// Minimum allowed value 00069 /// \param maxValue 00070 /// Maximum allowed value 00071 /// 00072 /// \return 00073 /// Returns an FdoPropertyValueConstraintRange 00074 /// 00075 FDO_API static FdoPropertyValueConstraintRange* Create( FdoDataValue *minValue, FdoDataValue* maxValue ); 00076 00077 /// \brief 00078 /// Returns FdoPropertyValueConstraintType_Range type. 00079 /// 00080 /// \return 00081 /// Returns the constraint type 00082 /// 00083 FDO_API virtual FdoPropertyValueConstraintType GetConstraintType(); 00084 00085 /// \brief 00086 /// Get the minimum allowed value. The type of this is the same as the type of the property. 00087 /// E.g. if the property is int32, then this value is int32. 00088 /// 00089 /// \return 00090 /// Returns the minimum value 00091 /// 00092 FDO_API FdoDataValue* GetMinValue(); 00093 00094 /// \brief 00095 /// Set the minimum allowed value. 00096 /// 00097 /// \param value 00098 /// Minimum allowed value 00099 /// 00100 /// \return 00101 /// Returns nothing 00102 /// 00103 FDO_API void SetMinValue(FdoDataValue* value); 00104 00105 /// \brief 00106 /// Returns a bool to indicate if the minimum value is inclusive or exclusive. This is the difference between >= and >. 00107 /// This is a boolean type where true means inclusive. 00108 /// 00109 /// \return 00110 /// Returns true if the value is inclusive. false otherwise 00111 /// 00112 FDO_API bool GetMinInclusive(); 00113 00114 /// \brief 00115 /// Set the minimum value to inclusive or exclusive. This is the difference between >= and >. 00116 /// 00117 /// \param value 00118 /// This is a boolean type where true means inclusive. 00119 /// 00120 /// \return 00121 /// Returns nothing 00122 /// 00123 FDO_API void SetMinInclusive(bool value); 00124 00125 /// \brief 00126 /// Get the maximum allowed value. The type of this is the same as the type of the property. 00127 /// E.g. if the property is int32, then this value is int32. 00128 /// 00129 /// \return 00130 /// Returns the maximum value 00131 /// 00132 FDO_API FdoDataValue* GetMaxValue(); 00133 00134 /// \brief 00135 /// Set the maximum allowed value. 00136 /// 00137 /// \param value 00138 /// Maximum allowed value 00139 /// 00140 /// \return 00141 /// Returns nothing 00142 /// 00143 FDO_API void SetMaxValue(FdoDataValue* value); 00144 00145 /// \brief 00146 /// Returns a bool to indicate if the maximum value is inclusive or exclusive. This is the difference between <= and <. 00147 /// This is a boolean type where true means inclusive. 00148 /// 00149 /// \return 00150 /// Returns true if the value is inclusive. false otherwise 00151 /// 00152 FDO_API bool GetMaxInclusive(); 00153 00154 /// \brief 00155 /// Returns a bool to indicate if the maximum value is inclusive or exclusive. This is the difference between <= and <. 00156 /// This is a boolean type where true means inclusive. 00157 /// 00158 /// \return 00159 /// Returns true if the value is inclusive. false otherwise 00160 /// 00161 FDO_API void SetMaxInclusive(bool value); 00162 00163 /// \cond DOXYGEN-IGNORE 00164 // Public non-API functions for XML and Schema Merge support 00165 00166 /// Update this range constraint from the given value constraint. 00167 virtual void Set( FdoPropertyValueConstraint* pProperty, FdoString* parentName, FdoSchemaMergeContext* pContext ); 00168 00169 // \brief 00170 // Compares this range constraint with another one. 00171 // 00172 // \param value 00173 // The Property Value constraint to compare with 00174 // 00175 // \return 00176 // Returns true if this range constraint is the same as pConstraint 00177 // (same constraint type and all members have the same values). 00178 virtual bool Equals( FdoPropertyValueConstraint* pConstraint ); 00179 00180 // \brief 00181 // Checks if a constraint domain is contained within another 00182 // 00183 // \param value 00184 // The Property Value constraint to compare with 00185 // 00186 // \return 00187 // Returns true if this constraint's domain is a superset of the domain 00188 // for pConstraint (all values that do not violate pConstraint also do not 00189 // violate this constraint). 00190 virtual bool Contains( FdoPropertyValueConstraint* pConstraint ); 00191 00192 // \brief 00193 // Checks if the given value violates this constraint. 00194 // 00195 // \param value 00196 // The Property Value 00197 // 00198 // \return 00199 // Returns true if the value is null or is within this constraint's value range. 00200 // Returns false if the value does violate this constraint. 00201 virtual bool Contains( FdoDataValue* pValue ); 00202 00203 private: 00204 // \brief 00205 // Compares two data values 00206 // 00207 // \param myValue 00208 // The first property value 00209 // 00210 // \param theirValue 00211 // The second property value 00212 // 00213 // \return 00214 // Returns true if the values are equal or both null. 00215 bool ValueEquals( FdoPtr<FdoDataValue> myValue, FdoPtr<FdoDataValue> theirValue ); 00216 00217 // \brief 00218 // Converts data value to string, handling memory cleanup and null values. 00219 // 00220 // \param value 00221 // The data value 00222 // 00223 // \return 00224 // Returns the data value as a string. L"" if the value is null. 00225 FdoStringP ValueToString( FdoPtr<FdoDataValue> value ); 00226 00227 // Same as CompareEnd expect that some extra checks are done for 00228 // date ranges. If any of the component nullities of the values to 00229 // compare are different, then FdoCompareType_Undefined is returned. 00230 // For example, if one values is a DateTime but the other is a Time 00231 // then Undefined is returned. This causes Contains( FdoPropertyValueConstraint*) 00232 // to always return false if the component nullities of the range 00233 // endpoints differ. 00234 FdoCompareType CompareRangeEnd( FdoBoolean myInclusive, FdoPtr<FdoDataValue> myValue, FdoBoolean theirInclusive, FdoPtr<FdoDataValue> theirValue, FdoBoolean isMax ); 00235 00236 // \brief 00237 // Compares the ends of two range constraints. 00238 // 00239 // \param myInclusive 00240 // First constraint's inclusivity setting. When the first and second values are equal, the 00241 // inclusive settings are then checked: 00242 // When isMax is true, inclusive values are greater than exclusive values 00243 // When isMax is false, inclusive values are less than exclusive values 00244 // There is currently a limitation in that, for integral types, inclusive values are not checked 00245 // when the values differ by 1. Therefore, values are sometimes reported as not equal when 00246 // they are equal. 00247 // 00248 // \param myValue 00249 // Value from the first constraint 00250 // 00251 // \param myInclusive 00252 // Second constraint's inclusivity setting 00253 // 00254 // \param theirValue 00255 // Value from the second constraint 00256 // 00257 // \param isMax 00258 // Determines how null and not null values are compared: 00259 // true: values are maximum end of ranges. NULL values are considered to be greater than not null values. 00260 // false: they are the minimum ends. NULL values are considered to be less than not null values. 00261 // 00262 // \return 00263 // Returns: 00264 // FdoCompareType_Equal when first and second values are equal 00265 // FdoCompareType_Greater when the first value is greater than the second value 00266 // FdoCompareType_Less when the first value is less than the second value 00267 // FdoCompareType_Undefined when these two values have incompatible types. 00268 00269 FdoCompareType CompareEnd( FdoBoolean myInclusive, FdoPtr<FdoDataValue> myValue, FdoBoolean theirInclusive, FdoPtr<FdoDataValue> theirValue, FdoBoolean isMax ); 00270 00271 FdoDataValue* m_minValue; 00272 FdoDataValue* m_maxValue; 00273 bool m_isMinInclusive; 00274 bool m_isMaxInclusive; 00275 /// \endcond 00276 }; 00277 00278 #endif 00279 00280