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-------------------------------------------------------------------------------
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 "namedDictionary.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34{
35 is >> *this;
36}
37
38
39// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40
42{
43 first().clear();
44 second().clear();
45}
46
47
49{
50 return (first().empty() && second().empty());
51}
52
53
54// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
55
57{
58 obj.clear();
59
60 // Three possible inputs:
61 // - key
62 // - key { ... }
63 // - { ... }
64
65 // Minor consistency with primitiveEntry, also accept the following:
66 // - key ;
67
68 token tok(is);
69 is.putBack(tok);
70
72 {
73 is >> obj.keyword();
74 is >> tok;
75
76 // Discards possible trailing ';'
77 if (!tok.isPunctuation(token::END_STATEMENT))
78 {
79 is.putBack(tok);
80 }
81 }
82
84 {
85 obj.dict().read(is);
86 }
87
89 return is;
90}
91
92
94{
95 // Three possible outputs:
96 // - key
97 // - key { ... }
98 // - { ... }
99 // No distinction between a missing and an empty dictionary
100
101 if (obj.keyword().empty() || !obj.dict().empty())
102 {
103 // Never allow empty output.
104 // Otherwise cannot re-read for streaming
105 obj.dict().writeEntry(obj.keyword(), os);
106 }
107 else
108 {
109 os << obj.keyword();
110 }
111
112 return os;
113}
114
115
116// ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
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
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:164
bool read(Istream &is)
Read dictionary from Istream. Discards the header.
Definition: dictionaryIO.C:141
A tuple of keyType and dictionary, which can be used when reading named or unnamed dictionary entries...
bool empty() const noexcept
Empty if both keyword and dictionary are empty.
namedDictionary()=default
Default construct.
const keyType & keyword() const noexcept
Return keyword.
void clear()
Clear keyword and dictionary.
const dictionary & dict() const noexcept
Read-access to the dictionay.
A token holds an item read from Istream.
Definition: token.H:69
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:159
@ END_STATEMENT
End entry [isseparator].
Definition: token.H:154
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:223