namedDictionary.H
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-2023 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 Class
28  Foam::namedDictionary
29 
30 Description
31  A tuple of keyType and dictionary, which can be used when reading
32  named or unnamed dictionary entries or simply a name.
33 
34  For example,
35  \verbatim
36  fields
37  (
38  U
39  T { relax false; }
40  );
41  \endverbatim
42 
43  The namedDictionary can also be used in situations where an individual
44  dictionary entry should be read. The keyword() and dict() methods
45  correspond to Foam::entry naming conventions.
46  \verbatim
47  actions
48  (
49  testing { action new; ... } // An action with a name
50  { action subset; } // Unnamed action
51  );
52  \endverbatim
53  Normal dictionary reading would fail for this type of input since the
54  leading 'testing' keyword would cause the entire content to be considered
55  a single dictionary.
56 
57 Note
58  No distinction currently made between a missing and an empty dictionary.
59 
60 SourceFiles
61  namedDictionary.C
62 
63 \*---------------------------------------------------------------------------*/
64 
65 #ifndef Foam_namedDictionary_H
66 #define Foam_namedDictionary_H
67 
68 #include "dictionary.H"
69 #include "Tuple2.H"
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
73 namespace Foam
74 {
75 
76 // Forward Declarations
77 class namedDictionary;
78 
79 Istream& operator>>(Istream&, namedDictionary&);
80 Ostream& operator<<(Ostream&, const namedDictionary&);
81 
82 /*---------------------------------------------------------------------------*\
83  Class namedDictionary Declaration
84 \*---------------------------------------------------------------------------*/
85 
86 class namedDictionary
87 :
88  public Tuple2<keyType, dictionary>
89 {
90 public:
91 
92  // Constructors
93 
94  //- Inherit constructors
96 
97  //- Default construct
98  namedDictionary() = default;
99 
100  //- Construct from Istream
101  explicit namedDictionary(Istream& is);
102 
103 
104  //- Destructor
105  ~namedDictionary() = default;
106 
107 
108  // Member Functions
109 
110  //- Clear keyword and dictionary
111  void clear();
112 
113  //- Empty if both keyword and dictionary are empty
114  bool empty() const noexcept;
115 
116  //- Return keyword
117  const keyType& keyword() const noexcept { return first(); }
118 
119  //- Return non-const access to keyword
120  keyType& keyword() noexcept { return first(); }
121 
122  //- Read-access to the dictionay
123  const dictionary& dict() const noexcept { return second(); }
124 
125  //- Write access to the dictionay
126  dictionary& dict() noexcept { return second(); }
127 
128 
129  // IOstream Operators
130 
132  friend Ostream& operator<<(Ostream&, const namedDictionary&);
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 #endif
143 
144 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:54
friend Ostream & operator<<(Ostream &, const namedDictionary &)
namedDictionary()=default
Default construct.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const keyType & keyword() const noexcept
Return keyword.
Istream & operator>>(Istream &, directionInfo &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
~namedDictionary()=default
Destructor.
A tuple of keyType and dictionary, which can be used when reading named or unnamed dictionary entries...
const dictionary & second() const noexcept
Access the second element.
Definition: Tuple2.H:142
bool empty() const noexcept
Empty if both keyword and dictionary are empty.
const dictionary & dict() const noexcept
Read-access to the dictionay.
const keyType & first() const noexcept
Access the first element.
Definition: Tuple2.H:132
friend Istream & operator>>(Istream &, namedDictionary &)
Namespace for OpenFOAM.
void clear()
Clear keyword and dictionary.