Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
29#include "dictionaryListEntry.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33
34// File-scope: The dictionary size without the "FoamFile" entry
35static inline Foam::label realSize(const Foam::dictionary& dict)
36{
37 return
38 (
39 (dict.empty() || (dict.front()->keyword() != "FoamFile"))
40 ? dict.size()
41 : dict.size() - 1
42 );
43}
44
45
46// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47
49(
50 const dictionary& parentDict,
51 const dictionaryListEntry& dictEnt
52)
53:
54 dictionaryEntry(parentDict, dictEnt)
55{}
56
57
59(
60 const dictionary& parentDict,
61 Istream& is
62)
63:
65 (
66 word("entry" + Foam::name(realSize(parentDict))),
67 parentDict,
68 dictionary::null
69 )
70{
71 token tok(is);
72 if (tok.isLabel())
73 {
74 const label len = tok.labelToken();
75
76 is.readBeginList("List");
77
78 for (label i=0; i<len; ++i)
79 {
80 entry::New(*this, is);
81 }
82 is.readEndList("List");
83 }
84 else if (tok.isPunctuation(token::BEGIN_LIST))
85 {
86 while (true)
87 {
88 is >> tok;
89 if (tok.error())
90 {
92 << "parsing error " << tok.info() << nl
94 }
95 else if (tok.isPunctuation(token::END_LIST))
96 {
97 break;
98 }
99 is.putBack(tok);
100 entry::New(*this, is);
101 }
102 }
103 else
104 {
106 << "incorrect first token, expected <int> or '(', found "
107 << tok.info() << nl
109 }
110}
111
112
113// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
115void Foam::dictionaryListEntry::write(Ostream& os) const
116{
117 os << nl << indent << size()
118 << token::SPACE << "// " << keyword() << nl
120
121 // Write contents
122 dictionary::write(os, false);
123
124 // Write end delimiter
127 os.check(FUNCTION_NAME);
128}
129
130
131// * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
132
133Foam::Ostream& Foam::operator<<
134(
135 Ostream& os,
136 const dictionaryListEntry& e
137)
139 e.write(os);
140 return os;
141}
142
143
144template<>
145Foam::Ostream& Foam::operator<<
146(
147 Ostream& os,
148 const InfoProxy<dictionaryListEntry>& iproxy
149)
150{
151 const auto& e = *iproxy;
152
153 os << " dictionaryListEntry '" << e.keyword() << "'" << endl;
154
155 return os;
156}
157
158
159// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
label size() const noexcept
The number of elements in list.
Definition DLListBase.H:194
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition Istream.C:192
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition Istream.C:171
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
Definition Istream.C:71
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A keyword and a list of tokens is a 'dictionaryEntry'.
virtual const fileName & name() const
Return the scoped dictionary name (eg, dictA.dictB.dictC).
dictionaryEntry(const dictionaryEntry &)=delete
No copy construct.
virtual const dictionary & dict() const noexcept
Return dictionary (ie, this).
Read/write List of dictionaries.
dictionaryListEntry(const dictionaryListEntry &)=delete
No copy construct.
virtual void write(Ostream &os) const
Write.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
Definition entryIO.C:98
const keyType & keyword() const noexcept
Return keyword.
Definition entry.H:231
A token holds an item read from Istream.
Definition token.H:70
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition tokenI.H:650
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
@ SPACE
Space [isspace].
Definition token.H:144
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
A class for handling words, derived from Foam::string.
Definition word.H:66
static Foam::label realSize(const Foam::dictionary &dict)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
volScalarField & e