Update ooo320-m1
[ooovba.git] / svx / inc / EnhancedCustomShapeFunctionParser.hxx
blobcdfa4dadaddd60f2695c4c758206a24c19608b4a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EnhancedCustomShapeFunctionParser.hxx,v $
10 * $Revision: 1.4 $
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>
39 #include <vector>
41 #include <svx/svxdllapi.h>
43 struct EnhancedCustomShapeEquation
45 sal_Int32 nOperation;
46 sal_Int32 nPara[ 3 ];
48 EnhancedCustomShapeEquation() :
49 nOperation ( 0 )
51 nPara[ 0 ] = nPara[ 1 ] = nPara[ 2 ] = 0;
55 class EnhancedCustomShape2d;
57 namespace EnhancedCustomShape {
59 enum ExpressionFunct
61 FUNC_CONST,
63 ENUM_FUNC_PI,
64 ENUM_FUNC_LEFT,
65 ENUM_FUNC_TOP,
66 ENUM_FUNC_RIGHT,
67 ENUM_FUNC_BOTTOM,
68 ENUM_FUNC_XSTRETCH,
69 ENUM_FUNC_YSTRETCH,
70 ENUM_FUNC_HASSTROKE,
71 ENUM_FUNC_HASFILL,
72 ENUM_FUNC_WIDTH,
73 ENUM_FUNC_HEIGHT,
74 ENUM_FUNC_LOGWIDTH,
75 ENUM_FUNC_LOGHEIGHT,
76 ENUM_FUNC_ADJUSTMENT,
77 ENUM_FUNC_EQUATION,
79 UNARY_FUNC_ABS,
80 UNARY_FUNC_SQRT,
81 UNARY_FUNC_SIN,
82 UNARY_FUNC_COS,
83 UNARY_FUNC_TAN,
84 UNARY_FUNC_ATAN,
85 UNARY_FUNC_NEG,
87 BINARY_FUNC_PLUS,
88 BINARY_FUNC_MINUS,
89 BINARY_FUNC_MUL,
90 BINARY_FUNC_DIV,
91 BINARY_FUNC_MIN,
92 BINARY_FUNC_MAX,
93 BINARY_FUNC_ATAN2,
95 TERNARY_FUNC_IF
98 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
100 SVX_DLLPUBLIC void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter&, const sal_Int32, EnhancedCustomShapeEquation& );
102 class ExpressionNode
104 public:
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
113 ExpressionNodes.
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.
139 struct ParseError
141 ParseError() {}
142 ParseError( const char* ) {}
145 class FunctionParser
147 public:
149 /** Parse a string
151 The following grammar is accepted by this method:
152 <code>
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' ' '
168 basic_expression =
169 number |
170 identifier |
171 function_reference |
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 =
180 basic_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
189 </code>
191 @param rFunction
192 The string to parse
194 @param rCustoShape
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 );
205 private:
206 // disabled constructor/destructor, since this is
207 // supposed to be a singleton
208 FunctionParser();
210 // default: disabled copy/assignment
211 FunctionParser(const FunctionParser&);
212 FunctionParser& operator=( const FunctionParser& );
217 #endif /* _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX */