/src/libreoffice/connectivity/source/inc/file/fcode.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
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> |
27 | | |
28 | | #include <stack> |
29 | | #include <utility> |
30 | | |
31 | | namespace connectivity |
32 | | { |
33 | | class OSQLParseNode; |
34 | | namespace file |
35 | | { |
36 | | |
37 | | class OOperand; |
38 | | typedef std::stack<OOperand*> OCodeStack; |
39 | | |
40 | | class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OCode |
41 | | { |
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 | 57.0k | OCode() = default; |
50 | | //and same issue for the assignment operators |
51 | | OCode& operator=(const OCode&) = default; |
52 | | OCode& operator=(OCode&&) = default; |
53 | | }; |
54 | | |
55 | | |
56 | | // operands that the parsetree generate |
57 | | class OOO_DLLPUBLIC_FILE OOperand : public OCode |
58 | | { |
59 | | protected: |
60 | | sal_Int32 m_eDBType; |
61 | | |
62 | 0 | OOperand(sal_Int32 _rType) : m_eDBType(_rType){} |
63 | 38.0k | OOperand() : m_eDBType(css::sdbc::DataType::OTHER){} |
64 | | |
65 | | public: |
66 | | virtual const ORowSetValue& getValue() const = 0; |
67 | | virtual void setValue(const ORowSetValue& _rVal) = 0; |
68 | | |
69 | 0 | sal_Int32 getDBType() const {return m_eDBType;} |
70 | | inline bool isValid() const; |
71 | | |
72 | | }; |
73 | | |
74 | | class OOperandRow : public OOperand |
75 | | { |
76 | | sal_uInt16 m_nRowPos; |
77 | | OValueRefRow m_pRow; |
78 | | |
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 |
85 | | |
86 | | }; |
87 | | |
88 | | // Attributes from a result row |
89 | | class OOperandAttr : public OOperandRow |
90 | | { |
91 | | public: |
92 | | OOperandAttr(sal_uInt16 _nPos, |
93 | | const css::uno::Reference< css::beans::XPropertySet>& _xColumn); |
94 | | |
95 | | }; |
96 | | |
97 | | // Parameter for a predicate |
98 | | class OOperandParam : public OOperandRow |
99 | | { |
100 | | public: |
101 | | OOperandParam(sal_Int32 _nPos); |
102 | | }; |
103 | | |
104 | | // Value operands |
105 | | class OOperandValue : public OOperand |
106 | | { |
107 | | protected: |
108 | | ORowSetValue m_aValue; |
109 | | |
110 | | protected: |
111 | 38.0k | OOperandValue(){} |
112 | | OOperandValue(ORowSetValue _aVar, sal_Int32 eDbType) |
113 | 0 | : OOperand(eDbType) |
114 | 0 | , m_aValue(std::move(_aVar)) |
115 | 0 | {} |
116 | | |
117 | 0 | OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){} |
118 | | public: |
119 | | virtual const ORowSetValue& getValue() const override; |
120 | | virtual void setValue(const ORowSetValue& _rVal) override; |
121 | | |
122 | | }; |
123 | | |
124 | | |
125 | | // Constants |
126 | | class OOperandConst : public OOperandValue |
127 | | { |
128 | | public: |
129 | | OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const OUString& aStrValue); |
130 | | |
131 | | }; |
132 | | |
133 | | |
134 | | // Result operands |
135 | | class OOperandResult : public OOperandValue |
136 | | { |
137 | | protected: |
138 | | OOperandResult(sal_Int32 eDbType) |
139 | 0 | :OOperandValue(eDbType) {} |
140 | | public: |
141 | | OOperandResult(const ORowSetValue& _rVar) |
142 | 0 | :OOperandValue(_rVar, _rVar.getTypeKind()) {} |
143 | | }; |
144 | | |
145 | | |
146 | | class OOperandResultBOOL : public OOperandResult |
147 | | { |
148 | | public: |
149 | 0 | OOperandResultBOOL(bool bResult) : OOperandResult(css::sdbc::DataType::BIT) |
150 | 0 | { |
151 | 0 | m_aValue = bResult ? 1.0 : 0.0; |
152 | 0 | m_aValue.setBound(true); |
153 | 0 | } |
154 | | }; |
155 | | |
156 | | class OOperandResultNUM : public OOperandResult |
157 | | { |
158 | | public: |
159 | 0 | OOperandResultNUM(double fNum) : OOperandResult(css::sdbc::DataType::DOUBLE) |
160 | 0 | { |
161 | 0 | m_aValue = fNum; |
162 | 0 | m_aValue.setBound(true); |
163 | 0 | } |
164 | | }; |
165 | | |
166 | | /** special stop operand |
167 | | is appended when a list of arguments ends |
168 | | */ |
169 | | class OStopOperand : public OOperandValue |
170 | | { |
171 | | public: |
172 | 0 | OStopOperand(){} |
173 | | }; |
174 | | |
175 | | // Operators |
176 | | class OOO_DLLPUBLIC_FILE OOperator : public OCode |
177 | | { |
178 | | public: |
179 | | virtual void Exec(OCodeStack&) = 0; |
180 | | }; |
181 | | |
182 | | |
183 | | // Boolean operators |
184 | | class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator |
185 | | { |
186 | | public: |
187 | | virtual void Exec(OCodeStack&) override; |
188 | | virtual bool operate(const OOperand*, const OOperand*) const; |
189 | | }; |
190 | | |
191 | | class OOp_NOT : public OBoolOperator |
192 | | { |
193 | | public: |
194 | | |
195 | | protected: |
196 | | virtual void Exec(OCodeStack&) override; |
197 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
198 | | }; |
199 | | |
200 | | class OOp_AND : public OBoolOperator |
201 | | { |
202 | | public: |
203 | | |
204 | | protected: |
205 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
206 | | }; |
207 | | |
208 | | class OOp_OR : public OBoolOperator |
209 | | { |
210 | | public: |
211 | | protected: |
212 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
213 | | }; |
214 | | |
215 | | class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator |
216 | | { |
217 | | public: |
218 | | public: |
219 | | virtual void Exec(OCodeStack&) override; |
220 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
221 | | }; |
222 | | |
223 | | class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL |
224 | | { |
225 | | public: |
226 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
227 | | }; |
228 | | |
229 | | class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator |
230 | | { |
231 | | const sal_Unicode cEscape; |
232 | | |
233 | | public: |
234 | 0 | OOp_LIKE(const sal_Unicode cEsc):cEscape(cEsc){}; |
235 | | |
236 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
237 | | }; |
238 | | |
239 | | class OOp_NOTLIKE : public OOp_LIKE |
240 | | { |
241 | | public: |
242 | | public: |
243 | 0 | OOp_NOTLIKE(const sal_Unicode cEsc):OOp_LIKE(cEsc){}; |
244 | | |
245 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
246 | | }; |
247 | | |
248 | | class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OOp_COMPARE : public OBoolOperator |
249 | | { |
250 | | sal_Int32 aPredicateType; |
251 | | |
252 | | public: |
253 | | OOp_COMPARE(sal_Int32 aPType) |
254 | 19.0k | :aPredicateType(aPType) {} |
255 | | |
256 | 0 | sal_Int32 getPredicateType() const { return aPredicateType; } |
257 | | virtual bool operate(const OOperand*, const OOperand*) const override; |
258 | | }; |
259 | | |
260 | | // Numerical operators |
261 | | class ONumOperator : public OOperator |
262 | | { |
263 | | public: |
264 | | virtual void Exec(OCodeStack&) override; |
265 | | |
266 | | |
267 | | protected: |
268 | | virtual double operate(const double& fLeft,const double& fRight) const = 0; |
269 | | }; |
270 | | |
271 | | class OOp_ADD : public ONumOperator |
272 | | { |
273 | | protected: |
274 | | virtual double operate(const double& fLeft,const double& fRight) const override; |
275 | | }; |
276 | | |
277 | | class OOp_SUB : public ONumOperator |
278 | | { |
279 | | protected: |
280 | | virtual double operate(const double& fLeft,const double& fRight) const override; |
281 | | }; |
282 | | |
283 | | class OOp_MUL : public ONumOperator |
284 | | { |
285 | | protected: |
286 | | virtual double operate(const double& fLeft,const double& fRight) const override; |
287 | | }; |
288 | | |
289 | | class OOp_DIV : public ONumOperator |
290 | | { |
291 | | protected: |
292 | | virtual double operate(const double& fLeft,const double& fRight) const override; |
293 | | }; |
294 | | |
295 | | inline bool OOperand::isValid() const |
296 | 0 | { |
297 | 0 | return getValue().getDouble() != 0.0; |
298 | 0 | } |
299 | | |
300 | | // Operator |
301 | | class ONthOperator : public OOperator |
302 | | { |
303 | | public: |
304 | | virtual void Exec(OCodeStack&) override; |
305 | | |
306 | | |
307 | | protected: |
308 | | virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const = 0; |
309 | | }; |
310 | | |
311 | | class OBinaryOperator : public OOperator |
312 | | { |
313 | | public: |
314 | | virtual void Exec(OCodeStack&) override; |
315 | | |
316 | | |
317 | | protected: |
318 | | virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0; |
319 | | }; |
320 | | |
321 | | class OUnaryOperator : public OOperator |
322 | | { |
323 | | public: |
324 | | virtual void Exec(OCodeStack&) override; |
325 | | virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0; |
326 | | |
327 | | |
328 | | }; |
329 | | } |
330 | | } |
331 | | |
332 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |