Update ooo320-m1
[ooovba.git] / connectivity / source / inc / file / fcode.hxx
blobde07555d4022f0e3821a2e9e8b56502eb25fc2d9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fcode.hxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_FILE_FCODE_HXX_
32 #define _CONNECTIVITY_FILE_FCODE_HXX_
34 #include "connectivity/sqliterator.hxx"
35 #include <com/sun/star/sdbc/DataType.hpp>
36 #include "connectivity/CommonTools.hxx"
37 #include <tools/rtti.hxx>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include "connectivity/FValue.hxx"
41 #include "file/filedllapi.hxx"
43 namespace connectivity
45 class OSQLParseNode;
46 namespace dbase
48 class ODbaseIndex;
50 namespace file
53 class OOperand;
54 typedef ::std::stack<OOperand*> OCodeStack;
55 class OBoolOperator;
56 typedef ::std::map<sal_Int32,sal_Int32> OEvaluateSet;
58 typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> OFileColumns;
61 class OOO_DLLPUBLIC_FILE OCode
63 public:
64 OCode();
65 virtual ~OCode();
67 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
68 { return ::rtl_allocateMemory( nSize ); }
69 inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW( () )
70 { return _pHint; }
71 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
72 { ::rtl_freeMemory( pMem ); }
73 inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW( () )
74 { }
76 TYPEINFO();
80 // operands that the parsetree generate
81 class OOO_DLLPUBLIC_FILE OOperand : public OCode
83 protected:
84 sal_Int32 m_eDBType;
86 OOperand(const sal_Int32& _rType) : m_eDBType(_rType){}
87 OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER){}
89 public:
90 virtual const ORowSetValue& getValue() const = 0;
91 virtual void setValue(const ORowSetValue& _rVal) = 0;
93 virtual sal_Int32 getDBType() const {return m_eDBType;}
94 virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0);
95 inline sal_Bool isValid() const;
97 TYPEINFO();
100 class OOO_DLLPUBLIC_FILE OOperandRow : public OOperand
102 sal_uInt16 m_nRowPos;
103 protected:
104 OValueRefRow m_pRow;
106 OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType);
107 public:
108 sal_uInt16 getRowPos() const {return m_nRowPos;}
109 virtual const ORowSetValue& getValue() const;
110 virtual void setValue(const ORowSetValue& _rVal);
111 void bindValue(const OValueRefRow& _pRow); // Bindung an den Wert, den der Operand repraesentiert
113 TYPEINFO();
116 // Attribute aus einer Ergebniszeile
117 class OOO_DLLPUBLIC_FILE OOperandAttr : public OOperandRow
119 protected:
120 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xColumn;
122 public:
123 OOperandAttr(sal_uInt16 _nPos,
124 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn);
126 virtual sal_Bool isIndexed() const;
127 virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0);
128 TYPEINFO();
131 // Parameter fuer ein Praedikat
132 class OOperandParam : public OOperandRow
134 public:
135 OOperandParam(connectivity::OSQLParseNode* pNode, sal_Int32 _nPos);
136 void describe(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn, ::vos::ORef<connectivity::OSQLColumns> _xParamColumns);
138 TYPEINFO();
141 // WerteOperanden
142 class OOperandValue : public OOperand
144 protected:
145 ORowSetValue m_aValue;
147 protected:
148 OOperandValue(){}
149 OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType)
150 : OOperand(eDbType)
151 , m_aValue(_rVar)
154 OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){}
155 public:
156 virtual const ORowSetValue& getValue() const;
157 virtual void setValue(const ORowSetValue& _rVal);
159 TYPEINFO();
163 // Konstanten
164 class OOperandConst : public OOperandValue
166 public:
167 OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const rtl::OUString& aStrValue);
169 TYPEINFO();
173 // Ergebnis Operanden
174 class OOperandResult : public OOperandValue
176 protected:
177 OOperandResult(const ORowSetValue& _rVar, sal_Int32 eDbType)
178 :OOperandValue(_rVar, eDbType) {}
179 OOperandResult(sal_Int32 eDbType)
180 :OOperandValue(eDbType) {}
181 public:
182 OOperandResult(const ORowSetValue& _rVar)
183 :OOperandValue(_rVar, _rVar.getTypeKind()) {}
184 TYPEINFO();
188 class OOperandResultBOOL : public OOperandResult
190 public:
191 OOperandResultBOOL(sal_Bool bResult) : OOperandResult(::com::sun::star::sdbc::DataType::BIT)
193 m_aValue = bResult ? 1.0 : 0.0;
194 m_aValue.setBound(sal_True);
198 class OOperandResultNUM : public OOperandResult
200 public:
201 OOperandResultNUM(double fNum) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE)
203 m_aValue = fNum;
204 m_aValue.setBound(sal_True);
208 /** special stop operand
209 is appended when a list of arguments ends
211 class OStopOperand : public OOperandValue
213 public:
214 OStopOperand(){}
215 TYPEINFO();
218 // Operatoren
219 class OOO_DLLPUBLIC_FILE OOperator : public OCode
221 public:
222 virtual void Exec(OCodeStack&) = 0;
223 virtual sal_uInt16 getRequestedOperands() const; // Anzahl benoetigter Operanden
224 // Standard ist 2
225 TYPEINFO();
229 // boolsche Operatoren
231 class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator
233 public:
234 TYPEINFO();
235 virtual void Exec(OCodeStack&);
236 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
239 class OOp_NOT : public OBoolOperator
241 public:
242 TYPEINFO();
244 protected:
245 virtual void Exec(OCodeStack&);
246 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
247 virtual sal_uInt16 getRequestedOperands() const;
250 class OOp_AND : public OBoolOperator
252 public:
253 TYPEINFO();
255 protected:
256 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
259 class OOp_OR : public OBoolOperator
261 public:
262 TYPEINFO();
263 protected:
264 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
267 class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator
269 public:
270 TYPEINFO();
271 public:
272 virtual void Exec(OCodeStack&);
273 virtual sal_uInt16 getRequestedOperands() const;
274 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
277 class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL
279 public:
280 TYPEINFO();
281 virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
284 class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator
286 public:
287 TYPEINFO();
288 protected:
289 const sal_Unicode cEscape;
291 public:
292 OOp_LIKE(const sal_Unicode cEsc = L'\0'):cEscape(cEsc){};
294 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
297 class OOp_NOTLIKE : public OOp_LIKE
299 public:
300 TYPEINFO();
301 public:
302 OOp_NOTLIKE(const sal_Unicode cEsc = L'\0'):OOp_LIKE(cEsc){};
304 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
307 class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator
309 sal_Int32 aPredicateType;
311 public:
312 TYPEINFO();
313 OOp_COMPARE(sal_Int32 aPType)
314 :aPredicateType(aPType) {}
316 inline sal_Int32 getPredicateType() const { return aPredicateType; }
317 virtual sal_Bool operate(const OOperand*, const OOperand*) const;
320 // numerische Operatoren
322 class ONumOperator : public OOperator
324 public:
325 virtual void Exec(OCodeStack&);
327 TYPEINFO();
329 protected:
330 virtual double operate(const double& fLeft,const double& fRight) const = 0;
333 class OOp_ADD : public ONumOperator
335 protected:
336 virtual double operate(const double& fLeft,const double& fRight) const;
339 class OOp_SUB : public ONumOperator
341 protected:
342 virtual double operate(const double& fLeft,const double& fRight) const;
345 class OOp_MUL : public ONumOperator
347 protected:
348 virtual double operate(const double& fLeft,const double& fRight) const;
351 class OOp_DIV : public ONumOperator
353 protected:
354 virtual double operate(const double& fLeft,const double& fRight) const;
357 inline sal_Bool OOperand::isValid() const
359 return getValue().getDouble() != double(0.0);
362 // operator
363 class ONthOperator : public OOperator
365 public:
366 virtual void Exec(OCodeStack&);
368 TYPEINFO();
370 protected:
371 virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const = 0;
374 class OBinaryOperator : public OOperator
376 public:
377 virtual void Exec(OCodeStack&);
379 TYPEINFO();
381 protected:
382 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0;
385 class OUnaryOperator : public OOperator
387 public:
388 virtual void Exec(OCodeStack&);
389 virtual sal_uInt16 getRequestedOperands() const;
390 virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0;
392 TYPEINFO();
398 #endif // _CONNECTIVITY_FILE_FCODE_HXX_