merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / engine / expressionnodefactory.cxx
blob646a66aa82d89286d4ec4774798c690bd6e5c1b5
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: expressionnodefactory.cxx,v $
10 * $Revision: 1.7 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <expressionnodefactory.hxx>
38 #include <canvas/verbosetrace.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
43 #include <functional>
44 #include <algorithm>
47 /* Implementation of ExpressionNodeFactory class */
49 namespace slideshow
51 namespace internal
53 namespace
55 class ConstantValueExpression : public ExpressionNode
57 public:
58 ConstantValueExpression( double rValue ) :
59 maValue( rValue )
63 virtual double operator()( double /*t*/ ) const
65 return maValue;
68 virtual bool isConstant() const
70 return true;
73 private:
74 double maValue;
77 class TValueExpression : public ExpressionNode
79 public:
80 TValueExpression()
84 virtual double operator()( double t ) const
86 return t;
89 virtual bool isConstant() const
91 return false;
95 /** Base class for following binary functions (*+-/)
97 Does not pay off to have all this as a template, since
98 we'd have to hold the functor as a member (+33% object
99 size).
101 class BinaryExpressionBase : public ExpressionNode
103 public:
104 BinaryExpressionBase( const ExpressionNodeSharedPtr& rFirstArg,
105 const ExpressionNodeSharedPtr& rSecondArg ) :
106 mpFirstArg( rFirstArg ),
107 mpSecondArg( rSecondArg )
111 virtual bool isConstant() const
113 return
114 mpFirstArg->isConstant() &&
115 mpSecondArg->isConstant();
118 protected:
119 ExpressionNodeSharedPtr mpFirstArg;
120 ExpressionNodeSharedPtr mpSecondArg;
123 class PlusExpression : public BinaryExpressionBase
125 public:
126 PlusExpression( const ExpressionNodeSharedPtr& rFirstArg,
127 const ExpressionNodeSharedPtr& rSecondArg ) :
128 BinaryExpressionBase( rFirstArg, rSecondArg )
132 virtual double operator()( double t ) const
134 return (*mpFirstArg)(t) + (*mpSecondArg)(t);
138 class MinusExpression : public BinaryExpressionBase
140 public:
141 MinusExpression( const ExpressionNodeSharedPtr& rFirstArg,
142 const ExpressionNodeSharedPtr& rSecondArg ) :
143 BinaryExpressionBase( rFirstArg, rSecondArg )
147 virtual double operator()( double t ) const
149 return (*mpFirstArg)(t) - (*mpSecondArg)(t);
153 class MultipliesExpression : public BinaryExpressionBase
155 public:
156 MultipliesExpression( const ExpressionNodeSharedPtr& rFirstArg,
157 const ExpressionNodeSharedPtr& rSecondArg ) :
158 BinaryExpressionBase( rFirstArg, rSecondArg )
162 virtual double operator()( double t ) const
164 return (*mpFirstArg)(t) * (*mpSecondArg)(t);
168 class DividesExpression : public BinaryExpressionBase
170 public:
171 DividesExpression( const ExpressionNodeSharedPtr& rFirstArg,
172 const ExpressionNodeSharedPtr& rSecondArg ) :
173 BinaryExpressionBase( rFirstArg, rSecondArg )
177 virtual double operator()( double t ) const
179 return (*mpFirstArg)(t) / (*mpSecondArg)(t);
183 class ComposedExpression : public BinaryExpressionBase
185 public:
186 ComposedExpression( const ExpressionNodeSharedPtr& rFirstArg,
187 const ExpressionNodeSharedPtr& rSecondArg ) :
188 BinaryExpressionBase( rFirstArg, rSecondArg )
192 virtual double operator()( double t ) const
194 return (*mpFirstArg)( (*mpSecondArg)(t) );
198 class MinExpression : public BinaryExpressionBase
200 public:
201 MinExpression( const ExpressionNodeSharedPtr& rFirstArg,
202 const ExpressionNodeSharedPtr& rSecondArg ) :
203 BinaryExpressionBase( rFirstArg, rSecondArg )
207 virtual double operator()( double t ) const
209 return ::std::min( (*mpFirstArg)(t), (*mpSecondArg)(t) );
213 class MaxExpression : public BinaryExpressionBase
215 public:
216 MaxExpression( const ExpressionNodeSharedPtr& rFirstArg,
217 const ExpressionNodeSharedPtr& rSecondArg ) :
218 BinaryExpressionBase( rFirstArg, rSecondArg )
222 virtual double operator()( double t ) const
224 return ::std::max( (*mpFirstArg)(t), (*mpSecondArg)(t) );
229 ExpressionNodeSharedPtr ExpressionNodeFactory::createConstantValueExpression( double rConstantValue )
231 return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue) );
234 ExpressionNodeSharedPtr ExpressionNodeFactory::createValueTExpression()
236 return ExpressionNodeSharedPtr( new TValueExpression() );
239 ExpressionNodeSharedPtr ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr& rLHS,
240 const ExpressionNodeSharedPtr& rRHS )
242 return ExpressionNodeSharedPtr( new PlusExpression(rLHS, rRHS) );
245 ExpressionNodeSharedPtr ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr& rLHS,
246 const ExpressionNodeSharedPtr& rRHS )
248 return ExpressionNodeSharedPtr( new MinusExpression(rLHS, rRHS) );
251 ExpressionNodeSharedPtr ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr& rLHS,
252 const ExpressionNodeSharedPtr& rRHS )
254 return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS, rRHS) );
257 ExpressionNodeSharedPtr ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr& rLHS,
258 const ExpressionNodeSharedPtr& rRHS )
260 return ExpressionNodeSharedPtr( new DividesExpression(rLHS, rRHS) );
263 ExpressionNodeSharedPtr ExpressionNodeFactory::createComposedExpression ( const ExpressionNodeSharedPtr& rOuterFunction,
264 const ExpressionNodeSharedPtr& rInnerFunction )
266 return ExpressionNodeSharedPtr( new ComposedExpression(rOuterFunction, rInnerFunction) );
269 ExpressionNodeSharedPtr ExpressionNodeFactory::createMinExpression ( const ExpressionNodeSharedPtr& rOuterFunction,
270 const ExpressionNodeSharedPtr& rInnerFunction )
272 return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction, rInnerFunction) );
275 ExpressionNodeSharedPtr ExpressionNodeFactory::createMaxExpression ( const ExpressionNodeSharedPtr& rOuterFunction,
276 const ExpressionNodeSharedPtr& rInnerFunction )
278 return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction, rInnerFunction) );