bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / inc / file / fcode.hxx
blob681a3e4310d71ba91b310d670aee75422b1d8d4a
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 #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
34 class OSQLParseNode;
35 namespace file
38 class OOperand;
39 typedef ::std::stack<OOperand*> OCodeStack;
40 class OBoolOperator;
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
48 public:
49 OCode();
50 virtual ~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 )
55 { return _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*/ )
59 { }
61 TYPEINFO();
65 // operands that the parsetree generate
66 class OOO_DLLPUBLIC_FILE OOperand : public OCode
68 protected:
69 sal_Int32 m_eDBType;
71 OOperand(const sal_Int32& _rType) : m_eDBType(_rType){}
72 OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER){}
74 public:
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;
82 TYPEINFO_OVERRIDE();
85 class OOO_DLLPUBLIC_FILE OOperandRow : public OOperand
87 sal_uInt16 m_nRowPos;
88 protected:
89 OValueRefRow m_pRow;
91 OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType);
92 public:
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
98 TYPEINFO_OVERRIDE();
101 // Attributes from a result row
102 class OOO_DLLPUBLIC_FILE OOperandAttr : public OOperandRow
104 protected:
105 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xColumn;
107 public:
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;
113 TYPEINFO_OVERRIDE();
116 // Parameter for a predicate
117 class OOperandParam : public OOperandRow
119 public:
120 OOperandParam(connectivity::OSQLParseNode* pNode, sal_Int32 _nPos);
121 TYPEINFO_OVERRIDE();
124 // Value operands
125 class OOperandValue : public OOperand
127 protected:
128 ORowSetValue m_aValue;
130 protected:
131 OOperandValue(){}
132 OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType)
133 : OOperand(eDbType)
134 , m_aValue(_rVar)
137 OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){}
138 public:
139 virtual const ORowSetValue& getValue() const SAL_OVERRIDE;
140 virtual void setValue(const ORowSetValue& _rVal) SAL_OVERRIDE;
142 TYPEINFO_OVERRIDE();
146 // Constants
147 class OOperandConst : public OOperandValue
149 public:
150 OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const OUString& aStrValue);
152 TYPEINFO_OVERRIDE();
156 // Result operands
157 class OOperandResult : public OOperandValue
159 protected:
160 OOperandResult(const ORowSetValue& _rVar, sal_Int32 eDbType)
161 :OOperandValue(_rVar, eDbType) {}
162 OOperandResult(sal_Int32 eDbType)
163 :OOperandValue(eDbType) {}
164 public:
165 OOperandResult(const ORowSetValue& _rVar)
166 :OOperandValue(_rVar, _rVar.getTypeKind()) {}
167 TYPEINFO_OVERRIDE();
171 class OOperandResultBOOL : public OOperandResult
173 public:
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
183 public:
184 OOperandResultNUM(double fNum) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE)
186 m_aValue = fNum;
187 m_aValue.setBound(true);
191 /** special stop operand
192 is appended when a list of arguments ends
194 class OStopOperand : public OOperandValue
196 public:
197 OStopOperand(){}
198 TYPEINFO_OVERRIDE();
201 // Operators
202 class OOO_DLLPUBLIC_FILE OOperator : public OCode
204 public:
205 virtual void Exec(OCodeStack&) = 0;
206 virtual sal_uInt16 getRequestedOperands() const; // Count of requested operands
207 // Defaults to 2
208 TYPEINFO_OVERRIDE();
212 // Boolean operators
213 class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator
215 public:
216 TYPEINFO_OVERRIDE();
217 virtual void Exec(OCodeStack&) SAL_OVERRIDE;
218 virtual bool operate(const OOperand*, const OOperand*) const;
221 class OOp_NOT : public OBoolOperator
223 public:
224 TYPEINFO_OVERRIDE();
226 protected:
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
234 public:
235 TYPEINFO_OVERRIDE();
237 protected:
238 virtual bool operate(const OOperand*, const OOperand*) const SAL_OVERRIDE;
241 class OOp_OR : public OBoolOperator
243 public:
244 TYPEINFO_OVERRIDE();
245 protected:
246 virtual bool operate(const OOperand*, const OOperand*) const SAL_OVERRIDE;
249 class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator
251 public:
252 TYPEINFO_OVERRIDE();
253 public:
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
261 public:
262 TYPEINFO_OVERRIDE();
263 virtual bool operate(const OOperand*, const OOperand* = NULL) const SAL_OVERRIDE;
266 class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator
268 public:
269 TYPEINFO_OVERRIDE();
270 protected:
271 const sal_Unicode cEscape;
273 public:
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
281 public:
282 TYPEINFO_OVERRIDE();
283 public:
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;
293 public:
294 TYPEINFO_OVERRIDE();
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
305 public:
306 virtual void Exec(OCodeStack&) SAL_OVERRIDE;
308 TYPEINFO_OVERRIDE();
310 protected:
311 virtual double operate(const double& fLeft,const double& fRight) const = 0;
314 class OOp_ADD : public ONumOperator
316 protected:
317 virtual double operate(const double& fLeft,const double& fRight) const SAL_OVERRIDE;
320 class OOp_SUB : public ONumOperator
322 protected:
323 virtual double operate(const double& fLeft,const double& fRight) const SAL_OVERRIDE;
326 class OOp_MUL : public ONumOperator
328 protected:
329 virtual double operate(const double& fLeft,const double& fRight) const SAL_OVERRIDE;
332 class OOp_DIV : public ONumOperator
334 protected:
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);
343 // Operator
344 class ONthOperator : public OOperator
346 public:
347 virtual void Exec(OCodeStack&) SAL_OVERRIDE;
349 TYPEINFO_OVERRIDE();
351 protected:
352 virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const = 0;
355 class OBinaryOperator : public OOperator
357 public:
358 virtual void Exec(OCodeStack&) SAL_OVERRIDE;
360 TYPEINFO_OVERRIDE();
362 protected:
363 virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0;
366 class OUnaryOperator : public OOperator
368 public:
369 virtual void Exec(OCodeStack&) SAL_OVERRIDE;
370 virtual sal_uInt16 getRequestedOperands() const SAL_OVERRIDE;
371 virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0;
373 TYPEINFO_OVERRIDE();
379 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */