Loading...
Searching...
No Matches
exprResultStackTemplates.C
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) 2012-2018 Bernhard Gschaider
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29template<class T>
30bool Foam::expressions::exprResultStack::pushChecked
31(
32 const exprResult& result
33)
34{
35 if (!isType<T>())
36 {
37 return false;
38 }
39
40 // The value to push
41 T val(Zero);
42
43 const Field<T>& resultField = result.cref<T>();
44
45 if (!resultField.empty())
46 {
47 val = resultField.front();
48 }
49
50 this->ref<T>().push_back(val);
51
52 return true;
53}
54
55
56template<class T>
57bool Foam::expressions::exprResultStack::popChecked
58(
59 exprResult& result
60)
61{
62 if (!isType<T>())
63 {
64 return false;
65 }
66
67 // The popped value
68 T val(Zero);
69
70 Field<T>& oldField = this->ref<T>();
71
72 if (!oldField.empty())
73 {
74 val = oldField.back();
75 oldField.pop_back();
76 }
77
78 result.setSingleValue(val);
79
80 return true;
81}
82
83
84// ************************************************************************* //
A polymorphic field/result from evaluating an expression.
Definition exprResult.H:122
bool isType() const
True if valueType corresponds to the given Type.
Field< Type > & ref()
Return non-const reference to the field.
const volScalarField & T
rDeltaT ref()
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
Definition typeInfo.H:112