namedDictionary.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) 2020 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "namedDictionary.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
36 {}
37 
38 
40 {
41  is >> *this;
42 }
43 
44 
45 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
46 
48 {
49  first().clear();
50  second().clear();
51 }
52 
53 
54 bool Foam::namedDictionary::empty() const noexcept
55 {
56  return (first().empty() && second().empty());
57 }
58 
59 
60 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
61 
63 {
64  obj.clear();
65 
66  // Three possible inputs:
67  // - key
68  // - key { ... }
69  // - { ... }
70 
71  // Minor consistency with primitiveEntry, also accept the following:
72  // - key ;
73 
74  token tok(is);
75  is.putBack(tok);
76 
78  {
79  is >> obj.keyword();
80  is >> tok;
81 
82  // Discards possible trailing ';'
83  if (!tok.isPunctuation(token::END_STATEMENT))
84  {
85  is.putBack(tok);
86  }
87  }
88 
90  {
91  obj.dict().read(is);
92  }
93 
94  is.check(FUNCTION_NAME);
95  return is;
96 }
97 
98 
100 {
101  // Three possible outputs:
102  // - key
103  // - key { ... }
104  // - { ... }
105  // No distinction between a missing and an empty dictionary
106 
107  if (obj.keyword().empty() || !obj.dict().empty())
108  {
109  // Never allow empty output.
110  // Otherwise cannot re-read for streaming
111  obj.dict().writeEntry(obj.keyword(), os);
112  }
113  else
114  {
115  os << obj.keyword();
116  }
117 
118  return os;
119 }
120 
121 
122 // ************************************************************************* //
Foam::namedDictionary::dict
const dictionary & dict() const noexcept
Read-access to the dictionay.
Definition: namedDictionary.H:126
Foam::namedDictionary::namedDictionary
namedDictionary()
Default construct.
Definition: namedDictionary.C:33
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:68
Foam::dictionary::writeEntry
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:164
namedDictionary.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::namedDictionary
A tuple of keyType and dictionary, which can be used when reading named or unnamed dictionary entries...
Definition: namedDictionary.H:83
Foam::token::isPunctuation
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:154
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
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::token::BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:159
Foam::dictionary::read
bool read(Istream &is)
Read dictionary from Istream. Discards the header.
Definition: dictionaryIO.C:141
Foam::namedDictionary::empty
bool empty() const noexcept
Empty if both keyword and dictionary are empty.
Definition: namedDictionary.C:54
Foam::namedDictionary::keyword
const keyType & keyword() const noexcept
Return keyword.
Definition: namedDictionary.H:114
Foam::Istream::putBack
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Definition: Istream.C:70
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::namedDictionary::clear
void clear()
Clear keyword and dictionary.
Definition: namedDictionary.C:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60