1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef CONNECTIVITY_ROWFUNCTIONPARSER_HXX_INCLUDED 25 #define CONNECTIVITY_ROWFUNCTIONPARSER_HXX_INCLUDED 26 27 #include <sal/config.h> 28 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED 29 #include <boost/shared_ptr.hpp> 30 #endif 31 #include "FDatabaseMetaDataResultSet.hxx" 32 #include <vector> 33 #include "connectivity/dbtoolsdllapi.hxx" 34 35 // ------------------------------------------------------------------------- 36 namespace connectivity 37 { 38 // ------------------------------------------------------------------------- 39 struct OOO_DLLPUBLIC_DBTOOLS RowEquation 40 { 41 sal_Int32 nOperation; 42 ORowSetValueDecoratorRef nPara[ 3 ]; 43 RowEquationconnectivity::RowEquation44 RowEquation() : 45 nOperation ( 0 ) 46 { 47 } 48 }; 49 50 enum ExpressionFunct 51 { 52 FUNC_CONST, 53 54 ENUM_FUNC_EQUATION, 55 56 UNARY_FUNC_COLUMN, 57 ENUM_FUNC_AND, 58 ENUM_FUNC_OR 59 }; 60 61 #define EXPRESSION_FLAG_SUMANGLE_MODE 1 62 63 class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE ExpressionNode 64 { 65 public: ~ExpressionNode()66 virtual ~ExpressionNode(){} 67 68 /** Operator to calculate function value. 69 70 This method calculates the function value. 71 */ 72 virtual ORowSetValueDecoratorRef evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow ) const = 0; 73 74 virtual void fill(const ODatabaseMetaDataResultSet::ORow& _aRow ) const = 0; 75 76 /** Operator to retrieve the type of expression node 77 */ 78 virtual ExpressionFunct getType() const = 0; 79 80 /** Operator to retrieve the ms version of expression 81 */ 82 virtual ODatabaseMetaDataResultSet::ORow fillNode( 83 std::vector< RowEquation >& rEquations, ExpressionNode* pOptionalArg, sal_uInt32 nFlags ) = 0; 84 }; 85 typedef ::boost::shared_ptr< ExpressionNode > ExpressionNodeSharedPtr; 86 87 /** This exception is thrown, when the arithmetic expression 88 parser failed to parse a string. 89 */ 90 struct OOO_DLLPUBLIC_DBTOOLS ParseError 91 { ParseErrorconnectivity::ParseError92 ParseError() {} ParseErrorconnectivity::ParseError93 ParseError( const char* ) {} 94 }; 95 96 class OOO_DLLPUBLIC_DBTOOLS FunctionParser 97 { 98 public: 99 100 /** Parse a string 101 102 The following grammar is accepted by this method: 103 <code> 104 105 number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' 106 107 number = number number_digit | number_digit 108 109 equal_function = '=' 110 ternary_function = 'if' 111 112 string_reference = 'a-z,A-Z,0-9' ' ' 113 modifier_reference = '$' '0-9' ' ' 114 115 basic_expression = 116 number | 117 string_reference | 118 additive_expression equal_function additive_expression | 119 unary_function '(' number_digit ')' 120 ternary_function '(' additive_expression ',' additive_expression ', 121 ' additive_expression ')' | '(' additive_expression ')' 122 123 </code> 124 125 @param rFunction 126 The string to parse 127 128 @throws ParseError if an invalid expression is given. 129 130 @return the generated function object. 131 */ 132 133 static ExpressionNodeSharedPtr parseFunction( const ::rtl::OUString& _sFunction); 134 135 private: 136 // disabled constructor/destructor, since this is 137 // supposed to be a singleton 138 FunctionParser(); 139 140 // default: disabled copy/assignment 141 FunctionParser(const FunctionParser&); 142 FunctionParser& operator=( const FunctionParser& ); 143 }; 144 145 // ------------------------------------------------------------------------- 146 } // namespace connectivity 147 // ------------------------------------------------------------------------- 148 #endif /* CONNECTIVITY_ROWFUNCTIONPARSER_HXX_INCLUDED */ 149