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 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 namedDictionary_H
65 #define 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 Istream& operator>>(Istream&, namedDictionary&);
78 Ostream& operator<<(Ostream&, const namedDictionary&);
79 
80 /*---------------------------------------------------------------------------*\
81  Class namedDictionary Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 class namedDictionary
85 :
86  public Tuple2<keyType, dictionary>
87 {
88 public:
89 
90  // Constructors
91 
92  //- Inherit constructors
94 
95  //- Default construct
97 
98  //- Construct from Istream
99  explicit namedDictionary(Istream& is);
100 
101 
102  //- Destructor
103  ~namedDictionary() = default;
104 
105 
106  // Member Functions
107 
108  //- Clear keyword and dictionary
109  void clear();
110 
111  //- Empty if both keyword and dictionary are empty
112  bool empty() const noexcept;
113 
114  //- Return keyword
115  const keyType& keyword() const noexcept
116  {
117  return first();
118  }
119 
120  //- Return non-const access to keyword
121  keyType& keyword() noexcept
122  {
123  return first();
124  }
125 
126  //- Read-access to the dictionay
127  const dictionary& dict() const noexcept
128  {
129  return second();
130  }
131 
132  //- Write access to the dictionay
133  dictionary& dict() noexcept
134  {
135  return second();
136  }
137 
138 
139  // IOstream Operators
140 
142  friend Ostream& operator<<(Ostream&, const namedDictionary&);
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
Foam::namedDictionary::dict
const dictionary & dict() const noexcept
Read-access to the dictionay.
Definition: namedDictionary.H:126
Tuple2.H
Foam::namedDictionary::dict
dictionary & dict() noexcept
Write access to the dictionay.
Definition: namedDictionary.H:132
Foam::namedDictionary::namedDictionary
namedDictionary()
Default construct.
Definition: namedDictionary.C:33
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::namedDictionary::operator<<
friend Ostream & operator<<(Ostream &, const namedDictionary &)
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::namedDictionary::keyword
keyType & keyword() noexcept
Return non-const access to keyword.
Definition: namedDictionary.H:120
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::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::namedDictionary::operator>>
friend Istream & operator>>(Istream &, namedDictionary &)
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
dictionary.H
Foam::Tuple2< keyType, dictionary >::second
const dictionary & second() const noexcept
Return second.
Definition: Tuple2.H:130
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
Foam::namedDictionary::~namedDictionary
~namedDictionary()=default
Destructor.
Foam::Tuple2< keyType, dictionary >::first
const keyType & first() const noexcept
Return first.
Definition: Tuple2.H:118