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