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 | Copyright (C) 2016 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 "IOstreams.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() != "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  entry::New(*this, is);
70  }
71  is.readEndList("List");
72  }
73  else if
74  (
75  firstToken.isPunctuation()
76  && firstToken.pToken() == token::BEGIN_LIST
77  )
78  {
79  while (true)
80  {
81  token nextToken(is);
82  if
83  (
84  nextToken.isPunctuation()
85  && nextToken.pToken() == token::END_LIST
86  )
87  {
88  break;
89  }
90  is.putBack(nextToken);
91  entry::New(*this, is);
92  }
93  }
94  else
95  {
97  << "incorrect first token, expected <int> or '(', found "
98  << firstToken.info()
99  << exit(FatalIOError);
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 
107 {
108  os << nl << indent << size()
109  << token::SPACE << "// " << keyword() << nl
111 
112  // Write contents
113  dictionary::write(os, false);
114 
115  // Write end delimiter
116  os << decrIndent << indent << token::END_LIST << nl;
117 
118  // Check state of IOstream
119  os.check("Ostream& operator<<(Ostream&, const dictionaryListEntry&)");
120 }
121 
122 
123 // * * * * * * * * * * * * * * Ostream operator * * * * * * * * * * * * * * //
124 
126 {
127  de.write(os);
128  return os;
129 }
130 
131 
132 template<>
133 Foam::Ostream& Foam::operator<<
134 (
135  Ostream& os,
137 )
138 {
139  const dictionaryListEntry& e = ip.t_;
140 
141  os << " dictionaryListEntry '" << e.keyword() << "'" << endl;
142 
143  return os;
144 }
145 
146 
147 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:254
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:172
punctuationToken pToken() const
Definition: tokenI.H:200
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:223
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const double e
Elementary charge.
Definition: doubleFloat.H:78
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:374
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const dictionary null
Null dictionary.
Definition: dictionary.H:202
A token holds items read from Istream.
Definition: token.H:69
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
Definition: entryIO.C:107
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
virtual void write(Ostream &) const
Write.
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
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
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:53
static const char nl
Definition: Ostream.H:262
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:237
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:331
Ostream & operator<<(Ostream &, const ensightPart &)
label labelToken() const
Definition: tokenI.H:259
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:230
bool isPunctuation() const
Definition: tokenI.H:195
IOerror FatalIOError