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 <bgschaid@hfd-research.com>
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.first();
48 }
49
50 this->ref<T>().append(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.last();
75 oldField.resize(oldField.size()-1);
76 }
77
78 result.setSingleValue(val);
79
80 return true;
81}
82
83
84// ************************************************************************* //
T & first()
Return the first element of the list.
Definition: UListI.H:202
const volScalarField & T
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131