LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/svx - EnhancedCustomShapeFunctionParser.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 4 0.0 %
Date: 2012-12-27 Functions: 0 1 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 _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
      21             : #define _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
      22             : 
      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>
      28             : #include <vector>
      29             : 
      30             : #include <svx/svxdllapi.h>
      31             : 
      32             : struct EnhancedCustomShapeEquation
      33             : {
      34             :     sal_Int32   nOperation;
      35             :     sal_Int32   nPara[ 3 ];
      36             : 
      37           0 :     EnhancedCustomShapeEquation() :
      38           0 :         nOperation  ( 0 )
      39             :         {
      40           0 :             nPara[ 0 ] = nPara[ 1 ] = nPara[ 2 ] = 0;
      41           0 :         }
      42             : };
      43             : 
      44             : class EnhancedCustomShape2d;
      45             : 
      46             : namespace EnhancedCustomShape {
      47             : 
      48             : enum ExpressionFunct
      49             : {
      50             :     FUNC_CONST,
      51             : 
      52             :     ENUM_FUNC_PI,
      53             :     ENUM_FUNC_LEFT,
      54             :     ENUM_FUNC_TOP,
      55             :     ENUM_FUNC_RIGHT,
      56             :     ENUM_FUNC_BOTTOM,
      57             :     ENUM_FUNC_XSTRETCH,
      58             :     ENUM_FUNC_YSTRETCH,
      59             :     ENUM_FUNC_HASSTROKE,
      60             :     ENUM_FUNC_HASFILL,
      61             :     ENUM_FUNC_WIDTH,
      62             :     ENUM_FUNC_HEIGHT,
      63             :     ENUM_FUNC_LOGWIDTH,
      64             :     ENUM_FUNC_LOGHEIGHT,
      65             :     ENUM_FUNC_ADJUSTMENT,
      66             :     ENUM_FUNC_EQUATION,
      67             : 
      68             :     UNARY_FUNC_ABS,
      69             :     UNARY_FUNC_SQRT,
      70             :     UNARY_FUNC_SIN,
      71             :     UNARY_FUNC_COS,
      72             :     UNARY_FUNC_TAN,
      73             :     UNARY_FUNC_ATAN,
      74             :     UNARY_FUNC_NEG,
      75             : 
      76             :     BINARY_FUNC_PLUS,
      77             :     BINARY_FUNC_MINUS,
      78             :     BINARY_FUNC_MUL,
      79             :     BINARY_FUNC_DIV,
      80             :     BINARY_FUNC_MIN,
      81             :     BINARY_FUNC_MAX,
      82             :     BINARY_FUNC_ATAN2,
      83             : 
      84             :     TERNARY_FUNC_IF
      85             : };
      86             : 
      87             : #define EXPRESSION_FLAG_SUMANGLE_MODE 1
      88             : 
      89             : SVX_DLLPUBLIC void FillEquationParameter( const com::sun::star::drawing::EnhancedCustomShapeParameter&, const sal_Int32, EnhancedCustomShapeEquation& );
      90             : 
      91             : class ExpressionNode
      92             : {
      93             : public:
      94             :     virtual ~ExpressionNode();
      95             : 
      96             :     /** Predicate whether this node is constant.
      97             : 
      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
     102             :         ExpressionNodes.
     103             : 
     104             :         @returns true, if the note is constant
     105             :     */
     106             :     virtual bool isConstant() const = 0;
     107             : 
     108             :     /** Operator to calculate function value.
     109             : 
     110             :         This method calculates the function value.
     111             :     */
     112             :     virtual double operator()() const = 0;
     113             : 
     114             :     /** Operator to retrieve the type of expression node
     115             :     */
     116             :     virtual ExpressionFunct getType() const = 0;
     117             : 
     118             :     /** Operator to retrieve the ms version of expression
     119             :     */
     120             :     virtual com::sun::star::drawing::EnhancedCustomShapeParameter fillNode(
     121             :         std::vector< EnhancedCustomShapeEquation >& rEquations, ExpressionNode* pOptionalArg, sal_uInt32 nFlags ) = 0;
     122             : };
     123             : typedef ::boost::shared_ptr< ExpressionNode > ExpressionNodeSharedPtr;
     124             : 
     125             : /** This exception is thrown, when the arithmetic expression
     126             :     parser failed to parse a string.
     127             :     */
     128             : struct ParseError
     129             : {
     130             :     ParseError() {}
     131             :     ParseError( const char* ) {}
     132             : };
     133             : 
     134             : class FunctionParser
     135             : {
     136             : public:
     137             : 
     138             :     /** Parse a string
     139             : 
     140             :         The following grammar is accepted by this method:
     141             :         <code>
     142             : 
     143             :         number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
     144             : 
     145             :         number = number number_digit | number_digit
     146             : 
     147             :         identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
     148             :                  'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
     149             : 
     150             :         unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
     151             :         binary_function = 'min'|'max'|'atan2'
     152             :         ternary_function = 'if'
     153             : 
     154             :         function_reference = '?' 'a-z,A-Z,0-9' ' '
     155             :         modifier_reference = '$' '0-9' ' '
     156             : 
     157             :         basic_expression =
     158             :             number |
     159             :             identifier |
     160             :             function_reference |
     161             :             unary_function '(' additive_expression ')' |
     162             :             binary_function '(' additive_expression ',' additive_expression ')' |
     163             :             ternary_function '(' additive_expression ',' additive_expression ',
     164             :                                ' additive_expression ')' | '(' additive_expression ')'
     165             : 
     166             :         unary_expression = '-' basic_expression
     167             : 
     168             :         multiplicative_expression =
     169             :                           basic_expression |
     170             :                           multiplicative_expression '*' basic_expression |
     171             :                           multiplicative_expression '/' basic_expression
     172             : 
     173             :         additive_expression =
     174             :                         multiplicative_expression |
     175             :                         additive_expression '+' multiplicative_expression |
     176             :                         additive_expression '-' multiplicative_expression
     177             : 
     178             :         </code>
     179             : 
     180             :         @param rFunction
     181             :         The string to parse
     182             : 
     183             :         @param rCustoShape
     184             :         The CustomShape is required for calculation of dynamic values such
     185             :         "hasstroke", function references and or modifier references ...
     186             : 
     187             :         @throws ParseError if an invalid expression is given.
     188             : 
     189             :         @return the generated function object.
     190             :        */
     191             : 
     192             :     SVX_DLLPUBLIC static ExpressionNodeSharedPtr parseFunction( const ::rtl::OUString& rFunction, const EnhancedCustomShape2d& rCustoShape );
     193             : 
     194             : private:
     195             :     // disabled constructor/destructor, since this is
     196             :     // supposed to be a singleton
     197             :     FunctionParser();
     198             : 
     199             :     // default: disabled copy/assignment
     200             :     FunctionParser(const FunctionParser&);
     201             :     FunctionParser& operator=( const FunctionParser& );
     202             : };
     203             : 
     204             : }
     205             : 
     206             : #endif /* _ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX */
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10