nss: upgrade to release 3.73
[LibreOffice.git] / slideshow / source / engine / expressionnodefactory.cxx
blob0b4136f34635f2f8f6e1d62d03bc9e2978422a1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <expressionnodefactory.hxx>
23 #include <algorithm>
26 /* Implementation of ExpressionNodeFactory class */
28 namespace slideshow::internal
30 namespace
32 class ConstantValueExpression : public ExpressionNode
34 public:
35 explicit ConstantValueExpression( double rValue ) :
36 maValue( rValue )
40 virtual double operator()( double /*t*/ ) const override
42 return maValue;
45 virtual bool isConstant() const override
47 return true;
50 private:
51 double maValue;
54 class TValueExpression : public ExpressionNode
56 public:
57 TValueExpression()
61 virtual double operator()( double t ) const override
63 return t;
66 virtual bool isConstant() const override
68 return false;
72 /** Base class for following binary functions (*+-/)
74 Does not pay off to have all this as a template, since
75 we'd have to hold the functor as a member (+33% object
76 size).
78 class BinaryExpressionBase : public ExpressionNode
80 public:
81 BinaryExpressionBase( const std::shared_ptr<ExpressionNode>& rFirstArg,
82 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
83 mpFirstArg( rFirstArg ),
84 mpSecondArg( rSecondArg )
88 virtual bool isConstant() const override
90 return
91 mpFirstArg->isConstant() &&
92 mpSecondArg->isConstant();
95 protected:
96 std::shared_ptr<ExpressionNode> mpFirstArg;
97 std::shared_ptr<ExpressionNode> mpSecondArg;
100 class PlusExpression : public BinaryExpressionBase
102 public:
103 PlusExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
104 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
105 BinaryExpressionBase( rFirstArg, rSecondArg )
109 virtual double operator()( double t ) const override
111 return (*mpFirstArg)(t) + (*mpSecondArg)(t);
115 class MinusExpression : public BinaryExpressionBase
117 public:
118 MinusExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
119 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
120 BinaryExpressionBase( rFirstArg, rSecondArg )
124 virtual double operator()( double t ) const override
126 return (*mpFirstArg)(t) - (*mpSecondArg)(t);
130 class MultipliesExpression : public BinaryExpressionBase
132 public:
133 MultipliesExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
134 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
135 BinaryExpressionBase( rFirstArg, rSecondArg )
139 virtual double operator()( double t ) const override
141 return (*mpFirstArg)(t) * (*mpSecondArg)(t);
145 class DividesExpression : public BinaryExpressionBase
147 public:
148 DividesExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
149 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
150 BinaryExpressionBase( rFirstArg, rSecondArg )
154 virtual double operator()( double t ) const override
156 return (*mpFirstArg)(t) / (*mpSecondArg)(t);
160 class MinExpression : public BinaryExpressionBase
162 public:
163 MinExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
164 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
165 BinaryExpressionBase( rFirstArg, rSecondArg )
169 virtual double operator()( double t ) const override
171 return ::std::min( (*mpFirstArg)(t), (*mpSecondArg)(t) );
175 class MaxExpression : public BinaryExpressionBase
177 public:
178 MaxExpression( const std::shared_ptr<ExpressionNode>& rFirstArg,
179 const std::shared_ptr<ExpressionNode>& rSecondArg ) :
180 BinaryExpressionBase( rFirstArg, rSecondArg )
184 virtual double operator()( double t ) const override
186 return ::std::max( (*mpFirstArg)(t), (*mpSecondArg)(t) );
191 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createConstantValueExpression( double rConstantValue )
193 return std::make_shared<ConstantValueExpression>(rConstantValue);
196 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createValueTExpression()
198 return std::make_shared<TValueExpression>();
201 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createPlusExpression( const std::shared_ptr<ExpressionNode>& rLHS,
202 const std::shared_ptr<ExpressionNode>& rRHS )
204 return std::make_shared<PlusExpression>(rLHS, rRHS);
207 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createMinusExpression( const std::shared_ptr<ExpressionNode>& rLHS,
208 const std::shared_ptr<ExpressionNode>& rRHS )
210 return std::make_shared<MinusExpression>(rLHS, rRHS);
213 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createMultipliesExpression( const std::shared_ptr<ExpressionNode>& rLHS,
214 const std::shared_ptr<ExpressionNode>& rRHS )
216 return std::make_shared<MultipliesExpression>(rLHS, rRHS);
219 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createDividesExpression( const std::shared_ptr<ExpressionNode>& rLHS,
220 const std::shared_ptr<ExpressionNode>& rRHS )
222 return std::make_shared<DividesExpression>(rLHS, rRHS);
225 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createMinExpression ( const std::shared_ptr<ExpressionNode>& rOuterFunction,
226 const std::shared_ptr<ExpressionNode>& rInnerFunction )
228 return std::make_shared<MinExpression>(rOuterFunction, rInnerFunction);
231 std::shared_ptr<ExpressionNode> ExpressionNodeFactory::createMaxExpression ( const std::shared_ptr<ExpressionNode>& rOuterFunction,
232 const std::shared_ptr<ExpressionNode>& rInnerFunction )
234 return std::make_shared<MaxExpression>(rOuterFunction, rInnerFunction);
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */