Loading...
Searching...
No Matches
boolExpression.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2025 M. Janssens
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26InNamespace
27 Foam::Expression
28
29Description
30 Expression templates for bool
31
32SourceFiles
33 boolExpression.H
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_boolExpression_H
38#define Foam_boolExpression_H
39
40#include "GenericExpression.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46namespace Expression
47{
48
49/*---------------------------------------------------------------------------*\
50 Class boolWrap Declaration
51\*---------------------------------------------------------------------------*/
53//- Expression wrap of non-const bool
54class boolWrap
55:
56 public GenericExpression<boolWrap>
57{
58 bool elems_;
60public:
61 static constexpr bool is_leaf = false; //true;
62
63 //- Construct from components
64 boolWrap(const bool elems)
65 :
66 elems_(elems)
67 {}
68
69 // Construct from GenericExpression, forcing its evaluation.
70 template<typename E>
72 (
74 )
75 :
76 elems_(expr.evaluate())
77 {}
78
79 auto evaluate() const
80 {
81 return elems_;
82 }
83
84 template<typename E>
86 (
88 )
89 {
90 elems_ = expr.evaluate();
91 return elems_;
92 }
93
94 //- Assignment
95 template<typename E>
96 void operator=
97 (
99 )
100 {
101 elems_ = expr.evaluate();
102 }
103};
104
105
106/*---------------------------------------------------------------------------*\
107 Class boolConstWrap Declaration
108\*---------------------------------------------------------------------------*/
109
110//- Expression wrap of const bool
111class boolConstWrap
112:
113 public GenericExpression<boolConstWrap>
114{
115 const bool elems_;
116
117public:
118
119 // ! Store as copy (since holds reference)
120 static constexpr bool is_leaf = false;
121
122 //- Construct from components
123 boolConstWrap(const bool elems)
125 elems_(elems)
126 {}
127
128 auto evaluate() const
130 return elems_;
131 }
132};
133
135// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136
137} // End namespace Expression
138} // End namespace Foam
139
140// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141
142#endif
143
144// ************************************************************************* //
static constexpr bool is_leaf
boolConstWrap(const bool elems)
Construct from components.
static constexpr bool is_leaf
auto evaluate(const GenericExpression< E > &expr)
boolWrap(const bool elems)
Construct from components.
boolWrap(const GenericExpression< E > &expr)
A namespace for expression templates.
ListConstRefWrap< typename Expr::value_type > expr
Fully self-contained constant field wrapper. Not needed?
Namespace for OpenFOAM.