Branch libreoffice-5-0-4
[LibreOffice.git] / include / svx / EnhancedCustomShapeFunctionParser.hxx
blob9f4f464e71332b89e3276d0fe89e81f0a0e97aac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <memory>
27 #include <vector>
29 #include <svx/svxdllapi.h>
31 struct EnhancedCustomShapeEquation
33 sal_Int32 nOperation;
34 sal_Int32 nPara[ 3 ];
36 EnhancedCustomShapeEquation() :
37 nOperation ( 0 )
39 nPara[ 0 ] = nPara[ 1 ] = nPara[ 2 ] = 0;
43 class EnhancedCustomShape2d;
45 namespace EnhancedCustomShape {
47 enum ExpressionFunct
49 FUNC_CONST,
51 ENUM_FUNC_PI,
52 ENUM_FUNC_LEFT,
53 ENUM_FUNC_TOP,
54 ENUM_FUNC_RIGHT,
55 ENUM_FUNC_BOTTOM,
56 ENUM_FUNC_XSTRETCH,
57 ENUM_FUNC_YSTRETCH,
58 ENUM_FUNC_HASSTROKE,
59 ENUM_FUNC_HASFILL,
60 ENUM_FUNC_WIDTH,
61 ENUM_FUNC_HEIGHT,
62 ENUM_FUNC_LOGWIDTH,
63 ENUM_FUNC_LOGHEIGHT,
64 ENUM_FUNC_ADJUSTMENT,
65 ENUM_FUNC_EQUATION,
67 UNARY_FUNC_ABS,
68 UNARY_FUNC_SQRT,
69 UNARY_FUNC_SIN,
70 UNARY_FUNC_COS,
71 UNARY_FUNC_TAN,
72 UNARY_FUNC_ATAN,
73 UNARY_FUNC_NEG,
75 BINARY_FUNC_PLUS,
76 BINARY_FUNC_MINUS,
77 BINARY_FUNC_MUL,
78 BINARY_FUNC_DIV,
79 BINARY_FUNC_MIN,
80 BINARY_FUNC_MAX,
81 BINARY_FUNC_ATAN2,
83 TERNARY_FUNC_IF
86 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
88 SVX_DLLPUBLIC void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter&, const sal_Int32, EnhancedCustomShapeEquation& );
90 class ExpressionNode
92 public:
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
101 ExpressionNodes.
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.
127 struct ParseError
129 ParseError() {}
130 ParseError( const char* ) {}
133 class FunctionParser
135 public:
137 /** Parse a string
139 The following grammar is accepted by this method:
140 <code>
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' ' '
156 basic_expression =
157 number |
158 identifier |
159 function_reference |
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 =
168 basic_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
177 </code>
179 @param rFunction
180 The string to parse
182 @param rCustoShape
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 );
193 private:
194 // disabled constructor/destructor, since this is
195 // supposed to be a singleton
196 FunctionParser();
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: */