1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
21 #define INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
23 #include <sal/config.h>
24 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
25 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
29 #include <svx/svxdllapi.h>
31 struct EnhancedCustomShapeEquation
36 EnhancedCustomShapeEquation() :
39 nPara
[ 0 ] = nPara
[ 1 ] = nPara
[ 2 ] = 0;
43 class EnhancedCustomShape2d
;
45 namespace EnhancedCustomShape
{
86 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
88 SVX_DLLPUBLIC
void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter
&, const sal_Int32
, EnhancedCustomShapeEquation
& );
93 virtual ~ExpressionNode();
95 /** Predicate whether this node is constant.
97 This predicate returns true, if this node is
98 neither time- nor ViewInfo dependent. This allows
99 for certain obtimizations, i.e. not the full
100 expression tree needs be represented by
103 @returns true, if the note is constant
105 virtual bool isConstant() const = 0;
107 /** Operator to calculate function value.
109 This method calculates the function value.
111 virtual double operator()() const = 0;
113 /** Operator to retrieve the type of expression node
115 virtual ExpressionFunct
getType() const = 0;
117 /** Operator to retrieve the ms version of expression
119 virtual com::sun::star::drawing::EnhancedCustomShapeParameter
fillNode(
120 std::vector
< EnhancedCustomShapeEquation
>& rEquations
, ExpressionNode
* pOptionalArg
, sal_uInt32 nFlags
) = 0;
122 typedef std::shared_ptr
< ExpressionNode
> ExpressionNodeSharedPtr
;
124 /** This exception is thrown, when the arithmetic expression
125 parser failed to parse a string.
130 ParseError( const char* ) {}
139 The following grammar is accepted by this method:
142 number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
144 number = number number_digit | number_digit
146 identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
147 'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
149 unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
150 binary_function = 'min'|'max'|'atan2'
151 ternary_function = 'if'
153 function_reference = '?' 'a-z,A-Z,0-9' ' '
154 modifier_reference = '$' '0-9' ' '
160 unary_function '(' additive_expression ')' |
161 binary_function '(' additive_expression ',' additive_expression ')' |
162 ternary_function '(' additive_expression ',' additive_expression ',
163 ' additive_expression ')' | '(' additive_expression ')'
165 unary_expression = '-' basic_expression
167 multiplicative_expression =
169 multiplicative_expression '*' basic_expression |
170 multiplicative_expression '/' basic_expression
172 additive_expression =
173 multiplicative_expression |
174 additive_expression '+' multiplicative_expression |
175 additive_expression '-' multiplicative_expression
183 The CustomShape is required for calculation of dynamic values such
184 "hasstroke", function references and or modifier references ...
186 @throws ParseError if an invalid expression is given.
188 @return the generated function object.
191 SVX_DLLPUBLIC
static ExpressionNodeSharedPtr
parseFunction( const OUString
& rFunction
, const EnhancedCustomShape2d
& rCustoShape
);
194 // disabled constructor/destructor, since this is
195 // supposed to be a singleton
198 FunctionParser(const FunctionParser
&) SAL_DELETED_FUNCTION
;
199 FunctionParser
& operator=( const FunctionParser
& ) SAL_DELETED_FUNCTION
;
204 #endif // INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */