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 .
22 #include <config_options.h>
23 #include <connectivity/sqliterator.hxx>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <connectivity/FValue.hxx>
26 #include <file/filedllapi.hxx>
31 namespace connectivity
38 typedef std::stack
<OOperand
*> OCodeStack
;
40 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE
) OCode
43 //virtual dtor to allow this to be the root of the class hierarchy
45 //but that disables the default move ctor
46 OCode(OCode
&&) = default;
47 //but that disables the rest of default ctors
48 OCode(const OCode
&) = default;
50 //and same issue for the assignment operators
51 OCode
& operator=(const OCode
&) = default;
52 OCode
& operator=(OCode
&&) = default;
56 // operands that the parsetree generate
57 class OOO_DLLPUBLIC_FILE OOperand
: public OCode
62 OOperand(sal_Int32 _rType
) : m_eDBType(_rType
){}
63 OOperand() : m_eDBType(css::sdbc::DataType::OTHER
){}
66 virtual const ORowSetValue
& getValue() const = 0;
67 virtual void setValue(const ORowSetValue
& _rVal
) = 0;
69 sal_Int32
getDBType() const {return m_eDBType
;}
70 inline bool isValid() const;
74 class OOperandRow
: public OOperand
80 OOperandRow(sal_uInt16 _nPos
, sal_Int32 _rType
);
82 virtual const ORowSetValue
& getValue() const override
;
83 virtual void setValue(const ORowSetValue
& _rVal
) override
;
84 void bindValue(const OValueRefRow
& _pRow
); // Bind to the value that the operand represents
88 // Attributes from a result row
89 class OOperandAttr
: public OOperandRow
92 OOperandAttr(sal_uInt16 _nPos
,
93 const css::uno::Reference
< css::beans::XPropertySet
>& _xColumn
);
97 // Parameter for a predicate
98 class OOperandParam
: public OOperandRow
101 OOperandParam(sal_Int32 _nPos
);
105 class OOperandValue
: public OOperand
108 ORowSetValue m_aValue
;
112 OOperandValue(ORowSetValue _aVar
, sal_Int32 eDbType
)
114 , m_aValue(std::move(_aVar
))
117 OOperandValue(sal_Int32 eDbType
) :OOperand(eDbType
){}
119 virtual const ORowSetValue
& getValue() const override
;
120 virtual void setValue(const ORowSetValue
& _rVal
) override
;
126 class OOperandConst
: public OOperandValue
129 OOperandConst(const connectivity::OSQLParseNode
& rColumnRef
, const OUString
& aStrValue
);
135 class OOperandResult
: public OOperandValue
138 OOperandResult(sal_Int32 eDbType
)
139 :OOperandValue(eDbType
) {}
141 OOperandResult(const ORowSetValue
& _rVar
)
142 :OOperandValue(_rVar
, _rVar
.getTypeKind()) {}
146 class OOperandResultBOOL
: public OOperandResult
149 OOperandResultBOOL(bool bResult
) : OOperandResult(css::sdbc::DataType::BIT
)
151 m_aValue
= bResult
? 1.0 : 0.0;
152 m_aValue
.setBound(true);
156 class OOperandResultNUM
: public OOperandResult
159 OOperandResultNUM(double fNum
) : OOperandResult(css::sdbc::DataType::DOUBLE
)
162 m_aValue
.setBound(true);
166 /** special stop operand
167 is appended when a list of arguments ends
169 class OStopOperand
: public OOperandValue
176 class OOO_DLLPUBLIC_FILE OOperator
: public OCode
179 virtual void Exec(OCodeStack
&) = 0;
184 class OOO_DLLPUBLIC_FILE OBoolOperator
: public OOperator
187 virtual void Exec(OCodeStack
&) override
;
188 virtual bool operate(const OOperand
*, const OOperand
*) const;
191 class OOp_NOT
: public OBoolOperator
196 virtual void Exec(OCodeStack
&) override
;
197 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
200 class OOp_AND
: public OBoolOperator
205 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
208 class OOp_OR
: public OBoolOperator
212 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
215 class OOO_DLLPUBLIC_FILE OOp_ISNULL
: public OBoolOperator
219 virtual void Exec(OCodeStack
&) override
;
220 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
223 class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL
: public OOp_ISNULL
226 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
229 class OOO_DLLPUBLIC_FILE OOp_LIKE
: public OBoolOperator
231 const sal_Unicode cEscape
;
234 OOp_LIKE(const sal_Unicode cEsc
):cEscape(cEsc
){};
236 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
239 class OOp_NOTLIKE
: public OOp_LIKE
243 OOp_NOTLIKE(const sal_Unicode cEsc
):OOp_LIKE(cEsc
){};
245 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
248 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE
) OOp_COMPARE
: public OBoolOperator
250 sal_Int32 aPredicateType
;
253 OOp_COMPARE(sal_Int32 aPType
)
254 :aPredicateType(aPType
) {}
256 sal_Int32
getPredicateType() const { return aPredicateType
; }
257 virtual bool operate(const OOperand
*, const OOperand
*) const override
;
260 // Numerical operators
261 class ONumOperator
: public OOperator
264 virtual void Exec(OCodeStack
&) override
;
268 virtual double operate(const double& fLeft
,const double& fRight
) const = 0;
271 class OOp_ADD
: public ONumOperator
274 virtual double operate(const double& fLeft
,const double& fRight
) const override
;
277 class OOp_SUB
: public ONumOperator
280 virtual double operate(const double& fLeft
,const double& fRight
) const override
;
283 class OOp_MUL
: public ONumOperator
286 virtual double operate(const double& fLeft
,const double& fRight
) const override
;
289 class OOp_DIV
: public ONumOperator
292 virtual double operate(const double& fLeft
,const double& fRight
) const override
;
295 inline bool OOperand::isValid() const
297 return getValue().getDouble() != 0.0;
301 class ONthOperator
: public OOperator
304 virtual void Exec(OCodeStack
&) override
;
308 virtual ORowSetValue
operate(const std::vector
<ORowSetValue
>& lhs
) const = 0;
311 class OBinaryOperator
: public OOperator
314 virtual void Exec(OCodeStack
&) override
;
318 virtual ORowSetValue
operate(const ORowSetValue
& lhs
,const ORowSetValue
& rhs
) const = 0;
321 class OUnaryOperator
: public OOperator
324 virtual void Exec(OCodeStack
&) override
;
325 virtual ORowSetValue
operate(const ORowSetValue
& lhs
) const = 0;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */