LCOV - code coverage report
Current view: top level - include/svx - EnhancedCustomShapeFunctionParser.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 6 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
      21             : #define INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : #include <boost/shared_ptr.hpp>
      25             : #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
      26             : #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
      27             : #include <vector>
      28             : 
      29             : #include <svx/svxdllapi.h>
      30             : 
      31             : struct EnhancedCustomShapeEquation
      32             : {
      33             :     sal_Int32   nOperation;
      34             :     sal_Int32   nPara[ 3 ];
      35             : 
      36           0 :     EnhancedCustomShapeEquation() :
      37           0 :         nOperation  ( 0 )
      38             :         {
      39           0 :             nPara[ 0 ] = nPara[ 1 ] = nPara[ 2 ] = 0;
      40           0 :         }
      41             : };
      42             : 
      43             : class EnhancedCustomShape2d;
      44             : 
      45             : namespace EnhancedCustomShape {
      46             : 
      47             : enum ExpressionFunct
      48             : {
      49             :     FUNC_CONST,
      50             : 
      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,
      66             : 
      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,
      74             : 
      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,
      82             : 
      83             :     TERNARY_FUNC_IF
      84             : };
      85             : 
      86             : #define EXPRESSION_FLAG_SUMANGLE_MODE 1
      87             : 
      88             : SVX_DLLPUBLIC void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter&, const sal_Int32, EnhancedCustomShapeEquation& );
      89             : 
      90           0 : class ExpressionNode
      91             : {
      92             : public:
      93             :     virtual ~ExpressionNode();
      94             : 
      95             :     /** Predicate whether this node is constant.
      96             : 
      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.
     102             : 
     103             :         @returns true, if the note is constant
     104             :     */
     105             :     virtual bool isConstant() const = 0;
     106             : 
     107             :     /** Operator to calculate function value.
     108             : 
     109             :         This method calculates the function value.
     110             :     */
     111             :     virtual double operator()() const = 0;
     112             : 
     113             :     /** Operator to retrieve the type of expression node
     114             :     */
     115             :     virtual ExpressionFunct getType() const = 0;
     116             : 
     117             :     /** Operator to retrieve the ms version of expression
     118             :     */
     119             :     virtual com::sun::star::drawing::EnhancedCustomShapeParameter fillNode(
     120             :         std::vector< EnhancedCustomShapeEquation >& rEquations, ExpressionNode* pOptionalArg, sal_uInt32 nFlags ) = 0;
     121             : };
     122             : typedef ::boost::shared_ptr< ExpressionNode > ExpressionNodeSharedPtr;
     123             : 
     124             : /** This exception is thrown, when the arithmetic expression
     125             :     parser failed to parse a string.
     126             :     */
     127             : struct ParseError
     128             : {
     129             :     ParseError() {}
     130           0 :     ParseError( const char* ) {}
     131             : };
     132             : 
     133             : class FunctionParser
     134             : {
     135             : public:
     136             : 
     137             :     /** Parse a string
     138             : 
     139             :         The following grammar is accepted by this method:
     140             :         <code>
     141             : 
     142             :         number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
     143             : 
     144             :         number = number number_digit | number_digit
     145             : 
     146             :         identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
     147             :                  'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
     148             : 
     149             :         unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
     150             :         binary_function = 'min'|'max'|'atan2'
     151             :         ternary_function = 'if'
     152             : 
     153             :         function_reference = '?' 'a-z,A-Z,0-9' ' '
     154             :         modifier_reference = '$' '0-9' ' '
     155             : 
     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 ')'
     164             : 
     165             :         unary_expression = '-' basic_expression
     166             : 
     167             :         multiplicative_expression =
     168             :                           basic_expression |
     169             :                           multiplicative_expression '*' basic_expression |
     170             :                           multiplicative_expression '/' basic_expression
     171             : 
     172             :         additive_expression =
     173             :                         multiplicative_expression |
     174             :                         additive_expression '+' multiplicative_expression |
     175             :                         additive_expression '-' multiplicative_expression
     176             : 
     177             :         </code>
     178             : 
     179             :         @param rFunction
     180             :         The string to parse
     181             : 
     182             :         @param rCustoShape
     183             :         The CustomShape is required for calculation of dynamic values such
     184             :         "hasstroke", function references and or modifier references ...
     185             : 
     186             :         @throws ParseError if an invalid expression is given.
     187             : 
     188             :         @return the generated function object.
     189             :        */
     190             : 
     191             :     SVX_DLLPUBLIC static ExpressionNodeSharedPtr parseFunction( const OUString& rFunction, const EnhancedCustomShape2d& rCustoShape );
     192             : 
     193             : private:
     194             :     // disabled constructor/destructor, since this is
     195             :     // supposed to be a singleton
     196             :     FunctionParser();
     197             : 
     198             :     // default: disabled copy/assignment
     199             :     FunctionParser(const FunctionParser&);
     200             :     FunctionParser& operator=( const FunctionParser& );
     201             : };
     202             : 
     203             : }
     204             : 
     205             : #endif // INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10