entry.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::entry
26 
27 Description
28  A keyword and a list of tokens is an 'entry'.
29 
30  An entry can be read, written and printed, and the types and values of
31  its tokens analysed. An entry is a high-level building block for data
32  description. It is a front-end for the token parser. A list of entries
33  can be used as a set of keyword syntax elements, for example.
34 
35 SourceFiles
36  entry.C
37  entryIO.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef entry_H
42 #define entry_H
43 
44 #include "keyType.H"
45 #include "IDLList.H"
46 #include "fileName.H"
47 #include "autoPtr.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 class ITstream;
55 class dictionary;
56 
57 // Forward declaration of friend functions and operators
58 
59 class entry;
60 Ostream& operator<<(Ostream&, const entry&);
61 
62 /*---------------------------------------------------------------------------*\
63  Class entry Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class entry
67 :
68  public IDLList<entry>::link
69 {
70  // Private Data
71 
72  //- Keyword of entry
73  keyType keyword_;
74 
75  //- Line number of the entry keyword
76  label startLineNumber_;
77 
78 
79  // Private Member Functions
80 
81  //- Get the next valid keyword
82  // set the line number return true if is valid
83  static bool getKeyword
84  (
86  token& keywordToken,
87  label& keywordLineNo,
88  Istream& is
89  );
90 
91  //- Get the next valid keyword
92  // set the line number return true if is valid
93  static bool getKeyword
94  (
96  label& keywordLineNo,
97  Istream& is
98  );
99 
100 
101 public:
102 
103  static int disableFunctionEntries;
104 
105 
106  // Constructors
107 
108  //- Construct from keyword and optional line number
109  explicit entry(const keyType& keyword, const label lineNumber=-1);
110 
111  //- Copy constructor
112  entry(const entry&);
113 
114  //- Construct on freestore as copy with reference to the
115  // dictionary the copy belongs to
116  virtual autoPtr<entry> clone(const dictionary& parentDict) const = 0;
117 
118  //- Construct on freestore as copy
119  // Note: the parent directory is set to dictionary::null
120  virtual autoPtr<entry> clone() const;
121 
122  //- Construct from Istream and insert into dictionary
123  static bool New(dictionary& parentDict, Istream&);
124 
125  //- Construct on freestore from Istream and return
126  static autoPtr<entry> New(Istream& is);
127 
128 
129  //- Destructor
130  virtual ~entry()
131  {}
132 
133 
134  // Member Functions
135 
136  //- Return keyword
137  const keyType& keyword() const
138  {
139  return keyword_;
140  }
141 
142  //- Return non-const access to keyword
143  keyType& keyword()
144  {
145  return keyword_;
146  }
147 
148  //- Return the dictionary name
149  virtual const fileName& name() const = 0;
150 
151  //- Return the dictionary name
152  virtual fileName& name() = 0;
153 
154  //- Return line number of keyword of the entry
155  virtual label startLineNumber() const
156  {
157  return startLineNumber_;
158  }
159 
160  //- Return non-const access to line number of keyword of the entry
161  virtual label& startLineNumber()
162  {
163  return startLineNumber_;
164  }
165 
166  //- Return line number of last token in dictionary
167  virtual label endLineNumber() const = 0;
168 
169  //- Return true if this entry is a stream
170  virtual bool isStream() const
171  {
172  return false;
173  }
174 
175  //- Return token stream if this entry is a primitive entry
176  virtual ITstream& stream() const = 0;
177 
178  //- Return true if this entry is a dictionary
179  virtual bool isDict() const
180  {
181  return false;
182  }
183 
184  //- Return dictionary if this entry is a dictionary
185  virtual const dictionary& dict() const = 0;
186 
187  //- Return non-const access to dictionary if this entry is a dictionary
188  virtual dictionary& dict() = 0;
189 
190  //- Write
191  virtual void write(Ostream&) const = 0;
192 
193 
194  // Member Operators
195 
196  void operator=(const entry&);
197 
198  bool operator==(const entry&) const;
199  bool operator!=(const entry&) const;
200 
201 
202  // Ostream operator
203 
204  friend Ostream& operator<<(Ostream&, const entry&);
205 };
206 
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 } // End namespace Foam
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #endif
215 
216 // ************************************************************************* //
Intrusive doubly-linked list.
Template class for intrusive linked lists.
Definition: ILList.H:67
Input token stream.
Definition: ITstream.H:53
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
virtual void write(Ostream &) const =0
Write.
void operator=(const entry &)
Definition: entry.C:64
friend Ostream & operator<<(Ostream &, const entry &)
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:178
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
const keyType & keyword() const
Return keyword.
Definition: entry.H:136
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:56
virtual label startLineNumber() const
Return line number of keyword of the entry.
Definition: entry.H:154
virtual const fileName & name() const =0
Return the dictionary name.
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
Definition: entryIO.C:103
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
entry(const keyType &keyword, const label lineNumber=-1)
Construct from keyword and optional line number.
Definition: entry.C:40
virtual label endLineNumber() const =0
Return line number of last token in dictionary.
virtual bool isStream() const
Return true if this entry is a stream.
Definition: entry.H:169
bool operator==(const entry &) const
Definition: entry.C:78
bool operator!=(const entry &) const
Definition: entry.C:97
virtual ~entry()
Destructor.
Definition: entry.H:129
static int disableFunctionEntries
Definition: entry.H:102
A class for handling file names.
Definition: fileName.H:82
A class for handling keywords in dictionaries.
Definition: keyType.H:69
A token holds items read from Istream.
Definition: token.H:73
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)