Loading...
Searching...
No Matches
fieldInfo.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) 2019-2023 OpenCFD Ltd.
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
26Class
27 Foam::functionObjects::fieldInfo
28
29Description
30 Helper class to store a wordRe and label used by
31 Foam::functionObjects::fieldSelection
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef Foam_functionObjects_fieldInfo_H
36#define Foam_functionObjects_fieldInfo_H
37
38#include "label.H"
39#include "wordRes.H"
40#include "Switch.H"
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
45{
46namespace functionObjects
47{
48
49// Forward Declarations
50class fieldInfo;
53
54/*---------------------------------------------------------------------------*\
55 Class fieldInfo Declaration
56\*---------------------------------------------------------------------------*/
57
58class fieldInfo
59{
60 // Private Data
61
62 //- Pattern for the field name(s)
63 wordRe name_;
64
65 //- Field component
66 label component_;
67
68 //- Found the field
69 mutable bool found_;
70
71
72public:
73
74 // Constructors
75
76 //- Default construct
77 fieldInfo()
78 :
79 name_(),
80 component_(-1),
81 found_(false)
82 {}
83
84 //- Construct from components
85 explicit fieldInfo(const wordRe& name, const label component = -1)
86 :
87 name_(name),
88 component_(component),
89 found_(false)
90 {}
91
92 //- Construct from stream
93 explicit fieldInfo(Istream& is)
94 :
95 name_(is),
96 component_(readLabel(is)),
97 found_(false)
98 {}
99
100
101 //- Destructor
102 ~fieldInfo() = default;
103
104
105 // Member Functions
106
107 //- Return the selector pattern for the field name(s)
108 const wordRe& name() const noexcept { return name_; }
110 //- Return the component
111 label component() const noexcept { return component_; }
112
113 //- Return the found state
114 bool found() const noexcept { return found_; }
115
116 //- Set the found state to be 'on'
117 void found(bool on) const noexcept { found_ = on; }
118
119
120 friend bool operator==(const fieldInfo& a, const fieldInfo& b)
121 {
122 return
123 (
124 a.found() == b.found()
125 && a.component() == b.component()
126 && a.name() == b.name()
127 );
128 }
129
130 friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
131 {
132 return !(a == b);
133 }
134
136 // IOstream Operators
137
138 friend Istream& operator>>(Istream& is, fieldInfo& fi)
139 {
140 is >> fi.name_ >> fi.component_ >> fi.found_;
141 return is;
142 }
143 friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
144 {
145 os << fi.name_ << ' '
146 << fi.component_ << ' '
147 << Switch::name(fi.found_);
148 return os;
149 }
150};
151
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155} // End namespace functionObjects
156} // End namespace Foam
157
158// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159
160#endif
161
162// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static const char * name(bool b) noexcept
A string representation of bool as "false" / "true".
Helper class to store a wordRe and label used by Foam::functionObjects::fieldSelection.
Definition fieldInfo.H:52
friend bool operator==(const fieldInfo &a, const fieldInfo &b)
Definition fieldInfo.H:135
fieldInfo(Istream &is)
Construct from stream.
Definition fieldInfo.H:98
friend Ostream & operator<<(Ostream &os, const fieldInfo &fi)
Definition fieldInfo.H:158
bool found() const noexcept
Return the found state.
Definition fieldInfo.H:127
label component() const noexcept
Return the component.
Definition fieldInfo.H:122
friend bool operator!=(const fieldInfo &a, const fieldInfo &b)
Definition fieldInfo.H:145
~fieldInfo()=default
Destructor.
void found(bool on) const noexcept
Set the found state to be 'on'.
Definition fieldInfo.H:132
fieldInfo(const wordRe &name, const label component=-1)
Construct from components.
Definition fieldInfo.H:88
friend Istream & operator>>(Istream &is, fieldInfo &fi)
Definition fieldInfo.H:153
fieldInfo()
Default construct.
Definition fieldInfo.H:78
const wordRe & name() const noexcept
Return the selector pattern for the field name(s).
Definition fieldInfo.H:117
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Ostream & operator<<(Ostream &, const fieldInfo &)
Definition fieldInfo.H:158
Istream & operator>>(Istream &, fieldInfo &)
Definition fieldInfo.H:153
Namespace for OpenFOAM.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition label.H:63
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
volScalarField & b