1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EnhancedCustomShapeFunctionParser.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
32 #define _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
34 #include <sal/config.h>
35 #include <boost/shared_ptr.hpp>
36 #include "EnhancedCustomShapeFunctionParser.hxx"
37 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
38 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
41 #include <svx/svxdllapi.h>
43 struct EnhancedCustomShapeEquation
48 EnhancedCustomShapeEquation() :
51 nPara
[ 0 ] = nPara
[ 1 ] = nPara
[ 2 ] = 0;
55 class EnhancedCustomShape2d
;
57 namespace EnhancedCustomShape
{
98 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
100 SVX_DLLPUBLIC
void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter
&, const sal_Int32
, EnhancedCustomShapeEquation
& );
105 virtual ~ExpressionNode();
107 /** Predicate whether this node is constant.
109 This predicate returns true, if this node is
110 neither time- nor ViewInfo dependent. This allows
111 for certain obtimizations, i.e. not the full
112 expression tree needs be represented by
115 @returns true, if the note is constant
117 virtual bool isConstant() const = 0;
119 /** Operator to calculate function value.
121 This method calculates the function value.
123 virtual double operator()() const = 0;
125 /** Operator to retrieve the type of expression node
127 virtual ExpressionFunct
getType() const = 0;
129 /** Operator to retrieve the ms version of expression
131 virtual com::sun::star::drawing::EnhancedCustomShapeParameter
fillNode(
132 std::vector
< EnhancedCustomShapeEquation
>& rEquations
, ExpressionNode
* pOptionalArg
, sal_uInt32 nFlags
) = 0;
134 typedef ::boost::shared_ptr
< ExpressionNode
> ExpressionNodeSharedPtr
;
136 /** This exception is thrown, when the arithmetic expression
137 parser failed to parse a string.
142 ParseError( const char* ) {}
151 The following grammar is accepted by this method:
154 number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
156 number = number number_digit | number_digit
158 identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
159 'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
161 unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
162 binary_function = 'min'|'max'|'atan2'
163 ternary_function = 'if'
165 function_reference = '?' 'a-z,A-Z,0-9' ' '
166 modifier_reference = '$' '0-9' ' '
172 unary_function '(' additive_expression ')' |
173 binary_function '(' additive_expression ',' additive_expression ')' |
174 ternary_function '(' additive_expression ',' additive_expression ',
175 ' additive_expression ')' | '(' additive_expression ')'
177 unary_expression = '-' basic_expression
179 multiplicative_expression =
181 multiplicative_expression '*' basic_expression |
182 multiplicative_expression '/' basic_expression
184 additive_expression =
185 multiplicative_expression |
186 additive_expression '+' multiplicative_expression |
187 additive_expression '-' multiplicative_expression
195 The CustomShape is required for calculation of dynamic values such
196 "hasstroke", function references and or modifier references ...
198 @throws ParseError if an invalid expression is given.
200 @return the generated function object.
203 SVX_DLLPUBLIC
static ExpressionNodeSharedPtr
parseFunction( const ::rtl::OUString
& rFunction
, const EnhancedCustomShape2d
& rCustoShape
);
206 // disabled constructor/destructor, since this is
207 // supposed to be a singleton
210 // default: disabled copy/assignment
211 FunctionParser(const FunctionParser
&);
212 FunctionParser
& operator=( const FunctionParser
& );
217 #endif /* _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX */