entry.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 | Copyright (C) 2011 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 otherwise return false
79  static bool getKeyword(keyType&, Istream&);
80 
81 
82 public:
83 
84  static int disableFunctionEntries;
85 
86 
87  // Constructors
88 
89  //- Construct from keyword
90  entry(const keyType&);
91 
92  //- Construct as copy
93  entry(const entry&);
94 
95  //- Construct on freestore as copy with reference to the
96  // dictionary the copy belongs to
97  virtual autoPtr<entry> clone
98  (
99  const dictionary& parentDict
100  ) const = 0;
101 
102  //- Construct on freestore as copy
103  // Note: the parent directory is set to dictionary::null
104  virtual autoPtr<entry> clone() const;
105 
106  //- Construct from Istream and insert into dictionary
107  static bool New(dictionary& parentDict, Istream&);
108 
109  //- Construct on freestore from Istream and return
110  static autoPtr<entry> New(Istream& is);
111 
112 
113  //- Destructor
114  virtual ~entry()
115  {}
116 
117 
118  // Member functions
119 
120  //- Return keyword
121  const keyType& keyword() const
122  {
123  return keyword_;
124  }
125 
126  //- Return non-const access to keyword
127  keyType& keyword()
128  {
129  return keyword_;
130  }
131 
132  //- Return the dictionary name
133  virtual const fileName& name() const = 0;
134 
135  //- Return the dictionary name
136  virtual fileName& name() = 0;
137 
138  //- Return line number of first token in dictionary
139  virtual label startLineNumber() const = 0;
140 
141  //- Return line number of last token in dictionary
142  virtual label endLineNumber() const = 0;
143 
144  //- Return true if this entry is a stream
145  virtual bool isStream() const
146  {
147  return false;
148  }
149 
150  //- Return token stream if this entry is a primitive entry
151  virtual ITstream& stream() const = 0;
152 
153  //- Return true if this entry is a dictionary
154  virtual bool isDict() const
155  {
156  return false;
157  }
158 
159  //- Return dictionary if this entry is a dictionary
160  virtual const dictionary& dict() const = 0;
161 
162  //- Return non-const access to dictionary if this entry is a dictionary
163  virtual dictionary& dict() = 0;
164 
165  //- Write
166  virtual void write(Ostream&) const = 0;
167 
168 
169  // Member operators
170 
171  void operator=(const entry&);
172 
173  bool operator==(const entry&) const;
174  bool operator!=(const entry&) const;
175 
176 
177  // Ostream operator
178 
179  friend Ostream& operator<<(Ostream&, const entry&);
180 };
181 
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 } // End namespace Foam
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:64
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
A class for handling file names.
Definition: fileName.H:69
bool operator!=(const entry &) const
Definition: entry.C:95
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual ~entry()
Destructor.
Definition: entry.H:113
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void write(Ostream &) const =0
Write.
bool operator==(const entry &) const
Definition: entry.C:76
virtual label startLineNumber() const =0
Return line number of first token in dictionary.
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
Definition: entryIO.C:91
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
entry(const keyType &)
Construct from keyword.
Definition: entry.C:40
static int disableFunctionEntries
Definition: entry.H:83
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
void operator=(const entry &)
Definition: entry.C:62
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Intrusive doubly-linked list.
Definition: IDLList.H:47
virtual label endLineNumber() const =0
Return line number of last token in dictionary.
Ostream & operator<<(Ostream &, const ensightPart &)
virtual const fileName & name() const =0
Return the dictionary name.
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:54
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
virtual bool isStream() const
Return true if this entry is a stream.
Definition: entry.H:144
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
Input token stream.
Definition: ITstream.H:49
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
friend Ostream & operator<<(Ostream &, const entry &)