cid#1607171 Data race condition
[LibreOffice.git] / connectivity / source / inc / file / fcode.hxx
blob541377c7dd5f6c4a0abfde0364e3b3a6988bc4bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
28 #include <stack>
29 #include <utility>
31 namespace connectivity
33 class OSQLParseNode;
34 namespace file
37 class OOperand;
38 typedef std::stack<OOperand*> OCodeStack;
40 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OCode
42 public:
43 //virtual dtor to allow this to be the root of the class hierarchy
44 virtual ~OCode();
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;
49 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
59 protected:
60 sal_Int32 m_eDBType;
62 OOperand(sal_Int32 _rType) : m_eDBType(_rType){}
63 OOperand() : m_eDBType(css::sdbc::DataType::OTHER){}
65 public:
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
76 sal_uInt16 m_nRowPos;
77 OValueRefRow m_pRow;
79 protected:
80 OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType);
81 public:
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
91 public:
92 OOperandAttr(sal_uInt16 _nPos,
93 const css::uno::Reference< css::beans::XPropertySet>& _xColumn);
97 // Parameter for a predicate
98 class OOperandParam : public OOperandRow
100 public:
101 OOperandParam(sal_Int32 _nPos);
104 // Value operands
105 class OOperandValue : public OOperand
107 protected:
108 ORowSetValue m_aValue;
110 protected:
111 OOperandValue(){}
112 OOperandValue(ORowSetValue _aVar, sal_Int32 eDbType)
113 : OOperand(eDbType)
114 , m_aValue(std::move(_aVar))
117 OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){}
118 public:
119 virtual const ORowSetValue& getValue() const override;
120 virtual void setValue(const ORowSetValue& _rVal) override;
125 // Constants
126 class OOperandConst : public OOperandValue
128 public:
129 OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const OUString& aStrValue);
134 // Result operands
135 class OOperandResult : public OOperandValue
137 protected:
138 OOperandResult(sal_Int32 eDbType)
139 :OOperandValue(eDbType) {}
140 public:
141 OOperandResult(const ORowSetValue& _rVar)
142 :OOperandValue(_rVar, _rVar.getTypeKind()) {}
146 class OOperandResultBOOL : public OOperandResult
148 public:
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
158 public:
159 OOperandResultNUM(double fNum) : OOperandResult(css::sdbc::DataType::DOUBLE)
161 m_aValue = fNum;
162 m_aValue.setBound(true);
166 /** special stop operand
167 is appended when a list of arguments ends
169 class OStopOperand : public OOperandValue
171 public:
172 OStopOperand(){}
175 // Operators
176 class OOO_DLLPUBLIC_FILE OOperator : public OCode
178 public:
179 virtual void Exec(OCodeStack&) = 0;
183 // Boolean operators
184 class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator
186 public:
187 virtual void Exec(OCodeStack&) override;
188 virtual bool operate(const OOperand*, const OOperand*) const;
191 class OOp_NOT : public OBoolOperator
193 public:
195 protected:
196 virtual void Exec(OCodeStack&) override;
197 virtual bool operate(const OOperand*, const OOperand*) const override;
200 class OOp_AND : public OBoolOperator
202 public:
204 protected:
205 virtual bool operate(const OOperand*, const OOperand*) const override;
208 class OOp_OR : public OBoolOperator
210 public:
211 protected:
212 virtual bool operate(const OOperand*, const OOperand*) const override;
215 class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator
217 public:
218 public:
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
225 public:
226 virtual bool operate(const OOperand*, const OOperand*) const override;
229 class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator
231 const sal_Unicode cEscape;
233 public:
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
241 public:
242 public:
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;
252 public:
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
263 public:
264 virtual void Exec(OCodeStack&) override;
267 protected:
268 virtual double operate(const double& fLeft,const double& fRight) const = 0;
271 class OOp_ADD : public ONumOperator
273 protected:
274 virtual double operate(const double& fLeft,const double& fRight) const override;
277 class OOp_SUB : public ONumOperator
279 protected:
280 virtual double operate(const double& fLeft,const double& fRight) const override;
283 class OOp_MUL : public ONumOperator
285 protected:
286 virtual double operate(const double& fLeft,const double& fRight) const override;
289 class OOp_DIV : public ONumOperator
291 protected:
292 virtual double operate(const double& fLeft,const double& fRight) const override;
295 inline bool OOperand::isValid() const
297 return getValue().getDouble() != 0.0;
300 // Operator
301 class ONthOperator : public OOperator
303 public:
304 virtual void Exec(OCodeStack&) override;
307 protected:
308 virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const = 0;
311 class OBinaryOperator : public OOperator
313 public:
314 virtual void Exec(OCodeStack&) override;
317 protected:
318 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0;
321 class OUnaryOperator : public OOperator
323 public:
324 virtual void Exec(OCodeStack&) override;
325 virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */