00001 #ifndef _STRINGVALUE_H_ 00002 #define _STRINGVALUE_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 #include <Fdo/Schema/DataType.h> 00029 00030 /// \brief 00031 /// The FdoStringValue class derives from FdoDataValue and represents a literal string. 00032 class FdoStringValue : public FdoDataValue 00033 { 00034 friend class FdoBooleanValue; 00035 friend class FdoByteValue; 00036 friend class FdoDateTimeValue; 00037 friend class FdoDecimalValue; 00038 friend class FdoDoubleValue; 00039 friend class FdoInt16Value; 00040 friend class FdoInt32Value; 00041 friend class FdoInt64Value; 00042 friend class FdoSingleValue; 00043 friend class FdoDataValue; 00044 /// \cond DOXYGEN-IGNORE 00045 protected: 00046 /// \brief 00047 /// Constructs a default instance of an FdoStringValue with a 00048 /// value of null. 00049 /// \return 00050 /// Returns nothing 00051 /// 00052 FdoStringValue(); 00053 00054 /// \brief 00055 /// Constructs a default instance of an FdoStringValue using the specified arguments. 00056 /// \return 00057 /// Returns nothing 00058 /// 00059 FdoStringValue(FdoString* value); 00060 00061 /// \brief 00062 /// Default destructor for FdoStringValue. 00063 virtual ~FdoStringValue(); 00064 00065 virtual void Dispose(); 00066 /// \endcond 00067 00068 public: 00069 /// \brief 00070 /// Constructs a default instance of an FdoStringValue with a value of null. 00071 /// 00072 /// \return 00073 /// Returns the created FdoStringValue 00074 /// 00075 FDO_API static FdoStringValue* Create(); 00076 00077 /// \brief 00078 /// Constructs a default instance of an FdoStringValue using the specified arguments. 00079 /// 00080 /// \param value 00081 /// Input a character string 00082 /// 00083 /// \return 00084 /// Returns the created FdoStringValue 00085 /// 00086 FDO_API static FdoStringValue* Create(FdoString* value); 00087 00088 /// \brief 00089 /// Gets the data type of the FdoStringValue. 00090 /// 00091 /// \return 00092 /// Returns FdoDataType 00093 /// 00094 FDO_API FdoDataType GetDataType(); 00095 00096 /// \brief 00097 /// Gets the FdoStringValue as a string. 00098 /// 00099 /// \return 00100 /// Returns a character string 00101 /// 00102 FDO_API FdoString* GetString(); 00103 00104 /// \brief 00105 /// Sets the FdoStringValue as a string. 00106 /// 00107 /// \param value 00108 /// Input a character string 00109 /// 00110 /// \return 00111 /// Returns nothing 00112 /// 00113 FDO_API void SetString(FdoString* value); 00114 00115 /// \brief 00116 /// Sets the FdoStringValue to a null value. 00117 /// 00118 /// \return 00119 /// Returns nothing 00120 /// 00121 FDO_API void SetNull(); 00122 00123 /// \brief 00124 /// Overrides FdoExpression.Process to pass the FdoStringValue to the appropriate 00125 /// expression processor operation. 00126 /// 00127 /// \param p 00128 /// Input an FdoIExpressionProcessor 00129 /// 00130 /// \return 00131 /// Returns nothing 00132 /// 00133 FDO_API void Process(FdoIExpressionProcessor* p); 00134 00135 /// \brief 00136 /// Returns the well defined text representation of this expression. 00137 /// 00138 /// \return 00139 /// Returns a character string 00140 /// 00141 FDO_API FdoString* ToString(); 00142 00143 /// \brief 00144 /// A cast operator to get the string. 00145 /// 00146 /// \return 00147 /// Returns a character string 00148 /// 00149 FDO_API operator wchar_t*() 00150 { 00151 return m_data; 00152 } 00153 00154 protected: 00155 /// \brief 00156 /// Constructs an instance of an FdoStringValue from another FdoDataValue. 00157 /// 00158 /// \param src 00159 /// Input the other FdoDataValue. Must be of one of the following types: 00160 /// FdoDataType_Boolean 00161 /// FdoDataType_Byte 00162 /// FdoDataType_Decimal 00163 /// FdoDataType_Double 00164 /// FdoDataType_Int16 00165 /// FdoDataType_Int32 00166 /// FdoDataType_Int64 00167 /// FdoDataType_Single 00168 /// FdoDataType_String 00169 /// 00170 /// In all other cases, the src type is considered incompatible with this type. 00171 /// \param nullIfIncompatible 00172 /// Input will determine what to do if the source value cannot be converted to 00173 /// this type: 00174 /// true - return NULL. 00175 /// false - throw an exception 00176 /// 00177 /// \param shift 00178 /// Input determines whether FdoFloat or FdoDouble values are allowed to shift 00179 /// when conversion to strings causes loss of precision. 00180 /// true - convert values allowing them to shift. 00181 /// false - behaviour depends on nullIfIncompatible: 00182 /// true - return NULL. 00183 /// false - throw an exception 00184 /// \param truncate 00185 /// Input for future use. There are currently no possible out of range 00186 /// src values. 00187 /// \return 00188 /// Returns an FdoStringValue, whose value is converted from the src value. 00189 /// If src is an FdoStringValue then its value is simply copied to the 00190 /// returned FdoStringValue. Otherwise, the value is converted by calling 00191 /// src->ToString(). 00192 /// 00193 static FdoStringValue* Create( 00194 FdoDataValue* src, 00195 FdoBoolean nullIfIncompatible = false, 00196 FdoBoolean shift = true, 00197 FdoBoolean truncate = false 00198 ); 00199 00200 template <class C> C* ConvertFrom( bool nullIfIncompatible, bool shift, bool truncate, FdoString* sTO ) 00201 { 00202 C* ret = NULL; 00203 FdoPtr<FdoDataValue> parsed = Parse(); 00204 00205 if ( (parsed == NULL) || (parsed->IsNull()) || (parsed->GetDataType() == FdoDataType_String) ) 00206 { 00207 if ( !nullIfIncompatible ) 00208 throw FdoExpressionException::Create( 00209 FdoException::NLSGetMessage( 00210 FDO_NLSID(EXPRESSION_22_INCOMPATIBLEDATATYPES), 00211 this->ToString(), 00212 (FdoString *) DataTypeToString(GetDataType()), 00213 sTO 00214 ) 00215 ); 00216 } 00217 else 00218 { 00219 ret = C::Create(parsed, nullIfIncompatible, shift, truncate); 00220 }; 00221 00222 return ret; 00223 }; 00224 00225 // See FdoDataValue::DoCompare() 00226 virtual FdoCompareType DoCompare( FdoDataValue* other ); 00227 00228 FdoDataValue* Parse(); 00229 00230 wchar_t* m_data; 00231 size_t m_allocatedSize; 00232 }; 00233 #endif 00234 00235