exprDriverIO.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) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "exprDriver.H"
29 #include "exprTools.H"
30 #include "stringOps.H"
31 
32 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
38 // Write list as single or multiple entries - see exprTools::getList()
39 static void writeList
40 (
41  Ostream& os,
42  const UList<expressions::exprString>& list
43 )
44 {
45  if (list.size() == 1)
46  {
47  os << list[0];
48  }
49  else
50  {
52 
53  if (!list.empty())
54  {
55  os << nl;
56 
57  for (const expressions::exprString& str : list)
58  {
59  os << str << nl;
60  }
61  }
63  }
64 }
65 
67 
68 } // End namespace Foam
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
75 (
76  const word& name,
77  const dictionary& dict
78 )
79 {
80  return expressions::exprString(dict.get<string>(name), dict);
81 }
82 
83 
86 (
87  const word& name
88 )
89 {
90  return readExpression(name, dict());
91 }
92 
93 
96 (
97  const dictionary& dict,
98  const word& keyword,
99  bool mandatory
100 )
101 {
102  return exprTools::getList(dict, keyword, mandatory);
103 }
104 
105 
107 (
108  const dictionary& dict,
109  bool mandatory
110 )
111 {
112  variableStrings_ = readVariableStrings(dict, "variable", mandatory);
113 
114  return variableStrings_.size();
115 }
116 
117 
119 (
120  Ostream& os,
121  const word& keyword
122 ) const
123 {
124  if (keyword.size())
125  {
126  os.writeKeyword(keyword);
127  }
128 
129  writeList(os, variableStrings_);
130 
131  if (keyword.size())
132  {
133  os.endEntry();
134  }
135 
136  return os;
137 }
138 
139 
140 // ************************************************************************* //
Foam::expressions::exprDriver::readExpression
static expressions::exprString readExpression(const word &name, const dictionary &dict)
Read an expression string and do substitutions.
Definition: exprDriverIO.C:75
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::exprDriver::readVariableStrings
static List< expressions::exprString > readVariableStrings(const dictionary &dict, const word &name="variables", bool mandatory=false)
Read the list of variable strings.
Definition: exprDriverIO.C:96
exprDriver.H
Foam::expressions::exprDriver::setVariableStrings
label setVariableStrings(const dictionary &dict, bool mandatory=false)
Read "variables" and assigns to the list of expression strings.
Definition: exprDriverIO.C:107
Foam::vtk::writeList
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:112
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
exprTools.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< Foam::expressions::exprString >
Foam::expressions::exprString
Definition: exprString.H:60
Foam::expressions::exprDriver::writeVariableStrings
Ostream & writeVariableStrings(Ostream &os, const word &keyword="") const
Write "variables".
Definition: exprDriverIO.C:119
Foam::expressions::exprString
A variant of Foam::string with expansion of dictionary variables into a comma-separated form.
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::exprTools::getList
List< expressions::exprString > getList(const dictionary &dict, const word &keyword, bool mandatory=true, label recursionDepth=0)
Get an expression string list from a dictionary.
Definition: exprTools.C:120
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
stringOps.H