dictionaryListEntryIO.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-2019 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 "dictionaryListEntry.H"
27 #include "keyType.H"
28 #include "IOobject.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 Foam::label Foam::dictionaryListEntry::realSize(const dictionary& dict)
33 {
34  if (dict.size() < 1 || dict.first()->keyword() != IOobject::foamFile)
35  {
36  return dict.size();
37  }
38  else
39  {
40  return dict.size() - 1;
41  }
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
47 Foam::dictionaryListEntry::dictionaryListEntry
48 (
49  const dictionary& parentDict,
50  Istream& is
51 )
52 :
54  (
55  word("entry" + Foam::name(realSize(parentDict))),
56  parentDict,
58  )
59 {
60  token firstToken(is);
61  if (firstToken.isLabel())
62  {
63  label s = firstToken.labelToken();
64 
65  is.readBeginList("List");
66 
67  for (label i=0; i<s; i++)
68  {
69  if (!entry::New(*this, is))
70  {
72  << "Failed to read dictionary entry in list"
73  << exit(FatalIOError);
74  }
75  }
76  is.readEndList("List");
77  }
78  else if
79  (
80  firstToken.isPunctuation()
81  && firstToken.pToken() == token::BEGIN_LIST
82  )
83  {
84  while (true)
85  {
86  token nextToken(is);
87  if
88  (
89  nextToken.isPunctuation()
90  && nextToken.pToken() == token::END_LIST
91  )
92  {
93  break;
94  }
95  is.putBack(nextToken);
96 
97  if (!entry::New(*this, is))
98  {
100  << "Failed to read dictionary entry in list"
101  << exit(FatalIOError);
102  }
103  }
104  }
105  else
106  {
108  << "incorrect first token, expected <int> or '(', found "
109  << firstToken.info()
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
127  os << decrIndent << indent << token::END_LIST << nl;
128 
129  // Check state of IOstream
130  os.check("Ostream& operator<<(Ostream&, const dictionaryListEntry&)");
131 }
132 
133 
134 // * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
135 
137 {
138  de.write(os);
139  return os;
140 }
141 
142 
143 template<>
144 Foam::Ostream& Foam::operator<<
145 (
146  Ostream& os,
148 )
149 {
150  const dictionaryListEntry& e = ip.t_;
151 
152  os << " dictionaryListEntry '" << e.keyword() << "'" << endl;
153 
154  return os;
155 }
156 
157 
158 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:392
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:207
punctuationToken pToken() const
Definition: tokenI.H:248
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
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
char readEndList(const char *funcName)
Definition: Istream.C:148
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
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
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
Definition: entryIO.C:92
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void write(Ostream &) const
Write.
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A class for handling words, derived from string.
Definition: word.H:59
static const dictionary null
Null dictionary.
Definition: dictionary.H:242
char readBeginList(const char *funcName)
Definition: Istream.C:127
Read/write List of dictionaries.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
Definition: IOobject.H:98
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:45
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Ostream & operator<<(Ostream &, const ensightPart &)
label labelToken() const
Definition: tokenI.H:397
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
bool isPunctuation() const
Definition: tokenI.H:243
IOerror FatalIOError