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 _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
21 #define _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
23 #include <sal/config.h>
24 #include <boost/shared_ptr.hpp>
25 #include "EnhancedCustomShapeFunctionParser.hxx"
26 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
27 #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
30 #include <svx/svxdllapi.h>
32 struct EnhancedCustomShapeEquation
37 EnhancedCustomShapeEquation() :
40 nPara
[ 0 ] = nPara
[ 1 ] = nPara
[ 2 ] = 0;
44 class EnhancedCustomShape2d
;
46 namespace EnhancedCustomShape
{
87 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
89 SVX_DLLPUBLIC
void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter
&, const sal_Int32
, EnhancedCustomShapeEquation
& );
94 virtual ~ExpressionNode();
96 /** Predicate whether this node is constant.
98 This predicate returns true, if this node is
99 neither time- nor ViewInfo dependent. This allows
100 for certain obtimizations, i.e. not the full
101 expression tree needs be represented by
104 @returns true, if the note is constant
106 virtual bool isConstant() const = 0;
108 /** Operator to calculate function value.
110 This method calculates the function value.
112 virtual double operator()() const = 0;
114 /** Operator to retrieve the type of expression node
116 virtual ExpressionFunct
getType() const = 0;
118 /** Operator to retrieve the ms version of expression
120 virtual com::sun::star::drawing::EnhancedCustomShapeParameter
fillNode(
121 std::vector
< EnhancedCustomShapeEquation
>& rEquations
, ExpressionNode
* pOptionalArg
, sal_uInt32 nFlags
) = 0;
123 typedef ::boost::shared_ptr
< ExpressionNode
> ExpressionNodeSharedPtr
;
125 /** This exception is thrown, when the arithmetic expression
126 parser failed to parse a string.
131 ParseError( const char* ) {}
140 The following grammar is accepted by this method:
143 number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
145 number = number number_digit | number_digit
147 identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
148 'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
150 unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
151 binary_function = 'min'|'max'|'atan2'
152 ternary_function = 'if'
154 function_reference = '?' 'a-z,A-Z,0-9' ' '
155 modifier_reference = '$' '0-9' ' '
161 unary_function '(' additive_expression ')' |
162 binary_function '(' additive_expression ',' additive_expression ')' |
163 ternary_function '(' additive_expression ',' additive_expression ',
164 ' additive_expression ')' | '(' additive_expression ')'
166 unary_expression = '-' basic_expression
168 multiplicative_expression =
170 multiplicative_expression '*' basic_expression |
171 multiplicative_expression '/' basic_expression
173 additive_expression =
174 multiplicative_expression |
175 additive_expression '+' multiplicative_expression |
176 additive_expression '-' multiplicative_expression
184 The CustomShape is required for calculation of dynamic values such
185 "hasstroke", function references and or modifier references ...
187 @throws ParseError if an invalid expression is given.
189 @return the generated function object.
192 SVX_DLLPUBLIC
static ExpressionNodeSharedPtr
parseFunction( const OUString
& rFunction
, const EnhancedCustomShape2d
& rCustoShape
);
195 // disabled constructor/destructor, since this is
196 // supposed to be a singleton
199 // default: disabled copy/assignment
200 FunctionParser(const FunctionParser
&);
201 FunctionParser
& operator=( const FunctionParser
& );
206 #endif /* _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX */
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */