dictionary.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::dictionary
29 
30 Description
31  A list of keyword definitions, which are a keyword followed by a number
32  of values (eg, words and numbers) or by a sub-dictionary.
33  Since the dictionary format is used extensively throughout OpenFOAM for
34  input/output files, there are many examples of its use.
35 
36  Dictionary keywords are a plain word or a pattern (regular expression).
37  The general order for searching is as follows:
38  - exact match
39  - pattern match (in reverse order)
40  - optional recursion into the enclosing (parent) dictionaries
41 
42  The dictionary class is the base class for IOdictionary and also serves
43  as a bootstrap dictionary for the objectRegistry data dictionaries.
44 
45 Note
46  Within dictionaries, entries can be referenced by using the
47  \c '$' syntax familiar from shell programming.
48  Similarly, the \c '/' separator is used when referencing
49  sub-dictionary entries:
50  - <b> "./" </b> : the current dictionary
51  - <b> "../" </b> : the parent dictionary
52  - <b> "../../" </b> : the grandparent dictionary
53  .
54 
55  An initial \c '/' anchor specifies that the path starts from the
56  top-level entry. It is also possible to use the '${}' syntax for clarity.
57 
58  For example,
59  \verbatim
60  key1 val1;
61  key2 $key1; // Use key1 value from current scope
62  key3 $./key1; // Use key1 value from current scope
63 
64  subdict1
65  {
66  key1 val1b;
67  key2 $../key1; // Use key1 value from parent
68  subdict2
69  {
70  key2 val2;
71  key3 $../../key1; // Use key1 value from grandparent
72  }
73  }
74 
75  key4 $/subdict1/subdict2/key3; // Lookup with absolute scoping
76  \endverbatim
77 
78  Prior to OpenFOAM-v1712, a dot-scoping (.) syntax was used, which is
79  still supported (AUG-2023) but deprecated in favour of the
80  less ambiguous slash-scoping (/) syntax.
81  With dot-scoping, an initial \c '^' anchor, or an initial (:), was used
82  to specify that the path starts from the top-level entry.
83 
84 
85 SourceFiles
86  dictionary.C
87  dictionaryIO.C
88  dictionarySearch.C
89 
90 SeeAlso
91  - Foam::entry
92  - Foam::dictionaryEntry
93  - Foam::primitiveEntry
94 
95 \*---------------------------------------------------------------------------*/
96 
97 #ifndef Foam_dictionary_H
98 #define Foam_dictionary_H
99 
100 #include <type_traits>
101 #include "entry.H"
102 #include "IDLList.H"
103 #include "DLList.H"
104 #include "fileName.H"
105 #include "ITstream.H"
106 #include "HashTable.H"
107 #include "wordList.H"
108 #include "className.H"
109 #include "refPtr.H"
110 #include "IOobjectOption.H"
111 
112 // Some common data types
113 #include "label.H"
114 #include "scalar.H"
115 #include "regExpFwd.H"
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 namespace Foam
120 {
121 
122 // Forward Declarations
123 class dictionary;
124 class OSstream;
125 class SHA1Digest;
126 
127 Istream& operator>>(Istream& is, dictionary& dict);
128 Ostream& operator<<(Ostream& os, const dictionary& dict);
130 /*---------------------------------------------------------------------------*\
131  Class dictionary Declaration
132 \*---------------------------------------------------------------------------*/
133 
134 class dictionary
135 :
136  public IDLList<entry>
137 {
138 public:
139 
140  // Searching
141 
142  //- Generic const/non-const dictionary entry %searcher.
143  // A %searcher provides a uniform means of finding and returning
144  // an entry pointer as well as the dictionary \a context in which
145  // the entry was located.
146  //
147  // Note that the constructors and set methods are protected such
148  // that only friends of the class can set things. This safeguards
149  // against inconsistencies in context/entry.
150  template<bool Const>
151  class Searcher
152  {
153  public:
154  friend dictionary;
155 
156  //- The const/non-const type for the context and sub-dictionaries
157  typedef typename std::conditional
159 
160  //- The const/non-const type for entries
161  typedef typename std::conditional
162  <Const, const entry, entry>::type value_type;
163 
164  //- A pointer to a const/non-const dictionary
165  typedef dict_type* dict_pointer;
166 
167  //- A reference to a const/non-const dictionary
168  typedef dict_type& dict_reference;
170  //- A pointer to a const/non-const entry
171  typedef value_type* pointer;
172 
173  //- A reference to a const/non-const entry
175 
176 
177  protected:
178 
179  //- The dictionary context for the entry
181 
182  //- The entry or nullptr
183  pointer eptr_;
185 
186  //- Implicit construct for the given dictionary context
188  :
189  dict_(dict),
190  eptr_(nullptr)
191  {}
193  //- Assign the entry
194  void set(pointer eptr) noexcept
195  {
196  eptr_ = eptr;
197  }
198 
199 
200  public:
201 
202  //- Default construct
203  constexpr Searcher() noexcept
204  :
205  dict_(nullptr),
206  eptr_(nullptr)
207  {}
208 
209 
210  //- True if entry was found
211  bool good() const noexcept { return eptr_; }
213  //- True if entry was found
214  // \deprecated(2019-01) - prefer good() method
215  bool found() const noexcept { return eptr_; }
216 
217  //- The containing dictionary context
218  dict_reference context() const { return *dict_; }
219 
220  //- A pointer to the entry (nullptr if not found)
221  pointer ptr() const noexcept { return eptr_; }
222 
223  //- A reference to the entry (Error if not found)
224  reference ref() const { return *eptr_; }
225 
226  //- True if found entry is a dictionary.
227  bool isDict() const noexcept
228  {
229  return (eptr_ && eptr_->dictPtr());
230  }
231 
232  //- True if found entry is a stream.
233  bool isStream() const noexcept
234  {
235  return (eptr_ && eptr_->streamPtr());
236  }
237 
238  //- Pointer to the found entry as a dictionary, nullptr otherwise
240  {
241  return (eptr_ ? eptr_->dictPtr() : nullptr);
242  }
243 
244  //- Pointer to the found entry as a stream, nullptr otherwise
246  {
247  return (eptr_ ? eptr_->streamPtr() : nullptr);
248  }
249 
250  //- Return the found entry as a dictionary.
251  //- Error if not found, or not a dictionary.
252  dict_reference dict() const { return eptr_->dict(); }
253 
254  //- Return the found entry as a ITstream.
255  //- Error if not found, or not a stream.
256  ITstream& stream() const { return eptr_->stream(); }
257 
258  //- Permit an explicit cast to the other (const/non-const) searcher
259  explicit operator const Searcher<!Const>&() const
260  {
261  return *reinterpret_cast<const Searcher<!Const>*>(this);
262  }
263 
264  //- A pointer to the entry (nullptr if not found)
265  pointer operator->() const noexcept { return eptr_; }
266 
267  //- A reference to the entry (Error if not found)
268  reference operator*() const { return *eptr_; }
269  };
270 
271 
272  //- Searcher with const access
273  typedef Searcher<true> const_searcher;
274 
275  //- Searcher with non-const access
277 
278 
279  // Friends
280 
281  //- Declare friendship with the entry class for IO
282  friend class entry;
283 
284  //- Declare friendship with the searcher classes
285  friend const_searcher;
286  friend searcher;
287 
288 
289 private:
290 
291  // Private Data
292 
293  //- The dictionary name
294  fileName name_;
295 
296  //- Parent dictionary
297  const dictionary& parent_;
298 
299  //- Quick lookup of the entries held on the IDLList
300  HashTable<entry*> hashedEntries_;
301 
302  //- Entries of matching patterns
303  DLList<entry*> patterns_;
305  //- Patterns as precompiled regular expressions
306  DLList<autoPtr<regExp>> regexps_;
307 
308 
309  // Typedefs
310 
311  //- The storage container
313 
314 
315  // Private Member Functions
316 
317  //- Convert old-style (1806) boolean search specification to enum
318  //
319  // \param recursive search parent dictionaries
320  // \param pattern match using regular expressions as well
321  inline static enum keyType::option
322  matchOpt(bool recursive, bool pattern)
323  {
324  return
326  (
327  (pattern ? keyType::REGEX : keyType::LITERAL)
328  | (recursive ? keyType::RECURSIVE : 0)
329  );
330  }
331 
332  //- Search using a '.' for scoping.
333  // A leading dot means to use the parent dictionary.
334  // An intermediate dot separates a sub-dictionary or sub-entry.
335  // However, the use of dots is unfortunately ambiguous.
336  // The value "a.b.c.d" could be a first-level entry, a second-level
337  // entry (eg, "a" with "b.c.d", "a.b" with "c.d" etc),
338  // or just about any other combination.
339  // The heuristic tries successively longer top-level entries
340  // until there is a suitable match.
341  //
342  // \param keyword the keyword to search for
343  // \param matchOpt the search mode
344  const_searcher csearchDotScoped
345  (
346  const word& keyword,
347  enum keyType::option matchOpt
348  ) const;
349 
350  //- Search using a '/' for scoping.
351  // Semantics as per normal files: an intermediate "." is the current
352  // dictionary level, an intermediate ".." is the parent dictionary.
353  // Note that since a slash is not a valid word character, there is no
354  // ambiguity between separator and content.
355  // No possibility or need for recursion.
356  //
357  // \param keyword the keyword to search for
358  // \param matchOpt the search mode. Recursive is ignored.
359  const_searcher csearchSlashScoped
360  (
361  const word& keyword,
362  enum keyType::option matchOpt
363  ) const;
364 
365 
366  //- Emit IOError about bad input for the entry
367  void raiseBadInput(const ITstream& is, const word& keyword) const;
368 
369  //- The currently known executable name,
370  //- obtained from argList envExecutable
371  static word executableName();
372 
373  //- Report (usually stderr) that the keyword default value was used,
374  //- or FatalIOError when writeOptionalEntries greater than 1
375  template<class T>
376  void reportDefault
377  (
378  const word& keyword,
379  const T& deflt,
380  const bool added = false // Value was added to the dictionary
381  ) const;
382 
383 
384 public:
385 
386  // Declare name of the class and its debug switch
387  ClassName("dictionary");
388 
389  // Static Data
390 
391  //- Report optional keywords and values if not present in dictionary
392  // For value greater than 1: fatal.
393  // Set/unset via an InfoSwitch or -info-switch at the command-line
394  static int writeOptionalEntries;
395 
396  //- An empty dictionary, which is also the parent for all dictionaries
397  static const dictionary null;
398 
399  //- Output location when reporting default values
401 
402 
403  // Static Member Functions
404 
405  //- Return the state of reporting optional (default) entries
406  // 0: no reporting, 1: report, 2: fatal if not set
407  inline static int reportOptional() noexcept;
408 
409  //- Change the state of reporting optional (default) entries
410  // 0: no reporting, 1: report, 2: fatal if not set
411  // \return old level
412  inline static int reportOptional(const int level) noexcept;
413 
414 
415  // Constructors
416 
417  //- Default construct, a top-level empty dictionary
418  dictionary();
419 
420  //- Construct top-level empty dictionary with given name
421  explicit dictionary(const fileName& name);
422 
423  //- Construct given the entry name, parent dictionary and Istream,
424  //- reading entries until EOF, optionally keeping the header
425  dictionary
426  (
427  const fileName& name,
428  const dictionary& parentDict,
429  Istream& is,
430  bool keepHeader = false
431  );
432 
433  //- Construct top-level dictionary from Istream (discards the header).
434  //- Reads entries until EOF or when the first token is a
435  //- '{' character, it will stop reading at the matching '}' character.
436  // \note this constructor should be explicit
437  dictionary(Istream& is);
438 
439  //- Construct top-level dictionary from Istream,
440  //- reading entries until EOF, optionally keeping the header
441  dictionary(Istream& is, bool keepHeader);
442 
443  //- Copy construct given the parent dictionary
444  dictionary(const dictionary& parentDict, const dictionary& dict);
445 
446  //- Copy construct top-level dictionary
447  dictionary(const dictionary& dict);
448 
449  //- Construct top-level dictionary as copy from pointer to dictionary.
450  // A null pointer is treated like an empty dictionary.
451  explicit dictionary(const dictionary* dict);
452 
453  //- Move construct for given parent dictionary
454  dictionary(const dictionary& parentDict, dictionary&& dict);
455 
456  //- Move construct top-level dictionary
458 
459  //- Construct and return clone
460  autoPtr<dictionary> clone() const;
461 
462  //- Construct top-level dictionary on freestore from Istream
463  static autoPtr<dictionary> New(Istream& is);
464 
465 
466  //- Destructor
467  virtual ~dictionary();
468 
469 
470  // Member Functions
471 
472  // Access
473 
474  //- The dictionary name
475  inline const fileName& name() const noexcept;
476 
477  //- The dictionary name for modification (use with caution).
478  inline fileName& name() noexcept;
479 
480  //- The local dictionary name (final part of scoped name)
481  inline word dictName() const;
482 
483  //- The dictionary name relative to the case.
484  // Uses argList::envRelativePath to obtain FOAM_CASE
485  //
486  // \param caseTag replace globalPath with <case> for later
487  // use with expand(), or prefix <case> if the file name was
488  // not an absolute location
489  fileName relativeName(const bool caseTag = false) const;
490 
491  //- The dictionary is actually dictionary::null (root dictionary)
492  inline bool isNullDict() const noexcept;
493 
494  //- Return the parent dictionary
495  inline const dictionary& parent() const noexcept;
496 
497  //- Return the top of the tree
498  const dictionary& topDict() const;
499 
500  //- Return line number of first token in dictionary
501  label startLineNumber() const;
502 
503  //- Return line number of last token in dictionary
504  label endLineNumber() const;
505 
506  //- Return the SHA1 digest of the dictionary contents
507  SHA1Digest digest() const;
508 
509  //- Return the dictionary as a list of tokens
510  tokenList tokens() const;
511 
512 
513  // Searching
514 
515  //- Find an entry (const access) with the given keyword.
516  //
517  // \param keyword the keyword to search for
518  // \param matchOpt search mode (default: non-recursive with patterns)
519  //
520  // \return pointer to the entry found or a nullptr.
521  inline const entry* findEntry
522  (
523  const word& keyword,
524  enum keyType::option matchOpt = keyType::REGEX
525  ) const;
526 
527  //- Find an entry (non-const access) with the given keyword.
528  //
529  // \param keyword the keyword to search for
530  // \param matchOpt search mode (default: non-recursive with patterns)
531  //
532  // \return pointer to the entry found or a nullptr.
533  inline entry* findEntry
534  (
535  const word& keyword,
536  enum keyType::option matchOpt = keyType::REGEX
537  );
538 
539  //- Find an entry (const access) with the given keyword.
540  //
541  // \param keyword the keyword to search for
542  // \param matchOpt search mode (default: non-recursive with patterns)
543  //
544  // \return True if entry was found
545  inline bool found
546  (
547  const word& keyword,
548  enum keyType::option matchOpt = keyType::REGEX
549  ) const;
550 
551  //- Search for a scoped entry (const access) with the given keyword.
552  // Allows scoping using '.'.
553  // Special handling for an absolute anchor (^) at start of the keyword
554  // and for '..' to ascend into the parent dictionaries.
555  //
556  // \param keyword the keyword to search for
557  // \param matchOpt search mode (default: non-recursive with patterns)
558  //
559  // \return pointer to the entry found or a nullptr.
560  inline const entry* findScoped
561  (
562  const word& keyword,
563  enum keyType::option matchOpt = keyType::REGEX
564  ) const;
565 
566  //- Find and return a sub-dictionary pointer if present
567  //- (and it is a dictionary) otherwise return nullptr.
568  //
569  // \param keyword the keyword to search for
570  // \param matchOpt search mode (default: non-recursive with patterns)
571  //
572  // \return pointer to sub-dictionary found or a nullptr.
573  inline const dictionary* findDict
574  (
575  const word& keyword,
576  enum keyType::option matchOpt = keyType::REGEX
577  ) const;
578 
579  //- Find and return a sub-dictionary pointer if present
580  //- (and it is a dictionary) otherwise return nullptr.
581  //
582  // \param keyword the keyword to search for
583  // \param matchOpt search mode (default: non-recursive with patterns)
584  //
585  // \return pointer to sub-dictionary found or a nullptr.
586  inline dictionary* findDict
587  (
588  const word& keyword,
589  enum keyType::option matchOpt = keyType::REGEX
590  );
591 
592  //- Find and return an entry stream if present
593  //- (and it is a stream) otherwise return nullptr.
594  //
595  // \param keyword the keyword to search for
596  // \param matchOpt search mode (default: non-recursive with patterns)
597  //
598  // \return pointer to ITstream or a nullptr
599  inline ITstream* findStream
600  (
601  const word& keyword,
602  enum keyType::option matchOpt = keyType::REGEX
603  ) const;
604 
605 
606  // Lookup
607 
608  //- Search for an entry (const access) with the given keyword.
609  //
610  // \param keyword the keyword to search for
611  // \param matchOpt search mode
612  //
613  // \return return an entry if present, otherwise FatalIOError.
614  const entry& lookupEntry
615  (
616  const word& keyword,
617  enum keyType::option matchOpt
618  ) const;
619 
620  //- Find and return an entry data stream.
621  //- FatalIOError if not found, or not a stream
622  //
623  // \param keyword the keyword to search for
624  // \param matchOpt search mode (default: non-recursive with patterns)
625  //
626  // \return entry stream or FatalIOError
628  (
629  const word& keyword,
630  enum keyType::option matchOpt = keyType::REGEX
631  ) const;
632 
633  //- Find and return a T.
634  //- FatalIOError if not found, or if the number of tokens is incorrect.
635  //
636  // \param keyword the keyword to search for
637  // \param matchOpt search mode (default: non-recursive with patterns)
638  template<class T>
639  T get
640  (
641  const word& keyword,
642  enum keyType::option matchOpt = keyType::REGEX
643  ) const;
644 
645  //- Find and return a T, or return the given default value.
646  //- FatalIOError if it is found and the number of tokens is incorrect.
647  //
648  // \param keyword the keyword to search for
649  // \param deflt the default value to use
650  // \param matchOpt search mode (default: non-recursive with patterns)
651  template<class T>
653  (
654  const word& keyword,
655  const T& deflt,
656  enum keyType::option matchOpt = keyType::REGEX
657  ) const;
658 
659  //- Find and return a T, or return the given default value
660  //- and add it to dictionary.
661  //- FatalIOError if it is found and the number of tokens is incorrect.
662  //
663  // \param keyword the keyword to search for
664  // \param deflt the default value to use
665  // \param matchOpt search mode (default: non-recursive with patterns)
666  template<class T>
667  T getOrAdd
668  (
669  const word& keyword,
670  const T& deflt,
671  enum keyType::option matchOpt = keyType::REGEX
672  );
673 
674  //- Find entry and assign to T val.
675  //- FatalIOError if it is found and the number of tokens is incorrect,
676  //- or it is mandatory and not found.
677  //
678  // \param keyword the keyword to search for
679  // \param val the value to read into
680  // \param matchOpt search mode (default: non-recursive with patterns)
681  // \param readOpt the entry is required/optional (default: MUST_READ)
682  //
683  // \return true if the entry was read
684  template<class T>
685  bool readEntry
686  (
687  const word& keyword,
688  T& val,
689  enum keyType::option matchOpt = keyType::REGEX,
690  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
691  ) const;
692 
693  //- Find an entry if present, and assign to T val.
694  //- FatalIOError if it is found and the number of tokens is incorrect.
695  //
696  // \param keyword the keyword to search for
697  // \param val the value to read into
698  // \param matchOpt search mode (default: non-recursive with patterns)
699  //
700  // \return true if the entry was read
701  template<class T>
702  bool readIfPresent
703  (
704  const word& keyword,
705  T& val,
706  enum keyType::option matchOpt = keyType::REGEX
707  ) const;
708 
709  //- Find and return a T with additional checking
710  //- FatalIOError if not found, or if the number of tokens is incorrect.
711  //
712  // \param keyword the keyword to search for
713  // \param pred the value check predicate
714  // \param matchOpt search mode (default: non-recursive with patterns)
715  template<class T, class Predicate>
716  T getCheck
717  (
718  const word& keyword,
719  const Predicate& pred,
720  enum keyType::option matchOpt = keyType::REGEX
721  ) const;
722 
723  //- Find and return a T, or return the given default value.
724  //- FatalIOError if it is found and the number of tokens is incorrect.
725  //
726  // \param keyword the keyword to search for
727  // \param deflt the default value to use
728  // \param pred the value check predicate
729  // \param matchOpt search mode (default: non-recursive with patterns)
730  template<class T, class Predicate>
732  (
733  const word& keyword,
734  const T& deflt,
735  const Predicate& pred,
736  enum keyType::option matchOpt = keyType::REGEX
737  ) const;
738 
739  //- Find and return a T, or return the given default value
740  //- and add it to dictionary.
741  //- FatalIOError if it is found and the number of tokens is incorrect.
742  //
743  // \param keyword the keyword to search for
744  // \param deflt the default value to use
745  // \param pred the value check predicate
746  // \param matchOpt search mode (default: non-recursive with patterns)
747  template<class T, class Predicate>
749  (
750  const word& keyword,
751  const T& deflt,
752  const Predicate& pred,
753  enum keyType::option matchOpt = keyType::REGEX
754  );
755 
756  //- Find entry and assign to T val.
757  //- FatalIOError if it is found and the number of tokens is incorrect,
758  //- or it is mandatory and not found.
759  //
760  // \param keyword the keyword to search for
761  // \param val the value to read into
762  // \param pred the value check predicate
763  // \param matchOpt search mode (default: non-recursive with patterns)
764  // \param readOpt the entry is required/optional (default: MUST_READ)
765  //
766  // \return true if the entry was read
767  template<class T, class Predicate>
768  bool readCheck
769  (
770  const word& keyword,
771  T& val,
772  const Predicate& pred,
773  enum keyType::option matchOpt = keyType::REGEX,
774  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
775  ) const;
776 
777  //- Find an entry if present, and assign to T val.
778  //- FatalIOError if it is found and the number of tokens is incorrect.
779  //
780  // \param keyword the keyword to search for
781  // \param val the value to read into
782  // \param pred the value check predicate
783  // \param matchOpt search mode (default: non-recursive with patterns)
784  //
785  // \return true if the entry read
786  template<class T, class Predicate>
787  bool readCheckIfPresent
788  (
789  const word& keyword,
790  T& val,
791  const Predicate& pred,
792  enum keyType::option matchOpt = keyType::REGEX
793  ) const;
794 
795  //- Find and return a sub-dictionary.
796  // Fatal if the entry does not exist or is not a sub-dictionary.
797  //
798  // \param keyword the keyword to search for
799  // \param matchOpt search mode (default: non-recursive with patterns)
800  const dictionary& subDict
801  (
802  const word& keyword,
803  enum keyType::option matchOpt = keyType::REGEX
804  ) const;
805 
806  //- Find and return a sub-dictionary for manipulation.
807  // Fatal if the entry does not exist or is not a sub-dictionary.
808  //
809  // \param keyword the keyword to search for
810  // \param matchOpt search mode (default: non-recursive with patterns)
812  (
813  const word& keyword,
814  enum keyType::option matchOpt = keyType::REGEX
815  );
816 
817  //- Find and return a sub-dictionary for manipulation.
818  // Fatal if the entry exist and is not a sub-dictionary.
819  //
820  // \param keyword the keyword to search for
821  // \param matchOpt search mode (default: non-recursive with patterns)
823  (
824  const word& keyword,
825  enum keyType::option matchOpt = keyType::REGEX
826  );
827 
828  //- Find and return a sub-dictionary as a copy, otherwise return
829  //- an empty dictionary.
830  // Warn if the entry exists but is not a sub-dictionary.
831  //
832  // \param keyword the keyword to search for
833  // \param matchOpt search mode (default: non-recursive with patterns)
834  // \param mandatory the keyword is mandatory (default: false)
836  (
837  const word& keyword,
838  enum keyType::option matchOpt = keyType::REGEX,
839  const bool mandatory = false
840  ) const;
841 
842  //- Find and return a sub-dictionary, otherwise return this dictionary.
843  // Warn if the entry exists but is not a sub-dictionary.
844  //
845  // \param keyword the keyword to search for
846  // \param matchOpt search mode (default: non-recursive with patterns)
848  (
849  const word& keyword,
850  enum keyType::option matchOpt = keyType::REGEX
851  ) const;
852 
853  //- Return the table of contents
854  wordList toc() const;
855 
856  //- Return the sorted table of contents
857  wordList sortedToc() const;
858 
859  //- Return table of contents sorted using the specified comparator
860  template<class Compare>
861  wordList sortedToc(const Compare& comp) const;
862 
863  //- Return the list of available keys or patterns
864  List<keyType> keys(bool patterns = false) const;
865 
866 
867  // Editing
868 
869  //- Substitute the given keyword (which is prefixed by '$')
870  // with the corresponding sub-dictionary entries
871  bool substituteKeyword
872  (
873  const word& keyword,
874  bool mergeEntry = false
875  );
876 
877  //- Substitute the given scoped keyword (which is prefixed by '$')
878  // with the corresponding sub-dictionary entries
880  (
881  const word& keyword,
882  bool mergeEntry = false
883  );
884 
885  //- Add a new entry.
886  //
887  // \param entryPtr the entry to add
888  // \param mergeEntry dictionaries are interwoven and primitive
889  // entries are overwritten (default: false)
890  //
891  // \return pointer to inserted entry, or place of merging
892  // or nullptr on failure
893  entry* add(entry* entryPtr, bool mergeEntry=false);
894 
895  //- Add an entry.
896  //
897  // \param e the entry to add
898  // \param mergeEntry dictionaries are interwoven and primitive
899  // entries are overwritten (default: false)
900  // \return pointer to inserted entry, or place of merging
901  // or nullptr on failure
902  entry* add(const entry& e, bool mergeEntry=false);
903 
904  //- Add a word entry.
905  // \param overwrite force overwrite of an existing entry.
906  // \return pointer to inserted entry or nullptr on failure
907  entry* add(const keyType& k, const word& v, bool overwrite=false);
908 
909  //- Add a string entry.
910  // \param overwrite force overwrite of an existing entry.
911  // \return pointer to inserted entry or nullptr on failure
912  entry* add(const keyType& k, const string& v, bool overwrite=false);
913 
914  //- Add a label entry.
915  // \param overwrite force overwrite of an existing entry.
916  // \return pointer to inserted entry or nullptr on failure
917  entry* add(const keyType& k, const label v, bool overwrite=false);
918 
919  //- Add a scalar entry.
920  // \param overwrite force overwrite of an existing entry.
921  // \return pointer to inserted entry or nullptr on failure
922  entry* add(const keyType& k, const scalar v, bool overwrite=false);
923 
924  //- Add a dictionary entry.
925  // \param mergeEntry merge into an existing sub-dictionary
926  // \return pointer to inserted entry, or place of merging
927  // or nullptr on failure
928  entry* add
929  (
930  const keyType& k,
931  const dictionary& d,
932  bool mergeEntry = false
933  );
934 
935  //- Add a T entry
936  // \param overwrite force overwrite of existing entry
937  // \return pointer to inserted entry or nullptr on failure
938  template<class T>
939  entry* add(const keyType& k, const T& v, bool overwrite=false);
940 
941  //- Assign a new entry, overwriting any existing entry.
942  //
943  // \return pointer to inserted entry or nullptr on failure
944  entry* set(entry* entryPtr);
945 
946  //- Assign a new entry, overwriting any existing entry.
947  //
948  // \return pointer to inserted entry or nullptr on failure
949  entry* set(const entry& e);
950 
951  //- Assign a dictionary entry, overwriting any existing entry.
952  //
953  // \return pointer to inserted entry or nullptr on failure
954  entry* set(const keyType& k, const dictionary& v);
955 
956  //- Assign a T entry, overwriting any existing entry.
957  // \return pointer to inserted entry or nullptr on failure
958  template<class T>
959  entry* set(const keyType& k, const T& v);
960 
961  //- Remove an entry specified by keyword
962  bool remove(const word& keyword);
963 
964  //- Change the keyword for an entry,
965  // \param overwrite force overwrite of an existing entry.
966  bool changeKeyword
967  (
968  const keyType& oldKeyword,
969  const keyType& newKeyword,
970  bool overwrite=false
971  );
972 
973  //- Merge entries from the given dictionary.
974  // Also merge sub-dictionaries as required.
975  bool merge(const dictionary& dict);
976 
977  //- Clear the dictionary
978  void clear();
979 
980  //- Transfer the contents of the argument and annul the argument.
981  void transfer(dictionary& dict);
982 
983 
984  // Read
985 
986  //- Check after reading if the input token stream has unconsumed
987  //- tokens remaining or if there were no tokens in the first place.
988  // Emits FatalIOError
989  void checkITstream(const ITstream& is, const word& keyword) const;
990 
991  //- Read dictionary from Istream (discards the header).
992  //- Reads entries until EOF or when the first token is a
993  //- '{' character, it will stop reading at the matching '}' character.
994  bool read(Istream& is);
995 
996  //- Read dictionary from Istream (optionally keeping the header)
997  //- Reads entries until EOF or when the first token is a
998  //- '{' character, it will stop reading at the matching '}' character.
999  bool read(Istream& is, bool keepHeader);
1000 
1001 
1002  // Write
1003 
1004  //- Write sub-dictionary with its dictName as its header
1005  void writeEntry(Ostream& os) const;
1006 
1007  //- Write sub-dictionary with the keyword as its header
1008  void writeEntry(const keyType& keyword, Ostream& os) const;
1009 
1010  //- Write dictionary entries.
1011  // \param extraNewLine adds additional newline between entries
1012  // for "top-level" dictionaries
1013  void writeEntries(Ostream& os, const bool extraNewLine=false) const;
1014 
1015  //- Write dictionary, normally with sub-dictionary formatting
1016  void write(Ostream& os, const bool subDict=true) const;
1017 
1018 
1019  // Searching
1020 
1021  //- Search dictionary for given keyword
1022  //
1023  // \param keyword the keyword to search for
1024  // \param matchOpt search mode (default: non-recursive with patterns)
1026  (
1027  const word& keyword,
1028  enum keyType::option matchOpt = keyType::REGEX
1029  ) const;
1030 
1031  //- Search dictionary for given keyword
1032  //
1033  // \param keyword the keyword to search for
1034  // \param matchOpt search mode (default: non-recursive with patterns)
1036  (
1037  const word& keyword,
1038  enum keyType::option matchOpt = keyType::REGEX
1039  ) const;
1040 
1041  //- Search dictionary for given keyword
1042  //
1043  // \param keyword the keyword to search for
1044  // \param matchOpt search mode (default: non-recursive with patterns)
1046  (
1047  const word& keyword,
1048  enum keyType::option matchOpt = keyType::REGEX
1049  );
1050 
1051  //- Search using scoping.
1052  // There are two types of scoping available:
1053  // -# dot-scoping, where a '.' is used to delineate the scope
1054  // -# slash-scoping, where a '/' is used to delineate the scope
1055  //
1056  // For dot-scoping, a leading '^' traverses to the top-level
1057  // dictionary, leading dots mean use the parent dictionary and an
1058  // intermediate dot separates a sub-dictionary or sub-entry.
1059  // However, since the use of dots is ambiguous ("a.b.c" could be
1060  // an entry itself or represent a "bc" entry from dictionary "a" etc),
1061  // the heuristic backtracks and attempts successively longer
1062  // top-level entries until a suitable match is found.
1063  //
1064  // For slash-scoping, semantics similar to directory structures are
1065  // used. A leading '/' traverses to the top-level dictionary,
1066  // a single leading or intermediate '.' references the current
1067  // dictionary level. A '..' pair references the parent dictionary.
1068  // Any doubled slashes are silently ignored.
1069  // Since a slash is not a valid keyword character, there is no
1070  // ambiguity between separator and content.
1071  //
1072  // \param keyword the keyword to search for
1073  // \param matchOpt search mode
1075  (
1076  const word& keyword,
1077  enum keyType::option matchOpt
1078  ) const;
1079 
1080  //- Search using dot or slash scoping.
1081  //
1082  // \param keyword the keyword to search for
1083  // \param matchOpt search mode
1085  (
1086  const word& keyword,
1087  enum keyType::option matchOpt
1088  ) const;
1089 
1090  //- Search using dot or slash scoping.
1091  //
1092  // \param keyword the keyword to search for
1093  // \param matchOpt search mode
1095  (
1096  const word& keyword,
1097  enum keyType::option matchOpt
1098  );
1099 
1100  //- Locate a sub-dictionary using slash-scoping
1101  // \return nullptr if the dictionary path does not exist
1102  const dictionary* cfindScopedDict(const fileName& dictPath) const;
1103 
1104  //- Locate a sub-dictionary using slash-scoping
1105  // \return nullptr if the dictionary path does not exist
1106  const dictionary* findScopedDict(const fileName& dictPath) const;
1107 
1108  //- Locate a sub-dictionary using slash-scoping
1109  // \return nullptr if the dictionary path does not exist
1110  dictionary* findScopedDict(const fileName& dictPath);
1111 
1112  //- Locate existing or create sub-dictionary using slash-scoping
1113  // \return nullptr if the dictionary path could not be created
1114  dictionary* makeScopedDict(const fileName& dictPath);
1115 
1116 
1117  // Compatibility helpers
1118 
1119  //- Search dictionary for given keyword and any compatibility names
1120  //
1121  // \param keyword the keyword to search for
1122  // \param compat list of old compatibility keywords and the last
1123  // OpenFOAM version for which they were used.
1124  // Old version 1600=OpenFOAM-v3.0, 240=OpenFOAM-2.4.x,
1125  // 170=OpenFOAM-1.7.x,...
1126  // \param matchOpt search mode (default: non-recursive with patterns)
1128  (
1129  const word& keyword,
1130  std::initializer_list<std::pair<const char*,int>> compat,
1131  enum keyType::option matchOpt = keyType::REGEX
1132  ) const;
1133 
1134  //- Find and return an entry pointer if present, or return a nullptr,
1135  //- using any compatibility names if needed.
1136  //
1137  // \param keyword the keyword to search for
1138  // \param compat list of old compatibility keywords and the last
1139  // OpenFOAM version for which they were used.
1140  // \param matchOpt search mode
1141  const entry* findCompat
1142  (
1143  const word& keyword,
1144  std::initializer_list<std::pair<const char*,int>> compat,
1145  enum keyType::option matchOpt
1146  ) const;
1147 
1148  //- Search dictionary for given keyword and any compatibility names
1149  //
1150  // \param keyword the keyword to search for
1151  // \param compat list of old compatibility keywords and the last
1152  // OpenFOAM version for which they were used.
1153  // \param matchOpt search mode (default: non-recursive with patterns)
1154  bool foundCompat
1155  (
1156  const word& keyword,
1157  std::initializer_list<std::pair<const char*,int>> compat,
1158  enum keyType::option matchOpt = keyType::REGEX
1159  ) const;
1160 
1161  //- Find and return an entry if present, otherwise FatalIOError,
1162  //- using any compatibility names if needed.
1163  //
1164  // \param keyword the keyword to search for
1165  // \param compat list of old compatibility keywords and the last
1166  // OpenFOAM version for which they were used.
1167  // \param matchOpt search mode
1168  const entry& lookupEntryCompat
1169  (
1170  const word& keyword,
1171  std::initializer_list<std::pair<const char*,int>> compat,
1172  enum keyType::option matchOpt
1173  ) const;
1174 
1175  //- Find and return an entry data stream,
1176  //- using any compatibility names if needed.
1177  //
1178  // \param keyword the keyword to search for
1179  // \param compat list of old compatibility keywords and the last
1180  // OpenFOAM version for which they were used.
1181  // \param matchOpt search mode (default: non-recursive with patterns)
1183  (
1184  const word& keyword,
1185  std::initializer_list<std::pair<const char*,int>> compat,
1186  enum keyType::option matchOpt = keyType::REGEX
1187  ) const;
1188 
1189  //- Find and return a T
1190  //- using any compatibility names if needed.
1191  //- FatalIOError if not found, or if there are excess tokens.
1192  //
1193  // \param keyword the keyword to search for
1194  // \param compat list of old compatibility keywords and the last
1195  // OpenFOAM version for which they were used.
1196  // \param matchOpt search mode (default: non-recursive with patterns)
1197  template<class T>
1198  T getCompat
1199  (
1200  const word& keyword,
1201  std::initializer_list<std::pair<const char*,int>> compat,
1202  enum keyType::option matchOpt = keyType::REGEX
1203  ) const;
1204 
1205  //- Find and return a T, or return the given default value
1206  //- using any compatibility names if needed.
1207  //
1208  // \param keyword the keyword to search for
1209  // \param compat list of old compatibility keywords and the last
1210  // OpenFOAM version for which they were used.
1211  // \param deflt the default value to use
1212  // \param matchOpt search mode (default: non-recursive with patterns)
1213  template<class T>
1215  (
1216  const word& keyword,
1217  std::initializer_list<std::pair<const char*,int>> compat,
1218  const T& deflt,
1219  enum keyType::option matchOpt = keyType::REGEX
1220  ) const;
1221 
1222  //- Find entry and assign to T val
1223  //- using any compatibility names if needed.
1224  //- FatalIOError if there are excess tokens.
1225  //
1226  // \param keyword the keyword to search for
1227  // \param compat list of old compatibility keywords and the last
1228  // OpenFOAM version for which they were used.
1229  // \param val the value to read
1230  // \param matchOpt search mode (default: non-recursive with patterns)
1231  // \param readOpt the entry is required/optional (default: MUST_READ)
1232  //
1233  // \return true if the entry was read
1234  template<class T>
1235  bool readCompat
1236  (
1237  const word& keyword,
1238  std::initializer_list<std::pair<const char*,int>> compat,
1239  T& val,
1240  enum keyType::option matchOpt = keyType::REGEX,
1241  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
1242  ) const;
1243 
1244  //- Find an entry if present, and assign to T val
1245  //- using any compatibility names if needed.
1246  //- FatalIOError if it is found and there are excess tokens.
1247  //
1248  // \param keyword the keyword to search for
1249  // \param compat list of old compatibility keywords and the last
1250  // OpenFOAM version for which they were used.
1251  // \param val the value to read
1252  // \param matchOpt search mode (default: non-recursive with patterns)
1253  //
1254  // \return true if the entry was found.
1255  template<class T>
1256  bool readIfPresentCompat
1257  (
1258  const word& keyword,
1259  std::initializer_list<std::pair<const char*,int>> compat,
1260  T& val,
1261  enum keyType::option matchOpt = keyType::REGEX
1262  ) const;
1263 
1264 
1265  // Member Operators
1266 
1267  //- Copy assignment
1268  void operator=(const dictionary& rhs);
1269 
1270  //- Include entries from the given dictionary.
1271  // Warn, but do not overwrite existing entries.
1272  void operator+=(const dictionary& rhs);
1273 
1274  //- Conditionally include entries from the given dictionary.
1275  // Do not overwrite existing entries.
1276  void operator|=(const dictionary& rhs);
1277 
1278  //- Unconditionally include entries from the given dictionary.
1279  // Overwrite existing entries.
1280  void operator<<=(const dictionary& rhs);
1281 
1282 
1283  // IOstream operators
1284 
1285  //- Read dictionary from Istream
1286  friend Istream& operator>>(Istream& is, dictionary& dict);
1287 
1288  //- Write dictionary to Ostream
1289  friend Ostream& operator<<(Ostream& os, const dictionary& dict);
1290 
1291 
1292  // Shortcuts - when a templated classes also inherits from a dictionary
1293 
1294  #undef defineDictionaryGetter
1295  #define defineDictionaryGetter(Func, Type) \
1296  \
1297  Type Func \
1298  ( \
1299  const word& keyword, \
1300  enum keyType::option matchOpt = keyType::REGEX \
1301  ) const \
1302  { \
1303  return get<Type>(keyword, matchOpt); \
1304  }
1305 
1312 
1313  #undef defineDictionaryGetter
1314 
1315 
1316  // Housekeeping
1317 
1318  //- Check for existence of a sub-dictionary.
1319  //- Generally prefer findDict() for more flexibility.
1320  FOAM_DEPRECATED_STRICT(2024-05, "findDict()")
1321  bool isDict
1322  (
1323  const word& keyword,
1324  enum keyType::option matchOpt = keyType::REGEX
1325  ) const
1326  {
1327  return static_cast<bool>(findDict(keyword, matchOpt));
1328  }
1329 
1330  //- Same as getOrDefault()
1331  template<class T>
1332  FOAM_DEPRECATED_STRICT(2019-06, "getOrDefault()")
1334  (
1335  const word& keyword,
1336  const T& deflt,
1337  enum keyType::option matchOpt = keyType::REGEX
1338  ) const
1339  {
1340  return getOrDefault<T>(keyword, deflt, matchOpt);
1341  }
1342 
1343  //- Same as getOrAdd()
1344  template<class T>
1345  FOAM_DEPRECATED_STRICT(2019-06, "getOrAdd()")
1347  (
1348  const word& keyword,
1349  const T& deflt,
1350  enum keyType::option matchOpt = keyType::REGEX
1351  )
1352  {
1353  return getOrAdd<T>(keyword, deflt, matchOpt);
1354  }
1355 
1356  //- Deprecated(2018-07) - use lookup() method
1357  // \deprecated(2018-07) - use lookup() method
1358  FOAM_DEPRECATED_FOR(2018-07, "lookup() method")
1359  ITstream& operator[](const word& keyword) const
1360  {
1361  return lookup(keyword);
1362  }
1363 
1364  //- Deprecated(2018-10)
1365  // \deprecated(2018-10) - use keyType::option version
1366  FOAM_DEPRECATED_FOR(2018-10, "found(keyType::option)")
1367  bool found
1368  (
1369  const word& keyword,
1370  bool recursive,
1371  bool patternMatch = true
1372  ) const
1373  {
1374  return found(keyword, matchOpt(recursive, patternMatch));
1375  }
1376 
1377  //- Deprecated(2018-10)
1378  // \deprecated(2018-10) - use findEntry() method
1379  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1381  (
1382  const word& keyword,
1383  bool recursive,
1384  bool patternMatch
1385  )
1386  {
1387  return findEntry(keyword, matchOpt(recursive, patternMatch));
1388  }
1389 
1390  //- Deprecated(2018-10)
1391  // \deprecated(2018-10) - use findEntry() method
1392  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1393  const entry* lookupEntryPtr
1394  (
1395  const word& keyword,
1396  bool recursive,
1397  bool patternMatch
1398  ) const
1399  {
1400  return findEntry(keyword, matchOpt(recursive, patternMatch));
1401  }
1402 
1403  //- Deprecated(2018-10)
1404  // \deprecated(2018-10) - use findScoped() method
1405  FOAM_DEPRECATED_FOR(2018-10, "findScoped(keyType::option)")
1407  (
1408  const word& keyword,
1409  bool recursive,
1410  bool patternMatch
1411  ) const
1412  {
1413  return findScoped(keyword, matchOpt(recursive, patternMatch));
1414  }
1415 
1416  //- Deprecated(2018-10)
1417  // Find and return a sub-dictionary pointer if present
1418  // (and a sub-dictionary) otherwise return nullptr.
1419  //
1420  // Search type: non-recursive with patterns.
1421  // \deprecated(2018-10) - use findDict() method
1422  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1423  const dictionary* subDictPtr(const word& keyword) const
1424  {
1425  return findDict(keyword, keyType::REGEX);
1426  }
1427 
1428  //- Deprecated(2018-10)
1429  //- Find and return a sub-dictionary pointer if present
1430  // (and a sub-dictionary) otherwise return nullptr.
1431  //
1432  // Search type: non-recursive with patterns.
1433  // \deprecated(2018-10) - use findDict() method
1434  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1435  dictionary* subDictPtr(const word& keyword)
1436  {
1437  return findDict(keyword, keyType::REGEX);
1438  }
1439 
1440  //- Deprecated(2018-10)
1441  // \deprecated(2018-10) - use keyType::option version
1442  FOAM_DEPRECATED_FOR(2018-10, "lookupEntry(keyType::option)")
1443  const entry& lookupEntry
1444  (
1445  const word& keyword,
1446  bool recursive,
1447  bool patternMatch
1448  ) const
1449  {
1450  return lookupEntry(keyword, matchOpt(recursive, patternMatch));
1451  }
1452 
1453  //- Deprecated(2018-10)
1454  // \deprecated(2018-10) - use keyType::option version
1455  FOAM_DEPRECATED_FOR(2018-10, "lookup(keyType::option)")
1456  ITstream& lookup
1457  (
1458  const word& keyword,
1459  bool recursive,
1460  bool patternMatch = true
1461  ) const
1462  {
1463  return lookup(keyword, matchOpt(recursive, patternMatch));
1464  }
1465 
1466  //- Deprecated(2018-10)
1467  // \deprecated(2018-10) - use keyType::option version
1468  template<class T>
1469  FOAM_DEPRECATED_FOR(2018-10, "getOrDefault(keyType::option)")
1471  (
1472  const word& keyword,
1473  const T& deflt,
1474  bool recursive,
1475  bool patternMatch = true
1476  ) const
1477  {
1478  return getOrDefault(keyword, matchOpt(recursive, patternMatch));
1479  }
1480 
1481  //- Deprecated(2018-10)
1482  // \deprecated(2018-10) - use keyType::option version
1483  template<class T>
1484  FOAM_DEPRECATED_FOR(2018-10, "getOrAdd(keyType::option)")
1486  (
1487  const word& keyword,
1488  const T& deflt,
1489  bool recursive,
1490  bool patternMatch = true
1491  )
1492  {
1493  return getOrAdd(keyword, deflt, matchOpt(recursive, patternMatch));
1494  }
1495 
1496  //- Deprecated(2018-10)
1497  // \deprecated(2018-10) - use keyType::option version
1498  template<class T>
1499  FOAM_DEPRECATED_FOR(2018-10, "readIfPresent(keyType::option)")
1500  bool readIfPresent
1501  (
1502  const word& keyword,
1503  T& val,
1504  bool recursive,
1505  bool patternMatch = true
1506  ) const
1507  {
1508  return
1510  (keyword, val, matchOpt(recursive, patternMatch));
1511  }
1512 
1513 
1514  // More compatibility
1515 
1516  //- Deprecated(2018-10) find and return a T.
1517  // \deprecated(2018-10) - use get() method
1518  template<class T>
1519  FOAM_DEPRECATED_FOR(2018-10, "get() method")
1520  T lookupType
1521  (
1522  const word& keyword,
1523  bool recursive = false,
1524  bool patternMatch = true
1525  ) const
1526  {
1527  return get<T>(keyword, matchOpt(recursive, patternMatch));
1528  }
1529 
1530  #ifdef COMPAT_OPENFOAM_ORG
1531  // Only available if compiled with COMPAT_OPENFOAM_ORG
1533  template<class T>
1534  FOAM_DEPRECATED_FOR(2019-11, "get() method - openfoam.org compat")
1535  T lookup
1536  (
1537  const word& keyword,
1538  bool recursive = false,
1539  bool patternMatch = true
1540  ) const
1541  {
1542  return get<T>(keyword, matchOpt(recursive, patternMatch));
1543  }
1544  #endif
1545 };
1546 
1547 
1548 // Global Operators
1549 
1550 //- Combine dictionaries.
1551 // Starting from the entries in dict1 and then including those from dict2.
1552 // Warn, but do not overwrite the entries from dict1.
1553 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
1554 
1555 //- Combine dictionaries.
1556 // Starting from the entries in dict1 and then including those from dict2.
1557 // Do not overwrite the entries from dict1.
1558 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
1559 
1560 
1561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1562 
1563 } // End namespace Foam
1564 
1565 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1566 
1567 #include "dictionaryI.H"
1568 
1569 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1570 
1571 #ifdef NoRepository
1572  #include "dictionaryTemplates.C"
1573 #endif
1574 
1575 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1576 
1577 #endif
1578 
1579 // ************************************************************************* //
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
Definition: dictionaryIO.C:157
Template class for intrusive linked lists.
Definition: ILList.H:45
bool readCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val using any compatibility names if needed. FatalIOError if there are exc...
dict_reference dict() const
Return the found entry as a dictionary. Error if not found, or not a dictionary.
Definition: dictionary.H:293
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
string getString(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< string >(const word&, keyType::option)
Definition: dictionary.H:1679
ClassName("dictionary")
A class for handling keywords in dictionaries.
Definition: keyType.H:66
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
Definition: dictionary.C:367
dictionary dict
value_type & reference
A reference to a const/non-const entry.
Definition: dictionary.H:184
entry * lookupEntryPtr(const word &keyword, bool recursive, bool patternMatch)
Deprecated(2018-10)
Definition: dictionary.H:1766
static int reportOptional() noexcept
Return the state of reporting optional (default) entries.
Definition: dictionaryI.H:25
A class for handling file names.
Definition: fileName.H:72
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:209
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:234
bool readIfPresentCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val using any compatibility names if needed. FatalIOError if it is found and there are excess tokens.
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:220
void transfer(dictionary &dict)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:853
pointer eptr_
The entry or nullptr.
Definition: dictionary.H:197
bool found() const noexcept
True if entry was found.
Definition: dictionary.H:240
bool read(Istream &is)
Read dictionary from Istream (discards the header). Reads entries until EOF or when the first token i...
Definition: dictionaryIO.C:134
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool readCheckIfPresent(const word &keyword, T &val, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
reference operator*() const
A reference to the entry (Error if not found)
Definition: dictionary.H:317
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
dict_pointer dictPtr() const noexcept
Pointer to the found entry as a dictionary, nullptr otherwise.
Definition: dictionary.H:276
Template class for non-intrusive linked lists.
Definition: LList.H:46
ITstream * findStream(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry stream if present (and it is a stream) otherwise return nullptr.
Definition: dictionaryI.H:144
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T with additional checking FatalIOError if not found, or if the number of tokens is...
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by &#39;$&#39;)
Definition: dictionary.C:409
T getCheckOrAdd(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX)
Find and return a T, or return the given default value and add it to dictionary. FatalIOError if it i...
The SHA1 message digest.
Definition: SHA1Digest.H:56
ITstream & stream() const
Return the found entry as a ITstream. Error if not found, or not a stream.
Definition: dictionary.H:299
std::conditional< Const, const entry, entry >::type value_type
The const/non-const type for entries.
Definition: dictionary.H:164
T lookupOrAddDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Same as getOrAdd()
Definition: dictionary.H:1723
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
label k
Boltzmann constant.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const entry & lookupEntry(const word &keyword, enum keyType::option matchOpt) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:347
Lookup type of boundary radiation properties.
Definition: lookup.H:57
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Same as getOrDefault()
Definition: dictionary.H:1708
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:41
bool readCheck(const word &keyword, T &val, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
bitSet operator|(const bitSet &a, const bitSet &b)
Bitwise-OR of two bitsets.
Definition: bitSetI.H:688
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:165
label getLabel(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< label >(const word&, keyType::option)
Definition: dictionary.H:1677
constexpr Searcher() noexcept
Default construct.
Definition: dictionary.H:223
Recursive search (eg, in dictionary)
Definition: keyType.H:86
wordList toc() const
Return the table of contents.
Definition: dictionary.C:587
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
Definition: dictionaryI.H:114
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition: dictionary.C:481
bool isStream() const noexcept
True if found entry is a stream.
Definition: dictionary.H:268
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
Searcher< false > searcher
Searcher with non-const access.
Definition: dictionary.H:329
bool remove(const word &keyword)
Remove an entry specified by keyword.
const_searcher search(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
dictionary()
Default construct, a top-level empty dictionary.
Definition: dictionary.C:68
const dictionary * findScopedDict(const fileName &dictPath) const
Locate a sub-dictionary using slash-scoping.
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect...
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:560
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:799
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
static refPtr< OSstream > reportingOutput
Output location when reporting default values.
Definition: dictionary.H:491
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
static autoPtr< dictionary > New(Istream &is)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:62
Intrusive doubly-linked list.
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition: dictionaryI.H:77
Generic const/non-const dictionary entry searcher.
Definition: dictionary.H:149
bool good() const noexcept
True if entry was found.
Definition: dictionary.H:233
A class for handling words, derived from Foam::string.
Definition: word.H:63
dict_reference context() const
The containing dictionary context.
Definition: dictionary.H:245
value_type * pointer
A pointer to a const/non-const entry.
Definition: dictionary.H:179
dict_type & dict_reference
A reference to a const/non-const dictionary.
Definition: dictionary.H:174
Istream & operator>>(Istream &, directionInfo &)
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:255
T getCheckOrDefault(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:486
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:185
bool substituteKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given keyword (which is prefixed by &#39;$&#39;)
Definition: dictionary.C:377
const entry * lookupScopedEntryPtr(const word &keyword, bool recursive, bool patternMatch) const
Deprecated(2018-10)
Definition: dictionary.H:1798
ITstream & lookupCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream, using any compatibility names if needed.
String literal.
Definition: keyType.H:82
dict_type * dict_pointer
A pointer to a const/non-const dictionary.
Definition: dictionary.H:169
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
word getWord(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< word >(const word&, keyType::option)
Definition: dictionary.H:1680
scalar getScalar(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< scalar >(const word&, keyType::option)
Definition: dictionary.H:1678
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition: stdFoam.H:55
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
T * pointer
Pointer for value_type.
Definition: UILList.H:78
const direction noexcept
Definition: Scalar.H:258
std::conditional< Const, const dictionary, dictionary >::type dict_type
The const/non-const type for the context and sub-dictionaries.
Definition: dictionary.H:158
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
const dictionary * cfindScopedDict(const fileName &dictPath) const
Locate a sub-dictionary using slash-scoping.
const_searcher csearchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using scoping.
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary. ...
Definition: dictionary.C:521
Searcher< true > const_searcher
Searcher with const access.
Definition: dictionary.H:324
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:481
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt) const
Find and return an entry pointer if present, or return a nullptr, using any compatibility names if ne...
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:179
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T using any compatibility names if needed. FatalIOError if not found, or if there are excess tokens.
const_searcher searchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using dot or slash scoping.
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check for existence of a sub-dictionary. Generally prefer findDict() for more flexibility.
Definition: dictionary.H:1694
T getOrAdd(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Find and return a T, or return the given default value and add it to dictionary. FatalIOError if it i...
dictionary * makeScopedDict(const fileName &dictPath)
Locate existing or create sub-dictionary using slash-scoping.
bool foundCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:607
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:204
bool isDict() const noexcept
True if found entry is a dictionary.
Definition: dictionary.H:260
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Searcher(dict_pointer dict) noexcept
Implicit construct for the given dictionary context.
Definition: dictionary.H:203
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:84
dict_pointer dict_
The dictionary context for the entry.
Definition: dictionary.H:192
Non-intrusive doubly-linked list.
void checkITstream(const ITstream &is, const word &keyword) const
Check after reading if the input token stream has unconsumed tokens remaining or if there were no tok...
Definition: dictionary.C:251
#define defineDictionaryGetter(Func, Type)
Definition: dictionary.H:1665
ITstream * streamPtr() const noexcept
Pointer to the found entry as a stream, nullptr otherwise.
Definition: dictionary.H:284
const dictionary * subDictPtr(const word &keyword) const
Deprecated(2018-10)
Definition: dictionary.H:1817
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
friend class entry
Declare friendship with the entry class for IO.
Definition: dictionary.H:337
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
T lookupType(const word &keyword, bool recursive=false, bool patternMatch=true) const
Deprecated(2018-10) find and return a T.
Definition: dictionary.H:1936
const_searcher csearch(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
pointer ptr() const noexcept
A pointer to the entry (nullptr if not found)
Definition: dictionary.H:250
void clear()
Clear the dictionary.
Definition: dictionary.C:844
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool overwrite=false)
Change the keyword for an entry,.
const entry & lookupEntryCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt) const
Find and return an entry if present, otherwise FatalIOError, using any compatibility names if needed...
fileName getFileName(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< fileName >(const word&, keyType::option)
Definition: dictionary.H:1681
friend Ostream & operator(Ostream &os, const UILList< LListBase, T > &lst)
Write UILList to Ostream with line breaks, as per writeList() with shortLen=-1.
Regular expression.
Definition: keyType.H:83
void writeEntries(Ostream &os, const bool extraNewLine=false) const
Write dictionary entries.
Definition: dictionaryIO.C:173
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:198
bool isNullDict() const noexcept
The dictionary is actually dictionary::null (root dictionary)
Definition: dictionaryI.H:71
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:601
An input stream of tokens.
Definition: ITstream.H:52
pointer operator->() const noexcept
A pointer to the entry (nullptr if not found)
Definition: dictionary.H:312
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
bool getBool(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< bool >(const word&, keyType::option)
Definition: dictionary.H:1676
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value using any compatibility names if needed...
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124