1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX
23 #include <connectivity/sqliterator.hxx>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <connectivity/CommonTools.hxx>
26 #include <tools/rtti.hxx>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XIndexAccess.hpp>
29 #include <connectivity/FValue.hxx>
30 #include "file/filedllapi.hxx"
32 namespace connectivity
39 typedef ::std::stack
<OOperand
*> OCodeStack
;
41 typedef ::std::map
<sal_Int32
,sal_Int32
> OEvaluateSet
;
43 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> OFileColumns
;
46 class OOO_DLLPUBLIC_FILE OCode
52 inline static void * SAL_CALL
operator new( size_t nSize
)
53 { return ::rtl_allocateMemory( nSize
); }
54 inline static void * SAL_CALL
operator new( size_t /*nSize*/,void* _pHint
)
56 inline static void SAL_CALL
operator delete( void * pMem
)
57 { ::rtl_freeMemory( pMem
); }
58 inline static void SAL_CALL
operator delete( void * /*pMem*/,void* /*_pHint*/ )
65 // operands that the parsetree generate
66 class OOO_DLLPUBLIC_FILE OOperand
: public OCode
71 OOperand(const sal_Int32
& _rType
) : m_eDBType(_rType
){}
72 OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER
){}
75 virtual const ORowSetValue
& getValue() const = 0;
76 virtual void setValue(const ORowSetValue
& _rVal
) = 0;
78 sal_Int32
getDBType() const {return m_eDBType
;}
79 virtual OEvaluateSet
* preProcess(OBoolOperator
* pOp
, OOperand
* pRight
= 0);
80 inline bool isValid() const;
85 class OOO_DLLPUBLIC_FILE OOperandRow
: public OOperand
91 OOperandRow(sal_uInt16 _nPos
, sal_Int32 _rType
);
93 sal_uInt16
getRowPos() const {return m_nRowPos
;}
94 virtual const ORowSetValue
& getValue() const SAL_OVERRIDE
;
95 virtual void setValue(const ORowSetValue
& _rVal
) SAL_OVERRIDE
;
96 void bindValue(const OValueRefRow
& _pRow
); // Bind to the value that the operand represents
101 // Attributes from a result row
102 class OOO_DLLPUBLIC_FILE OOperandAttr
: public OOperandRow
105 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xColumn
;
108 OOperandAttr(sal_uInt16 _nPos
,
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xColumn
);
111 virtual bool isIndexed() const;
112 virtual OEvaluateSet
* preProcess(OBoolOperator
* pOp
, OOperand
* pRight
= 0) SAL_OVERRIDE
;
116 // Parameter for a predicate
117 class OOperandParam
: public OOperandRow
120 OOperandParam(connectivity::OSQLParseNode
* pNode
, sal_Int32 _nPos
);
125 class OOperandValue
: public OOperand
128 ORowSetValue m_aValue
;
132 OOperandValue(const ORowSetValue
& _rVar
, sal_Int32 eDbType
)
137 OOperandValue(sal_Int32 eDbType
) :OOperand(eDbType
){}
139 virtual const ORowSetValue
& getValue() const SAL_OVERRIDE
;
140 virtual void setValue(const ORowSetValue
& _rVal
) SAL_OVERRIDE
;
147 class OOperandConst
: public OOperandValue
150 OOperandConst(const connectivity::OSQLParseNode
& rColumnRef
, const OUString
& aStrValue
);
157 class OOperandResult
: public OOperandValue
160 OOperandResult(const ORowSetValue
& _rVar
, sal_Int32 eDbType
)
161 :OOperandValue(_rVar
, eDbType
) {}
162 OOperandResult(sal_Int32 eDbType
)
163 :OOperandValue(eDbType
) {}
165 OOperandResult(const ORowSetValue
& _rVar
)
166 :OOperandValue(_rVar
, _rVar
.getTypeKind()) {}
171 class OOperandResultBOOL
: public OOperandResult
174 OOperandResultBOOL(bool bResult
) : OOperandResult(::com::sun::star::sdbc::DataType::BIT
)
176 m_aValue
= bResult
? 1.0 : 0.0;
177 m_aValue
.setBound(true);
181 class OOperandResultNUM
: public OOperandResult
184 OOperandResultNUM(double fNum
) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE
)
187 m_aValue
.setBound(true);
191 /** special stop operand
192 is appended when a list of arguments ends
194 class OStopOperand
: public OOperandValue
202 class OOO_DLLPUBLIC_FILE OOperator
: public OCode
205 virtual void Exec(OCodeStack
&) = 0;
206 virtual sal_uInt16
getRequestedOperands() const; // Count of requested operands
213 class OOO_DLLPUBLIC_FILE OBoolOperator
: public OOperator
217 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
218 virtual bool operate(const OOperand
*, const OOperand
*) const;
221 class OOp_NOT
: public OBoolOperator
227 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
228 virtual bool operate(const OOperand
*, const OOperand
* = NULL
) const SAL_OVERRIDE
;
229 virtual sal_uInt16
getRequestedOperands() const SAL_OVERRIDE
;
232 class OOp_AND
: public OBoolOperator
238 virtual bool operate(const OOperand
*, const OOperand
*) const SAL_OVERRIDE
;
241 class OOp_OR
: public OBoolOperator
246 virtual bool operate(const OOperand
*, const OOperand
*) const SAL_OVERRIDE
;
249 class OOO_DLLPUBLIC_FILE OOp_ISNULL
: public OBoolOperator
254 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
255 virtual sal_uInt16
getRequestedOperands() const SAL_OVERRIDE
;
256 virtual bool operate(const OOperand
*, const OOperand
* = NULL
) const SAL_OVERRIDE
;
259 class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL
: public OOp_ISNULL
263 virtual bool operate(const OOperand
*, const OOperand
* = NULL
) const SAL_OVERRIDE
;
266 class OOO_DLLPUBLIC_FILE OOp_LIKE
: public OBoolOperator
271 const sal_Unicode cEscape
;
274 OOp_LIKE(const sal_Unicode cEsc
= L
'\0'):cEscape(cEsc
){};
276 virtual bool operate(const OOperand
*, const OOperand
*) const SAL_OVERRIDE
;
279 class OOp_NOTLIKE
: public OOp_LIKE
284 OOp_NOTLIKE(const sal_Unicode cEsc
= L
'\0'):OOp_LIKE(cEsc
){};
286 virtual bool operate(const OOperand
*, const OOperand
*) const SAL_OVERRIDE
;
289 class OOO_DLLPUBLIC_FILE OOp_COMPARE
: public OBoolOperator
291 sal_Int32 aPredicateType
;
295 OOp_COMPARE(sal_Int32 aPType
)
296 :aPredicateType(aPType
) {}
298 inline sal_Int32
getPredicateType() const { return aPredicateType
; }
299 virtual bool operate(const OOperand
*, const OOperand
*) const SAL_OVERRIDE
;
302 // Numerical operators
303 class ONumOperator
: public OOperator
306 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
311 virtual double operate(const double& fLeft
,const double& fRight
) const = 0;
314 class OOp_ADD
: public ONumOperator
317 virtual double operate(const double& fLeft
,const double& fRight
) const SAL_OVERRIDE
;
320 class OOp_SUB
: public ONumOperator
323 virtual double operate(const double& fLeft
,const double& fRight
) const SAL_OVERRIDE
;
326 class OOp_MUL
: public ONumOperator
329 virtual double operate(const double& fLeft
,const double& fRight
) const SAL_OVERRIDE
;
332 class OOp_DIV
: public ONumOperator
335 virtual double operate(const double& fLeft
,const double& fRight
) const SAL_OVERRIDE
;
338 inline bool OOperand::isValid() const
340 return getValue().getDouble() != double(0.0);
344 class ONthOperator
: public OOperator
347 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
352 virtual ORowSetValue
operate(const ::std::vector
<ORowSetValue
>& lhs
) const = 0;
355 class OBinaryOperator
: public OOperator
358 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
363 virtual ORowSetValue
operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const = 0;
366 class OUnaryOperator
: public OOperator
369 virtual void Exec(OCodeStack
&) SAL_OVERRIDE
;
370 virtual sal_uInt16
getRequestedOperands() const SAL_OVERRIDE
;
371 virtual ORowSetValue
operate(const ORowSetValue
& lhs
) const = 0;
379 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */