1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fcode.hxx,v $
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
54 typedef ::std::stack
<OOperand
*> OCodeStack
;
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
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( () )
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( () )
80 // operands that the parsetree generate
81 class OOO_DLLPUBLIC_FILE OOperand
: public OCode
86 OOperand(const sal_Int32
& _rType
) : m_eDBType(_rType
){}
87 OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER
){}
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;
100 class OOO_DLLPUBLIC_FILE OOperandRow
: public OOperand
102 sal_uInt16 m_nRowPos
;
106 OOperandRow(sal_uInt16 _nPos
, sal_Int32 _rType
);
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
116 // Attribute aus einer Ergebniszeile
117 class OOO_DLLPUBLIC_FILE OOperandAttr
: public OOperandRow
120 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xColumn
;
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);
131 // Parameter fuer ein Praedikat
132 class OOperandParam
: public OOperandRow
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
);
142 class OOperandValue
: public OOperand
145 ORowSetValue m_aValue
;
149 OOperandValue(const ORowSetValue
& _rVar
, sal_Int32 eDbType
)
154 OOperandValue(sal_Int32 eDbType
) :OOperand(eDbType
){}
156 virtual const ORowSetValue
& getValue() const;
157 virtual void setValue(const ORowSetValue
& _rVal
);
164 class OOperandConst
: public OOperandValue
167 OOperandConst(const connectivity::OSQLParseNode
& rColumnRef
, const rtl::OUString
& aStrValue
);
173 // Ergebnis Operanden
174 class OOperandResult
: public OOperandValue
177 OOperandResult(const ORowSetValue
& _rVar
, sal_Int32 eDbType
)
178 :OOperandValue(_rVar
, eDbType
) {}
179 OOperandResult(sal_Int32 eDbType
)
180 :OOperandValue(eDbType
) {}
182 OOperandResult(const ORowSetValue
& _rVar
)
183 :OOperandValue(_rVar
, _rVar
.getTypeKind()) {}
188 class OOperandResultBOOL
: public OOperandResult
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
201 OOperandResultNUM(double fNum
) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE
)
204 m_aValue
.setBound(sal_True
);
208 /** special stop operand
209 is appended when a list of arguments ends
211 class OStopOperand
: public OOperandValue
219 class OOO_DLLPUBLIC_FILE OOperator
: public OCode
222 virtual void Exec(OCodeStack
&) = 0;
223 virtual sal_uInt16
getRequestedOperands() const; // Anzahl benoetigter Operanden
229 // boolsche Operatoren
231 class OOO_DLLPUBLIC_FILE OBoolOperator
: public OOperator
235 virtual void Exec(OCodeStack
&);
236 virtual sal_Bool
operate(const OOperand
*, const OOperand
*) const;
239 class OOp_NOT
: public OBoolOperator
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
256 virtual sal_Bool
operate(const OOperand
*, const OOperand
*) const;
259 class OOp_OR
: public OBoolOperator
264 virtual sal_Bool
operate(const OOperand
*, const OOperand
*) const;
267 class OOO_DLLPUBLIC_FILE OOp_ISNULL
: public OBoolOperator
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
281 virtual sal_Bool
operate(const OOperand
*, const OOperand
* = NULL
) const;
284 class OOO_DLLPUBLIC_FILE OOp_LIKE
: public OBoolOperator
289 const sal_Unicode cEscape
;
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
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
;
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
325 virtual void Exec(OCodeStack
&);
330 virtual double operate(const double& fLeft
,const double& fRight
) const = 0;
333 class OOp_ADD
: public ONumOperator
336 virtual double operate(const double& fLeft
,const double& fRight
) const;
339 class OOp_SUB
: public ONumOperator
342 virtual double operate(const double& fLeft
,const double& fRight
) const;
345 class OOp_MUL
: public ONumOperator
348 virtual double operate(const double& fLeft
,const double& fRight
) const;
351 class OOp_DIV
: public ONumOperator
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);
363 class ONthOperator
: public OOperator
366 virtual void Exec(OCodeStack
&);
371 virtual ORowSetValue
operate(const ::std::vector
<ORowSetValue
>& lhs
) const = 0;
374 class OBinaryOperator
: public OOperator
377 virtual void Exec(OCodeStack
&);
382 virtual ORowSetValue
operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const = 0;
385 class OUnaryOperator
: public OOperator
388 virtual void Exec(OCodeStack
&);
389 virtual sal_uInt16
getRequestedOperands() const;
390 virtual ORowSetValue
operate(const ORowSetValue
& lhs
) const = 0;
398 #endif // _CONNECTIVITY_FILE_FCODE_HXX_