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-2022 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  In can also be used in situations where an individual dictionary entry
44  should be read.
45  \verbatim
46  actions
47  (
48  testing { action new; ... } // An action with a name
49  { action subset; } // Unnamed action
50  );
51  \endverbatim
52  Normal dictionary reading would fail for this type of input since the
53  leading 'testing' keyword would cause the entire content to be considered
54  a single dictionary.
55 
56 Note
57  No distinction currently made between a missing and an empty dictionary.
58 
59 SourceFiles
60  namedDictionary.C
61 
62 \*---------------------------------------------------------------------------*/
63 
64 #ifndef Foam_namedDictionary_H
65 #define Foam_namedDictionary_H
66 
67 #include "dictionary.H"
68 #include "Tuple2.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 // Forward Declarations
76 class namedDictionary;
77 
78 Istream& operator>>(Istream&, namedDictionary&);
79 Ostream& operator<<(Ostream&, const namedDictionary&);
80 
81 /*---------------------------------------------------------------------------*\
82  Class namedDictionary Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 class namedDictionary
86 :
87  public Tuple2<keyType, dictionary>
88 {
89 public:
90 
91  // Constructors
92 
93  //- Inherit constructors
95 
96  //- Default construct
97  namedDictionary() = default;
98 
99  //- Construct from Istream
100  explicit namedDictionary(Istream& is);
101 
102 
103  //- Destructor
104  ~namedDictionary() = default;
105 
106 
107  // Member Functions
108 
109  //- Clear keyword and dictionary
110  void clear();
111 
112  //- Empty if both keyword and dictionary are empty
113  bool empty() const noexcept;
114 
115  //- Return keyword
116  const keyType& keyword() const noexcept
117  {
118  return first();
119  }
120 
121  //- Return non-const access to keyword
123  {
124  return first();
125  }
126 
127  //- Read-access to the dictionay
128  const dictionary& dict() const noexcept
129  {
130  return second();
131  }
132 
133  //- Write access to the dictionay
135  {
136  return second();
137  }
138 
139 
140  // IOstream Operators
143  friend Ostream& operator<<(Ostream&, const namedDictionary&);
144 };
145 
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 } // End namespace Foam
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #endif
154 
155 // ************************************************************************* //
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:120
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:55
const direction noexcept
Definition: Scalar.H:258
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
~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.