1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _CONNECTIVITY_FILE_FCODE_HXX_ 29 #define _CONNECTIVITY_FILE_FCODE_HXX_ 30 31 #include "connectivity/sqliterator.hxx" 32 #include <com/sun/star/sdbc/DataType.hpp> 33 #include "connectivity/CommonTools.hxx" 34 #include <tools/rtti.hxx> 35 #include <com/sun/star/container/XNameAccess.hpp> 36 #include <com/sun/star/container/XIndexAccess.hpp> 37 #include "connectivity/FValue.hxx" 38 #include "file/filedllapi.hxx" 39 40 namespace connectivity 41 { 42 class OSQLParseNode; 43 namespace dbase 44 { 45 class ODbaseIndex; 46 } 47 namespace file 48 { 49 50 class OOperand; 51 typedef ::std::stack<OOperand*> OCodeStack; 52 class OBoolOperator; 53 typedef ::std::map<sal_Int32,sal_Int32> OEvaluateSet; 54 55 typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> OFileColumns; 56 57 58 class OOO_DLLPUBLIC_FILE OCode 59 { 60 public: 61 OCode(); 62 virtual ~OCode(); 63 64 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 65 { return ::rtl_allocateMemory( nSize ); } 66 inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW( () ) 67 { return _pHint; } 68 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 69 { ::rtl_freeMemory( pMem ); } 70 inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW( () ) 71 { } 72 73 TYPEINFO(); 74 }; 75 76 77 // operands that the parsetree generate 78 class OOO_DLLPUBLIC_FILE OOperand : public OCode 79 { 80 protected: 81 sal_Int32 m_eDBType; 82 83 OOperand(const sal_Int32& _rType) : m_eDBType(_rType){} 84 OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER){} 85 86 public: 87 virtual const ORowSetValue& getValue() const = 0; 88 virtual void setValue(const ORowSetValue& _rVal) = 0; 89 90 virtual sal_Int32 getDBType() const {return m_eDBType;} 91 virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0); 92 inline sal_Bool isValid() const; 93 94 TYPEINFO(); 95 }; 96 97 class OOO_DLLPUBLIC_FILE OOperandRow : public OOperand 98 { 99 sal_uInt16 m_nRowPos; 100 protected: 101 OValueRefRow m_pRow; 102 103 OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType); 104 public: 105 sal_uInt16 getRowPos() const {return m_nRowPos;} 106 virtual const ORowSetValue& getValue() const; 107 virtual void setValue(const ORowSetValue& _rVal); 108 void bindValue(const OValueRefRow& _pRow); // Bindung an den Wert, den der Operand repraesentiert 109 110 TYPEINFO(); 111 }; 112 113 // Attribute aus einer Ergebniszeile 114 class OOO_DLLPUBLIC_FILE OOperandAttr : public OOperandRow 115 { 116 protected: 117 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xColumn; 118 119 public: 120 OOperandAttr(sal_uInt16 _nPos, 121 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn); 122 123 virtual sal_Bool isIndexed() const; 124 virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0); 125 TYPEINFO(); 126 }; 127 128 // Parameter fuer ein Praedikat 129 class OOperandParam : public OOperandRow 130 { 131 public: 132 OOperandParam(connectivity::OSQLParseNode* pNode, sal_Int32 _nPos); 133 void describe(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn, ::vos::ORef<connectivity::OSQLColumns> _xParamColumns); 134 135 TYPEINFO(); 136 }; 137 138 // WerteOperanden 139 class OOperandValue : public OOperand 140 { 141 protected: 142 ORowSetValue m_aValue; 143 144 protected: 145 OOperandValue(){} 146 OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType) 147 : OOperand(eDbType) 148 , m_aValue(_rVar) 149 {} 150 151 OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){} 152 public: 153 virtual const ORowSetValue& getValue() const; 154 virtual void setValue(const ORowSetValue& _rVal); 155 156 TYPEINFO(); 157 }; 158 159 160 // Konstanten 161 class OOperandConst : public OOperandValue 162 { 163 public: 164 OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const rtl::OUString& aStrValue); 165 166 TYPEINFO(); 167 }; 168 169 170 // Ergebnis Operanden 171 class OOperandResult : public OOperandValue 172 { 173 protected: 174 OOperandResult(const ORowSetValue& _rVar, sal_Int32 eDbType) 175 :OOperandValue(_rVar, eDbType) {} 176 OOperandResult(sal_Int32 eDbType) 177 :OOperandValue(eDbType) {} 178 public: 179 OOperandResult(const ORowSetValue& _rVar) 180 :OOperandValue(_rVar, _rVar.getTypeKind()) {} 181 TYPEINFO(); 182 }; 183 184 185 class OOperandResultBOOL : public OOperandResult 186 { 187 public: 188 OOperandResultBOOL(sal_Bool bResult) : OOperandResult(::com::sun::star::sdbc::DataType::BIT) 189 { 190 m_aValue = bResult ? 1.0 : 0.0; 191 m_aValue.setBound(sal_True); 192 } 193 }; 194 195 class OOperandResultNUM : public OOperandResult 196 { 197 public: 198 OOperandResultNUM(double fNum) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE) 199 { 200 m_aValue = fNum; 201 m_aValue.setBound(sal_True); 202 } 203 }; 204 205 /** special stop operand 206 is appended when a list of arguments ends 207 */ 208 class OStopOperand : public OOperandValue 209 { 210 public: 211 OStopOperand(){} 212 TYPEINFO(); 213 }; 214 215 // Operatoren 216 class OOO_DLLPUBLIC_FILE OOperator : public OCode 217 { 218 public: 219 virtual void Exec(OCodeStack&) = 0; 220 virtual sal_uInt16 getRequestedOperands() const; // Anzahl benoetigter Operanden 221 // Standard ist 2 222 TYPEINFO(); 223 }; 224 225 226 // boolsche Operatoren 227 228 class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator 229 { 230 public: 231 TYPEINFO(); 232 virtual void Exec(OCodeStack&); 233 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 234 }; 235 236 class OOp_NOT : public OBoolOperator 237 { 238 public: 239 TYPEINFO(); 240 241 protected: 242 virtual void Exec(OCodeStack&); 243 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 244 virtual sal_uInt16 getRequestedOperands() const; 245 }; 246 247 class OOp_AND : public OBoolOperator 248 { 249 public: 250 TYPEINFO(); 251 252 protected: 253 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 254 }; 255 256 class OOp_OR : public OBoolOperator 257 { 258 public: 259 TYPEINFO(); 260 protected: 261 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 262 }; 263 264 class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator 265 { 266 public: 267 TYPEINFO(); 268 public: 269 virtual void Exec(OCodeStack&); 270 virtual sal_uInt16 getRequestedOperands() const; 271 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 272 }; 273 274 class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL 275 { 276 public: 277 TYPEINFO(); 278 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 279 }; 280 281 class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator 282 { 283 public: 284 TYPEINFO(); 285 protected: 286 const sal_Unicode cEscape; 287 288 public: 289 OOp_LIKE(const sal_Unicode cEsc = L'\0'):cEscape(cEsc){}; 290 291 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 292 }; 293 294 class OOp_NOTLIKE : public OOp_LIKE 295 { 296 public: 297 TYPEINFO(); 298 public: 299 OOp_NOTLIKE(const sal_Unicode cEsc = L'\0'):OOp_LIKE(cEsc){}; 300 301 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 302 }; 303 304 class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator 305 { 306 sal_Int32 aPredicateType; 307 308 public: 309 TYPEINFO(); 310 OOp_COMPARE(sal_Int32 aPType) 311 :aPredicateType(aPType) {} 312 313 inline sal_Int32 getPredicateType() const { return aPredicateType; } 314 virtual sal_Bool operate(const OOperand*, const OOperand*) const; 315 }; 316 317 // numerische Operatoren 318 319 class ONumOperator : public OOperator 320 { 321 public: 322 virtual void Exec(OCodeStack&); 323 324 TYPEINFO(); 325 326 protected: 327 virtual double operate(const double& fLeft,const double& fRight) const = 0; 328 }; 329 330 class OOp_ADD : public ONumOperator 331 { 332 protected: 333 virtual double operate(const double& fLeft,const double& fRight) const; 334 }; 335 336 class OOp_SUB : public ONumOperator 337 { 338 protected: 339 virtual double operate(const double& fLeft,const double& fRight) const; 340 }; 341 342 class OOp_MUL : public ONumOperator 343 { 344 protected: 345 virtual double operate(const double& fLeft,const double& fRight) const; 346 }; 347 348 class OOp_DIV : public ONumOperator 349 { 350 protected: 351 virtual double operate(const double& fLeft,const double& fRight) const; 352 }; 353 354 inline sal_Bool OOperand::isValid() const 355 { 356 return getValue().getDouble() != double(0.0); 357 } 358 359 // operator 360 class ONthOperator : public OOperator 361 { 362 public: 363 virtual void Exec(OCodeStack&); 364 365 TYPEINFO(); 366 367 protected: 368 virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const = 0; 369 }; 370 371 class OBinaryOperator : public OOperator 372 { 373 public: 374 virtual void Exec(OCodeStack&); 375 376 TYPEINFO(); 377 378 protected: 379 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0; 380 }; 381 382 class OUnaryOperator : public OOperator 383 { 384 public: 385 virtual void Exec(OCodeStack&); 386 virtual sal_uInt16 getRequestedOperands() const; 387 virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0; 388 389 TYPEINFO(); 390 391 }; 392 } 393 } 394 395 #endif // _CONNECTIVITY_FILE_FCODE_HXX_ 396 397