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-2020 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 
76  // Private Member Functions
77 
78  //- Get the next valid keyword. Return true if is valid keyType.
79  static bool getKeyword(keyType&, token&, Istream&);
80 
81  //- Get the next valid keyword otherwise return false
82  static bool getKeyword(keyType&, Istream&);
83 
84 
85 public:
86 
87  static int disableFunctionEntries;
88 
89 
90  // Constructors
91 
92  //- Construct from keyword
93  entry(const keyType&);
94 
95  //- Copy constructor
96  entry(const entry&);
97 
98  //- Construct on freestore as copy with reference to the
99  // dictionary the copy belongs to
100  virtual autoPtr<entry> clone
101  (
102  const dictionary& parentDict
103  ) const = 0;
104 
105  //- Construct on freestore as copy
106  // Note: the parent directory is set to dictionary::null
107  virtual autoPtr<entry> clone() const;
108 
109  //- Construct from Istream and insert into dictionary
110  static bool New(dictionary& parentDict, Istream&);
111 
112  //- Construct on freestore from Istream and return
113  static autoPtr<entry> New(Istream& is);
114 
115 
116  //- Destructor
117  virtual ~entry()
118  {}
119 
120 
121  // Member Functions
122 
123  //- Return keyword
124  const keyType& keyword() const
125  {
126  return keyword_;
127  }
128 
129  //- Return non-const access to keyword
130  keyType& keyword()
131  {
132  return keyword_;
133  }
134 
135  //- Return the dictionary name
136  virtual const fileName& name() const = 0;
137 
138  //- Return the dictionary name
139  virtual fileName& name() = 0;
140 
141  //- Return line number of first token in dictionary
142  virtual label startLineNumber() const = 0;
143 
144  //- Return line number of last token in dictionary
145  virtual label endLineNumber() const = 0;
146 
147  //- Return true if this entry is a stream
148  virtual bool isStream() const
149  {
150  return false;
151  }
152 
153  //- Return token stream if this entry is a primitive entry
154  virtual ITstream& stream() const = 0;
155 
156  //- Return true if this entry is a dictionary
157  virtual bool isDict() const
158  {
159  return false;
160  }
161 
162  //- Return dictionary if this entry is a dictionary
163  virtual const dictionary& dict() const = 0;
164 
165  //- Return non-const access to dictionary if this entry is a dictionary
166  virtual dictionary& dict() = 0;
167 
168  //- Write
169  virtual void write(Ostream&) const = 0;
170 
171 
172  // Member Operators
173 
174  void operator=(const entry&);
175 
176  bool operator==(const entry&) const;
177  bool operator!=(const entry&) const;
178 
179 
180  // Ostream operator
181 
182  friend Ostream& operator<<(Ostream&, const entry&);
183 };
184 
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 } // End namespace Foam
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 #endif
193 
194 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
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:62
friend Ostream & operator<<(Ostream &, const entry &)
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:156
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
virtual label startLineNumber() const =0
Return line number of first token in dictionary.
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:54
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:91
entry(const keyType &)
Construct from keyword.
Definition: entry.C:40
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
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:147
bool operator==(const entry &) const
Definition: entry.C:76
bool operator!=(const entry &) const
Definition: entry.C:95
virtual ~entry()
Destructor.
Definition: entry.H:116
static int disableFunctionEntries
Definition: entry.H:86
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)