00001 #ifndef _BOOLEANVALUE_H_ 00002 #define _BOOLEANVALUE_H_ 00003 // 00004 00005 // 00006 // Copyright (C) 2004-2006 Autodesk, Inc. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of version 2.1 of the GNU Lesser 00010 // General Public License as published by the Free Software Foundation. 00011 // 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // Lesser General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public 00018 // License along with this library; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 // 00021 00022 #ifdef _WIN32 00023 #pragma once 00024 #endif 00025 00026 #include <FdoStd.h> 00027 #include <Fdo/Expression/DataValue.h> 00028 00029 /// \brief 00030 /// The FdoBooleanValue class derives from FdoDataValue and represents a Boolean 00031 /// value. 00032 class FdoBooleanValue : public FdoDataValue 00033 { 00034 friend class FdoStringValue; 00035 friend class FdoDataValue; 00036 /// \cond DOXYGEN-IGNORE 00037 protected: 00038 /// \brief 00039 /// Constructs a default instance of an FdoBooleanValue with a 00040 /// value of null. 00041 /// 00042 /// \return 00043 /// Returns nothing 00044 /// 00045 FdoBooleanValue(); 00046 00047 /// \brief 00048 /// Constructs a default instance of an FdoBooleanValue using the specified 00049 /// arguments. 00050 /// 00051 /// \param value 00052 /// Input a Boolean value 00053 /// 00054 /// \return 00055 /// Returns nothing 00056 /// 00057 FdoBooleanValue(bool value); 00058 00059 /// \brief 00060 /// Default destructor for FdoBooleanValue. 00061 /// 00062 /// \return 00063 /// Returns nothing 00064 /// 00065 virtual ~FdoBooleanValue(); 00066 00067 virtual void Dispose(); 00068 00069 /// \endcond 00070 00071 public: 00072 /// \brief 00073 /// Constructs a default instance of an FdoBooleanValue with a value of null. 00074 /// 00075 /// \return 00076 /// Returns the created FdoBooleanValue 00077 /// 00078 FDO_API static FdoBooleanValue* Create(); 00079 00080 /// \brief 00081 /// Constructs a default instance of an FdoBooleanValue using the specified arguments. 00082 /// 00083 /// \param value 00084 /// Input a Boolean value 00085 /// 00086 /// \return 00087 /// Returns the created FdoBooleanValue 00088 /// 00089 FDO_API static FdoBooleanValue* Create(bool value); 00090 00091 /// \brief 00092 /// Gets the data type of the FdoBooleanValue. 00093 /// 00094 /// \return 00095 /// Returns an FdoDataType 00096 /// 00097 FDO_API FdoDataType GetDataType(); 00098 00099 /// \brief 00100 /// Gets the FdoBooleanValue. 00101 /// 00102 /// \return 00103 /// Returns a Boolean value 00104 /// 00105 FDO_API bool GetBoolean(); 00106 00107 /// \brief 00108 /// Sets the Boolean value. 00109 /// 00110 /// \param value 00111 /// Input a Boolean value 00112 /// 00113 /// \return 00114 /// Returns nothing 00115 /// 00116 FDO_API void SetBoolean(bool value); 00117 00118 /// \brief 00119 /// Overrides FdoExpression.Process to pass the FdoBooleanValue to the appropriate 00120 /// expression processor operation. 00121 /// 00122 /// \param p 00123 /// Input the FdoIExpressionProcessor 00124 /// 00125 /// \return 00126 /// Returns nothing 00127 /// 00128 FDO_API void Process(FdoIExpressionProcessor* p); 00129 00130 /// \brief 00131 /// Returns the well defined text representation of this expression. 00132 /// 00133 /// \return 00134 /// Returns a character string. 00135 /// 00136 FDO_API FdoString* ToString(); 00137 00138 /// \brief 00139 /// A cast operator to get the Boolean value. 00140 /// 00141 /// \return 00142 /// Returns a Boolean value 00143 /// 00144 FDO_API operator bool() 00145 { 00146 return m_data; 00147 } 00148 00149 protected: 00150 /// \brief 00151 /// Constructs an instance of an FdoBooleanValue from another FdoDataValue. 00152 /// 00153 /// \param src 00154 /// Input the other FdoDataValue. Must be of one of the following types: 00155 /// FdoDataType_Boolean 00156 /// FdoDataType_Byte 00157 /// FdoDataType_Decimal 00158 /// FdoDataType_Double 00159 /// FdoDataType_Int16 00160 /// FdoDataType_Int32 00161 /// FdoDataType_Int64 00162 /// FdoDataType_Single 00163 /// FdoDataType_String 00164 /// - value must be "TRUE", "FALSE", or numeric. 00165 /// 00166 /// In all other cases, the src type is considered incompatible with this type. 00167 /// \param nullIfIncompatible 00168 /// Input will determine what to do if the source value cannot be converted to 00169 /// this type: 00170 /// true - return NULL. 00171 /// false - throw an exception 00172 /// 00173 /// \param shift 00174 /// Input for future use. 00175 /// \param truncate 00176 /// Input in the future will determine what to do if source value is numeric but 00177 /// not 0 or 1: 00178 /// true - set the FdoBooleanValue to true. 00179 /// false - behaviour depends on nullIfIncompatible: 00180 /// true - return NULL. 00181 /// false - throw an exception 00182 /// \return 00183 /// Returns an FdoBooleanValue, whose value is converted from the src value. 00184 /// If src value is numeric then: 00185 /// 0 is converted to false 00186 /// 1 is converted to true 00187 static FdoBooleanValue* Create( 00188 FdoDataValue* src, 00189 FdoBoolean nullIfIncompatible = false, 00190 FdoBoolean shift = true, 00191 FdoBoolean truncate = false 00192 ); 00193 00194 /// \brief 00195 /// Helper template for constructing FdoBooleanValue's from scalar values 00196 /// of various types. 00197 /// 00198 template <class T> static FdoBooleanValue* Convert( FdoDataValue* src, T val, bool nullIfIncompatible, bool truncate ) 00199 { 00200 FdoBooleanValue* ret = NULL; 00201 bool isNull = false; 00202 00203 if ( val == 0 ) 00204 { 00205 ret = FdoBooleanValue::Create(false); 00206 } 00207 else if ( (val == 1) || truncate ) 00208 { 00209 // Values other than 0 or 1 map to true but only if allowing 00210 // value truncation. 00211 ret = FdoBooleanValue::Create(true); 00212 } 00213 else if ( nullIfIncompatible ) 00214 { 00215 // Failed to convert, return null FdoBooleanValue 00216 ret = FdoBooleanValue::Create(); 00217 } 00218 else { 00219 // Failed to convert, error condition 00220 throw FdoExpressionException::Create( 00221 FdoException::NLSGetMessage( 00222 FDO_NLSID(EXPRESSION_24_BOOLEANTRUNCATED), 00223 src->ToString() 00224 ) 00225 ); 00226 } 00227 00228 return ret; 00229 }; 00230 00231 bool m_data; 00232 }; 00233 #endif 00234 00235