1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A list of keyword definitions, which are a keyword followed by any number
30 of values (e.g. words and numbers).
32 The dictionary class is the base class for IOdictionary.
33 It also serves as a bootstrap dictionary for the objectRegistry data
34 dictionaries since, unlike the IOdictionary class, it does not use an
35 objectRegistry itself to work.
38 A merge() member function with a non-const dictionary parameter.
39 This would avoid unnecessary cloning in the add(entry*,bool) method
45 \*---------------------------------------------------------------------------*/
54 #include "HashTable.H"
56 #include "className.H"
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 // Forward declaration of friend functions and operators
66 Istream& operator>>(Istream&, dictionary&);
67 Ostream& operator<<(Ostream&, const dictionary&);
70 /*---------------------------------------------------------------------------*\
71 Class dictionary Declaration
72 \*---------------------------------------------------------------------------*/
83 //- HashTable of the enries held on the DL-list for quick lookup
84 HashTable<entry*> hashedEntries_;
87 const dictionary& parent_;
92 //- Read dictionary from Istream
95 //- Substitute the given keyword prepended by '$' with the
96 // corresponding sub-dictionary entries
97 bool substituteKeyword(const word& keyword);
102 //- Declare friendship with the entry class for IO
106 // Declare name of the class and its debug switch
107 ClassName("dictionary");
111 static const dictionary null;
116 //- Construct top-level dictionary null
119 //- Construct from the parent dictionary and Istream, reading entries
120 // until lastEntry or EOF
123 const dictionary& parentDict,
127 //- Construct top-level dictionary from Istream, reading entries
129 dictionary(Istream&);
131 //- Construct as copy given the parent dictionary
132 dictionary(const dictionary& parentDict, const dictionary& dict);
134 //- Construct top-level dictionary as copy
135 dictionary(const dictionary& dict);
137 //- Construct and return clone
138 Foam::autoPtr<dictionary> clone() const;
140 //- Construct top-level dictionary on freestore from Istream
141 static Foam::autoPtr<dictionary> New(Istream& is);
151 //- Return the dictionary name
152 const fileName& name() const
157 //- Return the dictionary name
163 //- Return the parent dictionary
164 const dictionary& parent() const
169 //- Return line number of first token in dictionary
170 label startLineNumber() const;
172 //- Return line number of last token in dictionary
173 label endLineNumber() const;
178 //- Search dictionary for given keyword
179 // If recursive search parent dictionaries
180 bool found(const word& keyword, bool recursive=false) const;
182 //- Find and return an entry data stream pointer if present
183 // otherwise return NULL.
184 // If recursive search parent dictionaries
185 const entry* lookupEntryPtr
187 const word&, bool recursive=false
190 //- Find and return an entry data stream pointer for manipulation
191 // if present otherwise return NULL.
192 // If recursive search parent dictionaries
193 entry* lookupEntryPtr(const word&, bool recursive=false);
195 //- Find and return an entry data stream if present otherwise error.
196 // If recursive search parent dictionaries
197 const entry& lookupEntry(const word&, bool recursive=false) const;
199 //- Find and return an entry data stream
200 // If recursive search parent dictionaries
201 ITstream& lookup(const word&, bool recursive=false) const;
203 //- Find and return a T,
204 // if not found return the given default value
205 // If recursive search parent dictionaries
214 //- Find and return a T, if not found return the given
215 // default value, and add to dictionary.
216 // If recursive search parent dictionaries
225 //- Find an entry if present, and assign to T
226 // Returns true if the entry was found
235 //- Check if entry is a sub-dictionary
236 bool isDict(const word&) const;
238 //- Find and return a sub-dictionary pointer if present
239 // otherwise return NULL.
240 const dictionary* subDictPtr(const word&) const;
242 //- Find and return a sub-dictionary
243 const dictionary& subDict(const word&) const;
245 //- Find and return a sub-dictionary for manipulation
246 dictionary& subDict(const word&);
248 //- Return the table of contents
249 wordList toc() const;
255 // With the merge option, dictionaries are interwoven and
256 // primitive entries are overwritten
257 bool add(entry*, bool mergeEntry=false);
260 // With the merge option, dictionaries are interwoven and
261 // primitive entries are overwritten
262 void add(const entry&, bool mergeEntry=false);
265 // optionally overwrite an existing entry
266 void add(const word& keyword, const word&, bool overwrite=false);
268 //- Add a string entry
269 // optionally overwrite an existing entry
270 void add(const word& keyword, const string&, bool overwrite=false);
272 //- Add a label entry
273 // optionally overwrite an existing entry
274 void add(const word& keyword, const label, bool overwrite=false);
276 //- Add a scalar entry
277 // optionally overwrite an existing entry
278 void add (const word& keyword, const scalar, bool overwrite=false);
280 //- Add a dictionary entry
281 // optionally merge with an existing sub-dictionary
286 bool mergeEntry=false
290 // optionally overwrite an existing entry
292 void add(const word& keyword, const T&, bool overwrite=false);
294 //- Assign a new entry, overwrite any existing entry
297 //- Assign a new entry, overwrite any existing entry
298 void set(const entry&);
300 //- Assign a dictionary entry, overwrite any existing entry
301 void set(const word& keyword, const dictionary&);
303 //- Assign a T entry, overwrite any existing entry
305 void set(const word& keyword, const T&);
307 //- Remove an entry specified by keyword
308 bool remove(const word& keyword);
310 //- Change the keyword for an entry,
311 // optionally forcing overwrite of an existing entry
314 const word& oldKeyword,
315 const word& newKeyword,
316 bool forceOverwrite = false
319 //- Merge entries from the given dictionary.
320 // Also merge sub-dictionaries as required.
321 bool merge(const dictionary&);
323 //- Clear the dictionary
329 void write(Ostream& os, bool subDict = true) const;
334 //- Find and return entry
335 ITstream& operator[](const word&) const;
337 void operator=(const dictionary&);
339 //- Include entries from the given dictionary.
340 // Warn, but do not overwrite existing entries
341 void operator+=(const dictionary&);
343 //- Conditionally include entries from the given dictionary.
344 // Do not overwrite existing entries.
345 void operator|=(const dictionary&);
347 //- Unconditionally include entries from the given dictionary.
348 // Overwrite existing entries.
349 void operator<<=(const dictionary&);
352 // IOstream operators
354 //- Read dictionary from Istream
355 friend Istream& operator>>(Istream&, dictionary&);
357 //- Write dictionary to Ostream
358 friend Ostream& operator<<(Ostream&, const dictionary&);
364 //- Combine dictionaries starting from the entries in dict1 and then including those from dict2.
365 // Warn, but do not overwrite the entries from dict1.
366 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
368 //- Combine dictionaries starting from the entries in dict1 and then including those from dict2.
369 // Do not overwrite the entries from dict1.
370 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 } // End namespace Foam
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 # include "dictionaryTemplates.C"
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 // ************************************************************************* //