CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
forEachLeafLogic.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <type_traits>
38#include <utility>
39
40#include "../../../config.h"
42#include "../../../traits/expressionTraits.hpp"
43#include "../traversalLogic.hpp"
44
46namespace codi {
47
59 template<typename T_Impl>
60 struct ForEachLeafLogic : public TraversalLogic<T_Impl> {
61 public:
62
64
65 /*******************************************************************************/
68
70 template<typename Node, typename... Args>
71 void handleActive(Node const& node, Args&&... args) {
72 CODI_UNUSED(node, args...);
73 }
74
76 template<typename Node, typename... Args>
77 void handleConstant(Node const& node, Args&&... args) {
78 CODI_UNUSED(node, args...);
79 }
80
82 template<typename Node, typename... Args>
83 void handleEmpty(Node const& node, Args&&... args) {
84 CODI_UNUSED(node, args...);
85 }
86
88 /*******************************************************************************/
91
92 // TODO: Rewrite for C++17. One function with if constexpr.
93
95 template<typename Node, typename... Args>
97 cast().handleActive(node, std::forward<Args>(args)...);
98 }
99
101 template<typename Node, typename... Args>
103 cast().handleConstant(node, std::forward<Args>(args)...);
104 }
105
107 template<typename Node, typename... Args>
109 cast().handleEmpty(node, std::forward<Args>(args)...);
110 }
111
113
114 private:
115
116 CODI_INLINE Impl& cast() {
117 return static_cast<Impl&>(*this);
118 }
119 };
120}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:117
typename std::enable_if< IsEmptyExpression< Expr >::value, T >::type EnableIfEmptyExpression
Enable if wrapper for IsEmptyExpression.
Definition expressionTraits.hpp:232
typename std::enable_if< IsLhsExpression< Expr >::value, T >::type EnableIfLhsExpression
Enable if wrapper for IsLhsExpression.
Definition expressionTraits.hpp:198
typename std::enable_if< IsConstantExpression< Expr >::value, T >::type EnableIfConstantExpression
Enable if wrapper for IsConstantExpression.
Definition expressionTraits.hpp:215
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
Implement logic for leaf nodes only.
Definition forEachLeafLogic.hpp:60
void handleActive(Node const &node, Args &&... args)
Called for leaf nodes which implement LhsExpressionInterface.
Definition forEachLeafLogic.hpp:71
inlineExpressionTraits::EnableIfConstantExpression< Node > leaf(Node const &node, Args &&... args)
Called for all leaf nodes in the expression.
Definition forEachLeafLogic.hpp:102
void handleConstant(Node const &node, Args &&... args)
Called for leaf nodes which implement ConstantExpression.
Definition forEachLeafLogic.hpp:77
void handleEmpty(Node const &node, Args &&... args)
Called for leaf nodes which have an EmptyOperation..
Definition forEachLeafLogic.hpp:83
inlineExpressionTraits::EnableIfEmptyExpression< Node > leaf(Node const &node, Args &&... args)
Called for all leaf nodes in the expression.
Definition forEachLeafLogic.hpp:108
T_Impl Impl
See ForEachLeafLogic.
Definition forEachLeafLogic.hpp:63
inlineExpressionTraits::EnableIfLhsExpression< Node > leaf(Node const &node, Args &&... args)
Called for all leaf nodes in the expression.
Definition forEachLeafLogic.hpp:96
Traversal of CoDiPack expressions.
Definition traversalLogic.hpp:57
inlinevoid node(Node const &node, Args &&... args)
Called for each node in the expression.
Definition traversalLogic.hpp:87