blockMeshTools.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "blockMeshTools.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
31 (
32  Istream& is,
33  label& val,
34  const dictionary& dict
35 )
36 {
37  token t(is);
38  if (t.isLabel())
39  {
40  val = t.labelToken();
41  }
42  else if (t.isWord())
43  {
44  const word& varName = t.wordToken();
45  const entry* ePtr = dict.lookupScopedEntryPtr
46  (
47  varName,
48  true,
49  true
50  );
51  if (ePtr)
52  {
53  // Read as label
54  val = Foam::readLabel(ePtr->stream());
55  }
56  else
57  {
59  << "Undefined variable "
60  << varName << ". Valid variables are " << dict
61  << exit(FatalIOError);
62  }
63  }
64  else
65  {
67  << "Illegal token " << t.info()
68  << " when trying to read label"
69  << exit(FatalIOError);
70  }
71 
72  is.fatalCheck
73  (
74  "operator>>(Istream&, List<T>&) : reading entry"
75  );
76 }
77 
78 
80 (
81  Istream& is,
82  const dictionary& dict
83 )
84 {
85  label val;
86  read(is, val, dict);
87  return val;
88 }
89 
90 
92 (
93  Ostream& os,
94  const label val,
95  const dictionary& dict
96 )
97 {
98  forAllConstIter(dictionary, dict, iter)
99  {
100  if (iter().isStream())
101  {
102  label keyVal(Foam::readLabel(iter().stream()));
103  if (keyVal == val)
104  {
105  os << iter().keyword();
106  return;
107  }
108  }
109  }
110  os << val;
111 }
112 
113 
115 (
116  const dictionary& dict,
117  const label val
118 )
119 {
120  forAllConstIter(dictionary, dict, iter)
121  {
122  if (iter().isStream())
123  {
124  label keyVal(Foam::readLabel(iter().stream()));
125  if (keyVal == val)
126  {
127  return iter().keyword();
128  }
129  }
130  }
131 
132  return keyType::null;
133 }
134 
135 
136 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:392
A class for handling keywords in dictionaries.
Definition: keyType.H:66
bool isWord() const
Definition: tokenI.H:261
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
const word & wordToken() const
Definition: tokenI.H:266
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:871
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
A class for handling words, derived from string.
Definition: word.H:59
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
label readLabel(Istream &is)
Definition: label.H:64
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const keyType & findEntry(const dictionary &, const label)
Linear search for label entry.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
label labelToken() const
Definition: tokenI.H:397
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
IOerror FatalIOError