FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/keyType.H>
45 #include <OpenFOAM/IDLList.H>
46 #include <OpenFOAM/fileName.H>
47 #include <OpenFOAM/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  // Constructors
85 
86  //- Construct from keyword
87  entry(const keyType&);
88 
89  //- Construct as copy
90  entry(const entry&);
91 
92  //- Construct on freestore as copy with reference to the
93  // dictionary the copy belongs to
94  virtual autoPtr<entry> clone
95  (
96  const dictionary& parentDict
97  ) const = 0;
98 
99  //- Construct on freestore as copy
100  // Note: the parent directory is set to dictionary::null
101  virtual autoPtr<entry> clone() const;
102 
103  //- Construct from Istream and insert into dictionary
104  static bool New(dictionary& parentDict, Istream&);
105 
106  //- Construct on freestore from Istream and return
107  static autoPtr<entry> New(Istream& is);
108 
109 
110  //- Destructor
111  virtual ~entry()
112  {}
113 
114 
115  // Member functions
116 
117  //- Return keyword
118  const keyType& keyword() const
119  {
120  return keyword_;
121  }
122 
123  //- Return non-const access to keyword
125  {
126  return keyword_;
127  }
128 
129  //- Return the dictionary name
130  virtual const fileName& name() const = 0;
131 
132  //- Return the dictionary name
133  virtual fileName& name() = 0;
134 
135  //- Return line number of first token in dictionary
136  virtual label startLineNumber() const = 0;
137 
138  //- Return line number of last token in dictionary
139  virtual label endLineNumber() const = 0;
140 
141  //- Return true if this entry is a stream
142  virtual bool isStream() const
143  {
144  return false;
145  }
146 
147  //- Return token stream if this entry is a primitive entry
148  virtual ITstream& stream() const = 0;
149 
150  //- Return true if this entry is a dictionary
151  virtual bool isDict() const
152  {
153  return false;
154  }
155 
156  //- Return dictionary if this entry is a dictionary
157  virtual const dictionary& dict() const = 0;
158 
159  //- Return non-const access to dictionary if this entry is a dictionary
160  virtual dictionary& dict() = 0;
161 
162  //- Write
163  virtual void write(Ostream&) const = 0;
164 
165 
166  // Member operators
167 
168  void operator=(const entry&);
169 
170  bool operator==(const entry&) const;
171  bool operator!=(const entry&) const;
172 
173 
174  // Ostream operator
175 
176  friend Ostream& operator<<(Ostream&, const entry&);
177 };
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 } // End namespace Foam
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #endif
187 
188 // ************************ vim: set sw=4 sts=4 et: ************************ //