LibreOffice Module svx (master)  1
EnhancedCustomShapeFunctionParser.hxx
Go to the documentation of this file.
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 <config_options.h>
24 #include <sal/config.h>
25 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
26 #include <memory>
27 #include <ostream>
28 #include <vector>
29 
30 #include <svx/svxdllapi.h>
31 
33 {
34  sal_Int32 nOperation;
35  sal_Int32 nPara[ 3 ];
36 
38  nOperation ( 0 )
39  {
40  nPara[ 0 ] = nPara[ 1 ] = nPara[ 2 ] = 0;
41  }
42 };
43 
45 
46 namespace EnhancedCustomShape {
47 
48 enum class ExpressionFunct
49 {
50  Const,
51 
52  EnumPi,
53  EnumLeft,
54  EnumTop,
55  EnumRight,
56  EnumBottom,
61  EnumWidth,
62  EnumHeight,
67 
68  UnaryAbs,
69  UnarySqrt,
70  UnarySin,
71  UnaryCos,
72  UnaryTan,
73  UnaryAtan,
74  UnaryNeg,
75 
76  BinaryPlus,
78  BinaryMul,
79  BinaryDiv,
80  BinaryMin,
81  BinaryMax,
83 
84  TernaryIf
85 };
86 
87 template< typename charT, typename traits >
88 inline std::basic_ostream<charT, traits> & operator <<(
89  std::basic_ostream<charT, traits> & stream, const ExpressionFunct& eFunc )
90 {
91  switch (eFunc)
92  {
93  case ExpressionFunct::Const : return stream << "const";
94 
95  case ExpressionFunct::EnumPi : return stream << "pi";
96  case ExpressionFunct::EnumLeft : return stream << "left";
97  case ExpressionFunct::EnumTop : return stream << "top";
98  case ExpressionFunct::EnumRight : return stream << "right";
99  case ExpressionFunct::EnumBottom : return stream << "bottom";
100  case ExpressionFunct::EnumXStretch : return stream << "xstretch";
101  case ExpressionFunct::EnumYStretch : return stream << "ystretch";
102  case ExpressionFunct::EnumHasStroke : return stream << "hasstroke";
103  case ExpressionFunct::EnumHasFill : return stream << "hasfill";
104  case ExpressionFunct::EnumWidth : return stream << "width";
105  case ExpressionFunct::EnumHeight : return stream << "height";
106  case ExpressionFunct::EnumLogWidth : return stream << "logwidth";
107  case ExpressionFunct::EnumLogHeight : return stream << "logheight";
108  case ExpressionFunct::EnumAdjustment : return stream << "adjustment";
109  case ExpressionFunct::EnumEquation : return stream << "equation";
110 
111  case ExpressionFunct::UnaryAbs : return stream << "abs";
112  case ExpressionFunct::UnarySqrt : return stream << "sqrt";
113  case ExpressionFunct::UnarySin : return stream << "sin";
114  case ExpressionFunct::UnaryCos : return stream << "cos";
115  case ExpressionFunct::UnaryTan : return stream << "tan";
116  case ExpressionFunct::UnaryAtan : return stream << "atan";
117  case ExpressionFunct::UnaryNeg : return stream << "neg";
118 
119  case ExpressionFunct::BinaryPlus : return stream << "plus";
120  case ExpressionFunct::BinaryMinus : return stream << "minus";
121  case ExpressionFunct::BinaryMul : return stream << "mul";
122  case ExpressionFunct::BinaryDiv : return stream << "div";
123  case ExpressionFunct::BinaryMin : return stream << "min";
124  case ExpressionFunct::BinaryMax : return stream << "max";
125  case ExpressionFunct::BinaryAtan2 : return stream << "atan2";
126 
127  case ExpressionFunct::TernaryIf : return stream << "if";
128 
129  default: return stream << "?(" << static_cast<int>(eFunc) << ")";
130  }
131 }
132 
133 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
134 
135 SVXCORE_DLLPUBLIC void FillEquationParameter( const css::drawing::EnhancedCustomShapeParameter&, const sal_Int32, EnhancedCustomShapeEquation& );
136 
137 class SAL_DLLPUBLIC_RTTI ExpressionNode
138 {
139 public:
140  virtual ~ExpressionNode();
141 
152  virtual bool isConstant() const = 0;
153 
158  virtual double operator()() const = 0;
159 
162  virtual ExpressionFunct getType() const = 0;
163 
166  virtual css::drawing::EnhancedCustomShapeParameter fillNode(
167  std::vector< EnhancedCustomShapeEquation >& rEquations, ExpressionNode* pOptionalArg, sal_uInt32 nFlags ) = 0;
168 };
169 
174 {
175  ParseError( const char* ) {}
176 };
177 
179 {
180 public:
181 
236  UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) static std::shared_ptr<ExpressionNode> const & parseFunction( const OUString& rFunction, const EnhancedCustomShape2d& rCustoShape );
237 
238  // this is a singleton
239  FunctionParser() = delete;
240  FunctionParser(const FunctionParser&) = delete;
241  FunctionParser& operator=( const FunctionParser& ) = delete;
242 };
243 
244 }
245 
246 #endif // INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
247 
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool getType(BSTR name, Type &type)
SVXCORE_DLLPUBLIC void FillEquationParameter(const css::drawing::EnhancedCustomShapeParameter &, const sal_Int32, EnhancedCustomShapeEquation &)
FunctionParser & operator=(const FunctionParser &)=delete
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const ExpressionFunct &eFunc)
UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) static std FunctionParser()=delete
Parse a string.
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchange class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) OLocalExchangeHelper
a helper for navigator windows (SvTreeListBox'es) which allow DnD within themself ...
Definition: fmexch.hxx:93
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
This exception is thrown, when the arithmetic expression parser failed to parse a string...