Branch data Line data Source code
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 : : #ifndef _CONNECTIVITY_FILE_FCODE_HXX_
21 : : #define _CONNECTIVITY_FILE_FCODE_HXX_
22 : :
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"
31 : :
32 : : namespace connectivity
33 : : {
34 : : class OSQLParseNode;
35 : : namespace file
36 : : {
37 : :
38 : : class OOperand;
39 : : typedef ::std::stack<OOperand*> OCodeStack;
40 : : class OBoolOperator;
41 : : typedef ::std::map<sal_Int32,sal_Int32> OEvaluateSet;
42 : :
43 : : typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> OFileColumns;
44 : :
45 : :
46 : : class OOO_DLLPUBLIC_FILE OCode
47 : : {
48 : : public:
49 : : OCode();
50 : : virtual ~OCode();
51 : :
52 : 264 : inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
53 : 264 : { return ::rtl_allocateMemory( nSize ); }
54 : : inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW(())
55 : : { return _pHint; }
56 : 264 : inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
57 : 264 : { ::rtl_freeMemory( pMem ); }
58 : : inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW(())
59 : : { }
60 : :
61 : : TYPEINFO();
62 : : };
63 : :
64 : :
65 : : // operands that the parsetree generate
66 [ - + ]: 180 : class OOO_DLLPUBLIC_FILE OOperand : public OCode
67 : : {
68 : : protected:
69 : : sal_Int32 m_eDBType;
70 : :
71 : 84 : OOperand(const sal_Int32& _rType) : m_eDBType(_rType){}
72 : 96 : OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER){}
73 : :
74 : : public:
75 : : virtual const ORowSetValue& getValue() const = 0;
76 : : virtual void setValue(const ORowSetValue& _rVal) = 0;
77 : :
78 : 24 : virtual sal_Int32 getDBType() const {return m_eDBType;}
79 : : virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0);
80 : : inline sal_Bool isValid() const;
81 : :
82 : : TYPEINFO();
83 : : };
84 : :
85 [ + - ][ - + ]: 48 : class OOO_DLLPUBLIC_FILE OOperandRow : public OOperand
86 : : {
87 : : sal_uInt16 m_nRowPos;
88 : : protected:
89 : : OValueRefRow m_pRow;
90 : :
91 : : OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType);
92 : : public:
93 : : sal_uInt16 getRowPos() const {return m_nRowPos;}
94 : : virtual const ORowSetValue& getValue() const;
95 : : virtual void setValue(const ORowSetValue& _rVal);
96 : : void bindValue(const OValueRefRow& _pRow); // Bind to the value that the operand represents
97 : :
98 : : TYPEINFO();
99 : : };
100 : :
101 : : // Attributes from a result row
102 [ - + ]: 48 : class OOO_DLLPUBLIC_FILE OOperandAttr : public OOperandRow
103 : : {
104 : : protected:
105 : : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xColumn;
106 : :
107 : : public:
108 : : OOperandAttr(sal_uInt16 _nPos,
109 : : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn);
110 : :
111 : : virtual sal_Bool isIndexed() const;
112 : : virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0);
113 : : TYPEINFO();
114 : : };
115 : :
116 : : // Parameter for a predicate
117 [ - + ]: 48 : class OOperandParam : public OOperandRow
118 : : {
119 : : public:
120 : : OOperandParam(connectivity::OSQLParseNode* pNode, sal_Int32 _nPos);
121 : : TYPEINFO();
122 : : };
123 : :
124 : : // Value operands
125 [ + - ][ - + ]: 132 : class OOperandValue : public OOperand
126 : : {
127 : : protected:
128 : : ORowSetValue m_aValue;
129 : :
130 : : protected:
131 : 96 : OOperandValue(){}
132 : 0 : OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType)
133 : : : OOperand(eDbType)
134 [ # # ]: 0 : , m_aValue(_rVar)
135 : 0 : {}
136 : :
137 : 36 : OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){}
138 : : public:
139 : : virtual const ORowSetValue& getValue() const;
140 : : virtual void setValue(const ORowSetValue& _rVal);
141 : :
142 : : TYPEINFO();
143 : : };
144 : :
145 : :
146 : : // Constants
147 [ - + ]: 192 : class OOperandConst : public OOperandValue
148 : : {
149 : : public:
150 : : OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const rtl::OUString& aStrValue);
151 : :
152 : : TYPEINFO();
153 : : };
154 : :
155 : :
156 : : // Result operands
157 [ - + ]: 36 : class OOperandResult : public OOperandValue
158 : : {
159 : : protected:
160 : : OOperandResult(const ORowSetValue& _rVar, sal_Int32 eDbType)
161 : : :OOperandValue(_rVar, eDbType) {}
162 : 36 : OOperandResult(sal_Int32 eDbType)
163 : 36 : :OOperandValue(eDbType) {}
164 : : public:
165 : 0 : OOperandResult(const ORowSetValue& _rVar)
166 : 0 : :OOperandValue(_rVar, _rVar.getTypeKind()) {}
167 : : TYPEINFO();
168 : : };
169 : :
170 : :
171 [ - + ]: 72 : class OOperandResultBOOL : public OOperandResult
172 : : {
173 : : public:
174 : 36 : OOperandResultBOOL(sal_Bool bResult) : OOperandResult(::com::sun::star::sdbc::DataType::BIT)
175 : : {
176 [ + - ][ + + ]: 36 : m_aValue = bResult ? 1.0 : 0.0;
177 : 36 : m_aValue.setBound(sal_True);
178 : 36 : }
179 : : };
180 : :
181 [ # # ]: 0 : class OOperandResultNUM : public OOperandResult
182 : : {
183 : : public:
184 : 0 : OOperandResultNUM(double fNum) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE)
185 : : {
186 [ # # ]: 0 : m_aValue = fNum;
187 : 0 : m_aValue.setBound(sal_True);
188 : 0 : }
189 : : };
190 : :
191 : : /** special stop operand
192 : : is appended when a list of arguments ends
193 : : */
194 [ # # ]: 0 : class OStopOperand : public OOperandValue
195 : : {
196 : : public:
197 : 0 : OStopOperand(){}
198 : : TYPEINFO();
199 : : };
200 : :
201 : : // Operators
202 [ - + ]: 168 : class OOO_DLLPUBLIC_FILE OOperator : public OCode
203 : : {
204 : : public:
205 : : virtual void Exec(OCodeStack&) = 0;
206 : : virtual sal_uInt16 getRequestedOperands() const; // Count of requested operands
207 : : // Defaults to 2
208 : : TYPEINFO();
209 : : };
210 : :
211 : :
212 : : // Boolean operators
213 [ - + ]: 168 : class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator
214 : : {
215 : : public:
216 : : TYPEINFO();
217 : : virtual void Exec(OCodeStack&);
218 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
219 : : };
220 : :
221 [ # # ]: 0 : class OOp_NOT : public OBoolOperator
222 : : {
223 : : public:
224 : : TYPEINFO();
225 : :
226 : : protected:
227 : : virtual void Exec(OCodeStack&);
228 : : virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
229 : : virtual sal_uInt16 getRequestedOperands() const;
230 : : };
231 : :
232 [ - + ]: 36 : class OOp_AND : public OBoolOperator
233 : : {
234 : : public:
235 : : TYPEINFO();
236 : :
237 : : protected:
238 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
239 : : };
240 : :
241 [ # # ]: 0 : class OOp_OR : public OBoolOperator
242 : : {
243 : : public:
244 : : TYPEINFO();
245 : : protected:
246 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
247 : : };
248 : :
249 [ # # ]: 0 : class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator
250 : : {
251 : : public:
252 : : TYPEINFO();
253 : : public:
254 : : virtual void Exec(OCodeStack&);
255 : : virtual sal_uInt16 getRequestedOperands() const;
256 : : virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
257 : : };
258 : :
259 [ # # ]: 0 : class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL
260 : : {
261 : : public:
262 : : TYPEINFO();
263 : : virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const;
264 : : };
265 : :
266 [ # # ]: 0 : class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator
267 : : {
268 : : public:
269 : : TYPEINFO();
270 : : protected:
271 : : const sal_Unicode cEscape;
272 : :
273 : : public:
274 : 0 : OOp_LIKE(const sal_Unicode cEsc = L'\0'):cEscape(cEsc){};
275 : :
276 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
277 : : };
278 : :
279 [ # # ]: 0 : class OOp_NOTLIKE : public OOp_LIKE
280 : : {
281 : : public:
282 : : TYPEINFO();
283 : : public:
284 : 0 : OOp_NOTLIKE(const sal_Unicode cEsc = L'\0'):OOp_LIKE(cEsc){};
285 : :
286 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
287 : : };
288 : :
289 [ - + ]: 144 : class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator
290 : : {
291 : : sal_Int32 aPredicateType;
292 : :
293 : : public:
294 : : TYPEINFO();
295 : 72 : OOp_COMPARE(sal_Int32 aPType)
296 : 72 : :aPredicateType(aPType) {}
297 : :
298 : 0 : inline sal_Int32 getPredicateType() const { return aPredicateType; }
299 : : virtual sal_Bool operate(const OOperand*, const OOperand*) const;
300 : : };
301 : :
302 : : // Numerical operators
303 [ # # ]: 0 : class ONumOperator : public OOperator
304 : : {
305 : : public:
306 : : virtual void Exec(OCodeStack&);
307 : :
308 : : TYPEINFO();
309 : :
310 : : protected:
311 : : virtual double operate(const double& fLeft,const double& fRight) const = 0;
312 : : };
313 : :
314 [ # # ]: 0 : class OOp_ADD : public ONumOperator
315 : : {
316 : : protected:
317 : : virtual double operate(const double& fLeft,const double& fRight) const;
318 : : };
319 : :
320 [ # # ]: 0 : class OOp_SUB : public ONumOperator
321 : : {
322 : : protected:
323 : : virtual double operate(const double& fLeft,const double& fRight) const;
324 : : };
325 : :
326 [ # # ]: 0 : class OOp_MUL : public ONumOperator
327 : : {
328 : : protected:
329 : : virtual double operate(const double& fLeft,const double& fRight) const;
330 : : };
331 : :
332 [ # # ]: 0 : class OOp_DIV : public ONumOperator
333 : : {
334 : : protected:
335 : : virtual double operate(const double& fLeft,const double& fRight) const;
336 : : };
337 : :
338 : 36 : inline sal_Bool OOperand::isValid() const
339 : : {
340 : 36 : return getValue().getDouble() != double(0.0);
341 : : }
342 : :
343 : : // Operator
344 [ # # ]: 0 : class ONthOperator : public OOperator
345 : : {
346 : : public:
347 : : virtual void Exec(OCodeStack&);
348 : :
349 : : TYPEINFO();
350 : :
351 : : protected:
352 : : virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const = 0;
353 : : };
354 : :
355 [ # # ]: 0 : class OBinaryOperator : public OOperator
356 : : {
357 : : public:
358 : : virtual void Exec(OCodeStack&);
359 : :
360 : : TYPEINFO();
361 : :
362 : : protected:
363 : : virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0;
364 : : };
365 : :
366 [ # # ]: 0 : class OUnaryOperator : public OOperator
367 : : {
368 : : public:
369 : : virtual void Exec(OCodeStack&);
370 : : virtual sal_uInt16 getRequestedOperands() const;
371 : : virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0;
372 : :
373 : : TYPEINFO();
374 : :
375 : : };
376 : : }
377 : : }
378 : :
379 : : #endif // _CONNECTIVITY_FILE_FCODE_HXX_
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|