dictionaryEntry.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-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::dictionaryEntry
29 
30 Description
31  A keyword and a list of tokens is a 'dictionaryEntry'.
32 
33  An dictionaryEntry can be read, written and printed, and the types and
34  values of its tokens analysed. A dictionaryEntry is a high-level building
35  block for data description. It is a front-end for the token parser.
36  A list of entries can be used as a set of keyword syntax elements,
37  for example.
38 
39 SourceFiles
40  dictionaryEntry.C
41  dictionaryEntryIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_dictionaryEntry_H
46 #define Foam_dictionaryEntry_H
47 
48 #include "entry.H"
49 #include "dictionary.H"
50 #include "InfoProxy.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class dictionaryEntry;
59 Ostream& operator<<(Ostream& os, const dictionaryEntry& e);
60 
61 template<>
62 Ostream& operator<<(Ostream&, const InfoProxy<dictionaryEntry>&);
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class dictionaryEntry Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class dictionaryEntry
70 :
71  public entry,
72  public dictionary
73 {
74 public:
75 
76  // Generated Methods
77 
78  //- No copy construct
79  dictionaryEntry(const dictionaryEntry&) = delete;
80 
81 
82  // Constructors
83 
84  //- Construct from the parent dictionary and Istream.
85  // The keyword is extracted from the stream
86  dictionaryEntry(const dictionary& parentDict, Istream& is);
87 
88  //- Construct from the keyword, parent dictionary and a Istream
90  (
91  const keyType& key,
92  const dictionary& parentDict,
93  Istream& is
94  );
95 
96  //- Construct from the keyword, parent dictionary and a dictionary
98  (
99  const keyType& key,
100  const dictionary& parentDict,
101  const dictionary& dict
102  );
103 
104  //- Construct as copy for the given parent dictionary
106  (
107  const dictionary& parentDict,
108  const dictionaryEntry& dictEnt
109  );
110 
111  autoPtr<entry> clone(const dictionary& parentDict) const
112  {
113  return autoPtr<entry>(new dictionaryEntry(parentDict, *this));
114  }
115 
116 
117  // Member functions
118 
119  //- Return the scoped dictionary name (eg, dictA.dictB.dictC)
120  virtual const fileName& name() const
121  {
122  return dictionary::name();
123  }
124 
125  //- Return scoped dictionary name for modification
126  virtual fileName& name()
127  {
129  }
130 
131  //- Return scoped dictionary name relative to the current case
132  virtual fileName relativeName() const
133  {
134  return dictionary::relativeName();
135  }
137  //- Return line number of first token in dictionary
138  virtual label startLineNumber() const;
139 
140  //- Return line number of last token in dictionary
141  virtual label endLineNumber() const;
142 
143  //- This entry is not a primitive,
144  //- calling this function generates a FatalError
145  virtual ITstream& stream() const;
146 
147 
148  //- Return pointer to this dictionary
149  virtual const dictionary* dictPtr() const noexcept;
150 
151  //- Return non-const pointer to this dictionary
152  virtual dictionary* dictPtr() noexcept;
153 
154  //- Return dictionary (ie, this)
155  virtual const dictionary& dict() const noexcept;
156 
157  //- Return non-const access to dictionary
158  virtual dictionary& dict() noexcept;
159 
160 
161  //- Write
162  virtual void write(Ostream& os) const;
163 
164  //- Return info proxy,
165  //- used to print token information to a stream
166  InfoProxy<dictionaryEntry> info() const noexcept { return *this; }
167 
168 
169  // Ostream Operators
170 
171  friend Ostream& operator<<(Ostream& os, const dictionaryEntry& e);
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Foam
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 #endif
182 
183 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:66
A class for handling file names.
Definition: fileName.H:72
dictionaryEntry(const dictionaryEntry &)=delete
No copy construct.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
InfoProxy< dictionaryEntry > info() const noexcept
Return info proxy, used to print token information to a stream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual ITstream & stream() const
This entry is not a primitive, calling this function generates a FatalError.
friend Ostream & operator<<(Ostream &os, const dictionaryEntry &e)
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:41
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:165
virtual label endLineNumber() const
Return line number of last token in dictionary.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
virtual fileName relativeName() const
Return scoped dictionary name relative to the current case.
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
OBJstream os(runTime.globalPath()/outputName)
virtual void write(Ostream &os) const
Write.
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:179
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
virtual label startLineNumber() const
Return line number of first token in dictionary.
virtual const fileName & name() const
Return the scoped dictionary name (eg, dictA.dictB.dictC)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual const dictionary & dict() const noexcept
Return dictionary (ie, this)
virtual const dictionary * dictPtr() const noexcept
Return pointer to this dictionary.
An input stream of tokens.
Definition: ITstream.H:52
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63