dictionaryListEntryIO.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2021 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
29#include "dictionaryListEntry.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33
34// File-scope: The dictionary size without the "FoamFile" entry
35static Foam::label realSize(const Foam::dictionary& dict)
36{
37 if (dict.size() < 1 || dict.first()->keyword() != "FoamFile")
38 {
39 return dict.size();
40 }
41 else
42 {
43 return dict.size() - 1;
44 }
45}
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51(
52 const dictionary& parentDict,
53 const dictionaryListEntry& dictEnt
54)
55:
56 dictionaryEntry(parentDict, dictEnt)
57{}
58
59
61(
62 const dictionary& parentDict,
63 Istream& is
64)
65:
67 (
68 word("entry" + Foam::name(realSize(parentDict))),
69 parentDict,
70 dictionary::null
71 )
72{
73 token tok(is);
74 if (tok.isLabel())
75 {
76 const label len = tok.labelToken();
77
78 is.readBeginList("List");
79
80 for (label i=0; i<len; ++i)
81 {
82 entry::New(*this, is);
83 }
84 is.readEndList("List");
85 }
86 else if (tok.isPunctuation(token::BEGIN_LIST))
87 {
88 while (true)
89 {
90 is >> tok;
91 if (tok.error())
92 {
94 << "parsing error " << tok.info() << nl
96 }
97 else if (tok.isPunctuation(token::END_LIST))
98 {
99 break;
100 }
101 is.putBack(tok);
102 entry::New(*this, is);
103 }
104 }
105 else
106 {
108 << "incorrect first token, expected <int> or '(', found "
109 << tok.info() << nl
110 << exit(FatalIOError);
111 }
112}
113
114
115// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116
118{
119 os << nl << indent << size()
120 << token::SPACE << "// " << keyword() << nl
122
123 // Write contents
124 dictionary::write(os, false);
125
126 // Write end delimiter
128
130}
131
132
133// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
134
136{
137 e.write(os);
138 return os;
139}
140
141
142template<>
143Foam::Ostream& Foam::operator<<
144(
145 Ostream& os,
147)
148{
149 const dictionaryListEntry& e = ip.t_;
150
151 os << " dictionaryListEntry '" << e.keyword() << "'" << endl;
152
153 return os;
154}
155
156
157// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition: Istream.C:169
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition: Istream.C:148
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Definition: Istream.C:70
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A keyword and a list of tokens is a 'dictionaryEntry'.
Read/write List of dictionaries.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
virtual bool write(const bool valid=true) const
Write using setting from DB.
A token holds an item read from Istream.
Definition: token.H:69
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
label labelToken() const
Return label value.
Definition: tokenI.H:513
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
A class for handling words, derived from Foam::string.
Definition: word.H:68
static Foam::label realSize(const Foam::dictionary &dict)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
IOerror FatalIOError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
volScalarField & e
Definition: createFields.H:11