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-2022 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  //- Construct for the given dictionary context.
187  // Allow implicit conversion
189  :
190  dict_(dict),
191  eptr_(nullptr)
192  {}
193 
194  //- Assign the entry
195  void set(pointer eptr) noexcept
196  {
197  eptr_ = eptr;
198  }
199 
200 
201  public:
202 
203  //- Default construct
204  constexpr Searcher() noexcept
205  :
206  dict_(nullptr),
207  eptr_(nullptr)
208  {}
209 
210 
211  //- True if entry was found
212  bool good() const noexcept { return eptr_; }
213 
214  //- True if entry was found
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_; }
226  //- True if found entry is a dictionary.
227  bool isDict() const noexcept
228  {
229  return (eptr_ && eptr_->dictPtr());
230  }
231 
232  //- Pointer to the found entry as a dictionary, nullptr otherwise
234  {
235  return eptr_ ? eptr_->dictPtr() : nullptr;
236  }
237 
238  //- Reference the found entry as a dictionary.
239  // (Error if not found, or not a dictionary).
241  {
242  return eptr_->dict();
243  }
244 
245  //- Permit an explicit cast to the other (const/non-const) searcher
246  explicit operator const Searcher<!Const>&() const
247  {
248  return *reinterpret_cast<const Searcher<!Const>*>(this);
249  }
251  //- A pointer to the entry (nullptr if not found)
252  pointer operator->() const noexcept
253  {
254  return eptr_;
255  }
256 
257  //- A reference to the entry (Error if not found)
258  reference operator*() const
259  {
260  return *eptr_;
261  }
262  };
263 
264 
265  //- Searcher with const access
266  typedef Searcher<true> const_searcher;
267 
268  //- Searcher with non-const access
269  typedef Searcher<false> searcher;
270 
271 
272  // Friends
273 
274  //- Declare friendship with the entry class for IO
275  friend class entry;
276 
277  //- Declare friendship with the searcher classes
279  friend searcher;
280 
281 
282 private:
283 
284  // Private Data
285 
286  //- The dictionary name
287  fileName name_;
288 
289  //- Parent dictionary
290  const dictionary& parent_;
291 
292  //- Quick lookup of the entries held on the IDLList
293  HashTable<entry*> hashedEntries_;
295  //- Entries of matching patterns
296  DLList<entry*> patterns_;
297 
298  //- Patterns as precompiled regular expressions
299  DLList<autoPtr<regExp>> regexps_;
300 
301 
302  // Typedefs
303 
304  //- The storage container
305  typedef IDLList<entry> parent_type;
306 
307 
308  // Private Member Functions
309 
310  //- Convert old-style (1806) boolean search specification to enum
311  //
312  // \param recursive search parent dictionaries
313  // \param pattern match using regular expressions as well
314  inline static enum keyType::option
315  matchOpt(bool recursive, bool pattern)
316  {
317  return
319  (
320  (pattern ? keyType::REGEX : keyType::LITERAL)
321  | (recursive ? keyType::RECURSIVE : 0)
322  );
323  }
324 
325  //- Search using a '.' for scoping.
326  // A leading dot means to use the parent dictionary.
327  // An intermediate dot separates a sub-dictionary or sub-entry.
328  // However, the use of dots is unfortunately ambiguous.
329  // The value "a.b.c.d" could be a first-level entry, a second-level
330  // entry (eg, "a" with "b.c.d", "a.b" with "c.d" etc),
331  // or just about any other combination.
332  // The heuristic tries successively longer top-level entries
333  // until there is a suitable match.
334  //
335  // \param keyword the keyword to search for
336  // \param matchOpt the search mode
337  const_searcher csearchDotScoped
338  (
339  const word& keyword,
340  enum keyType::option matchOpt
341  ) const;
342 
343  //- Search using a '/' for scoping.
344  // Semantics as per normal files: an intermediate "." is the current
345  // dictionary level, an intermediate ".." is the parent dictionary.
346  // Note that since a slash is not a valid word character, there is no
347  // ambiguity between separator and content.
348  // No possibility or need for recursion.
349  //
350  // \param keyword the keyword to search for
351  // \param matchOpt the search mode. Recursive is ignored.
352  const_searcher csearchSlashScoped
353  (
354  const word& keyword,
355  enum keyType::option matchOpt
356  ) const;
357 
358 
359  //- Emit IOError about bad input for the entry
360  void raiseBadInput(const ITstream& is, const word& keyword) const;
361 
362  //- The currently known executable name,
363  //- obtained from argList envExecutable
364  static word executableName();
365 
366  //- Report (usually stderr) that the keyword default value was used,
367  //- or FatalIOError when writeOptionalEntries greater than 1
368  template<class T>
369  void reportDefault
370  (
371  const word& keyword,
372  const T& deflt,
373  const bool added = false // Value was added to the dictionary
374  ) const;
375 
376 
377 public:
378 
379  // Declare name of the class and its debug switch
380  ClassName("dictionary");
381 
382  // Static Data
383 
384  //- Report optional keywords and values if not present in dictionary
385  // For value greater than 1: fatal.
386  // Set/unset via an InfoSwitch or -info-switch at the command-line
387  static int writeOptionalEntries;
388 
389  //- An empty dictionary, which is also the parent for all dictionaries
390  static const dictionary null;
391 
392  //- Output location when reporting default values
394 
395 
396  // Static Member Functions
397 
398  //- Return the state of reporting optional (default) entries
399  // 0: no reporting, 1: report, 2: fatal if not set
400  inline static int reportOptional() noexcept;
401 
402  //- Change the state of reporting optional (default) entries
403  // 0: no reporting, 1: report, 2: fatal if not set
404  // \return old level
405  inline static int reportOptional(const int level) noexcept;
406 
407 
408  // Constructors
409 
410  //- Default construct, a top-level empty dictionary
411  dictionary();
412 
413  //- Construct top-level empty dictionary with given name
414  explicit dictionary(const fileName& name);
415 
416  //- Construct given the entry name, parent dictionary and Istream,
417  //- reading entries until EOF, optionally keeping the header
418  dictionary
419  (
420  const fileName& name,
421  const dictionary& parentDict,
422  Istream& is,
423  bool keepHeader = false
424  );
425 
426  //- Construct top-level dictionary from Istream (discards the header).
427  //- Reads entries until EOF or when the first token is a
428  //- '{' character, it will stop reading at the matching '}' character.
429  // \note this constructor should be explicit
430  dictionary(Istream& is);
431 
432  //- Construct top-level dictionary from Istream,
433  //- reading entries until EOF, optionally keeping the header
434  dictionary(Istream& is, bool keepHeader);
435 
436  //- Copy construct given the parent dictionary
437  dictionary(const dictionary& parentDict, const dictionary& dict);
438 
439  //- Copy construct top-level dictionary
440  dictionary(const dictionary& dict);
441 
442  //- Construct top-level dictionary as copy from pointer to dictionary.
443  // A null pointer is treated like an empty dictionary.
444  explicit dictionary(const dictionary* dict);
445 
446  //- Move construct for given parent dictionary
447  dictionary(const dictionary& parentDict, dictionary&& dict);
448 
449  //- Move construct top-level dictionary
451 
452  //- Construct and return clone
453  autoPtr<dictionary> clone() const;
454 
455  //- Construct top-level dictionary on freestore from Istream
456  static autoPtr<dictionary> New(Istream& is);
457 
458 
459  //- Destructor
460  virtual ~dictionary();
461 
462 
463  // Member Functions
464 
465  // Access
466 
467  //- The dictionary name
468  inline const fileName& name() const noexcept;
470  //- The dictionary name for modification (use with caution).
471  inline fileName& name() noexcept;
472 
473  //- The local dictionary name (final part of scoped name)
474  inline word dictName() const;
475 
476  //- The dictionary name relative to the case.
477  // Uses argList::envRelativePath to obtain FOAM_CASE
478  //
479  // \param caseTag replace globalPath with <case> for later
480  // use with expand(), or prefix <case> if the file name was
481  // not an absolute location
482  fileName relativeName(const bool caseTag = false) const;
483 
484  //- The dictionary is actually dictionary::null (root dictionary)
485  inline bool isNullDict() const noexcept;
486 
487  //- Return the parent dictionary
488  inline const dictionary& parent() const noexcept;
489 
490  //- Return the top of the tree
491  const dictionary& topDict() const;
492 
493  //- Return line number of first token in dictionary
494  label startLineNumber() const;
495 
496  //- Return line number of last token in dictionary
497  label endLineNumber() const;
498 
499  //- Return the SHA1 digest of the dictionary contents
500  SHA1Digest digest() const;
501 
502  //- Return the dictionary as a list of tokens
503  tokenList tokens() const;
504 
505 
506  // Searching
507 
508  //- Find an entry (const access) with the given keyword.
509  //
510  // \param keyword the keyword to search for
511  // \param matchOpt search mode (default: non-recursive with patterns)
512  //
513  // \return pointer to the entry found or a nullptr.
514  inline const entry* findEntry
515  (
516  const word& keyword,
517  enum keyType::option matchOpt = keyType::REGEX
518  ) const;
519 
520  //- Find an entry (non-const access) with the given keyword.
521  //
522  // \param keyword the keyword to search for
523  // \param matchOpt search mode (default: non-recursive with patterns)
524  //
525  // \return pointer to the entry found or a nullptr.
526  inline entry* findEntry
527  (
528  const word& keyword,
529  enum keyType::option matchOpt = keyType::REGEX
530  );
531 
532  //- Find an entry (const access) with the given keyword.
533  //
534  // \param keyword the keyword to search for
535  // \param matchOpt search mode (default: non-recursive with patterns)
536  //
537  // \return True if entry was found
538  inline bool found
539  (
540  const word& keyword,
541  enum keyType::option matchOpt = keyType::REGEX
542  ) const;
543 
544  //- Search for a scoped entry (const access) with the given keyword.
545  // Allows scoping using '.'.
546  // Special handling for an absolute anchor (^) at start of the keyword
547  // and for '..' to ascend into the parent dictionaries.
548  //
549  // \param keyword the keyword to search for
550  // \param matchOpt search mode (default: non-recursive with patterns)
551  //
552  // \return pointer to the entry found or a nullptr.
553  inline const entry* findScoped
554  (
555  const word& keyword,
556  enum keyType::option matchOpt = keyType::REGEX
557  ) const;
558 
559  //- Find and return a sub-dictionary pointer if present
560  //- (and a sub-dictionary) otherwise return nullptr.
561  //
562  // \param keyword the keyword to search for
563  // \param matchOpt search mode (default: non-recursive with patterns)
564  //
565  // \return pointer to sub-dictionary found or a nullptr.
566  inline const dictionary* findDict
567  (
568  const word& keyword,
569  enum keyType::option matchOpt = keyType::REGEX
570  ) const;
571 
572  //- Find and return a sub-dictionary pointer if present
573  //- (and a sub-dictionary) otherwise return nullptr.
574  //
575  // \param keyword the keyword to search for
576  // \param matchOpt search mode (default: non-recursive with patterns)
577  //
578  // \return pointer to sub-dictionary found or a nullptr.
579  inline dictionary* findDict
580  (
581  const word& keyword,
582  enum keyType::option matchOpt = keyType::REGEX
583  );
584 
585  //- Find a sub-dictionary.
586  //
587  // \param keyword the keyword to search for
588  // \param matchOpt search mode (default: non-recursive with patterns)
589  //
590  // \return true if the sub-dictionary was found
591  inline bool isDict
592  (
593  const word& keyword,
594  enum keyType::option matchOpt = keyType::REGEX
595  ) const;
596 
597 
598  // Lookup
599 
600  //- Search for an entry (const access) with the given keyword.
601  //
602  // \param keyword the keyword to search for
603  // \param matchOpt search mode
604  //
605  // \return return an entry if present, otherwise FatalIOError.
606  const entry& lookupEntry
607  (
608  const word& keyword,
609  enum keyType::option matchOpt
610  ) const;
611 
612  //- Find and return an entry data stream.
613  //- FatalIOError if not found, or not a stream
614  //
615  // \param keyword the keyword to search for
616  // \param matchOpt search mode (default: non-recursive with patterns)
617  //
618  // \return entry stream or FatalIOError
620  (
621  const word& keyword,
622  enum keyType::option matchOpt = keyType::REGEX
623  ) const;
624 
625  //- Find and return a T.
626  //- FatalIOError if not found, or if the number of tokens is incorrect.
627  //
628  // \param keyword the keyword to search for
629  // \param matchOpt search mode (default: non-recursive with patterns)
630  template<class T>
631  T get
632  (
633  const word& keyword,
634  enum keyType::option matchOpt = keyType::REGEX
635  ) const;
636 
637  //- Find and return a T, or return the given default value.
638  //- FatalIOError if it is found and the number of tokens is incorrect.
639  //
640  // \param keyword the keyword to search for
641  // \param deflt the default value to use
642  // \param matchOpt search mode (default: non-recursive with patterns)
643  template<class T>
645  (
646  const word& keyword,
647  const T& deflt,
648  enum keyType::option matchOpt = keyType::REGEX
649  ) const;
650 
651  //- Find and return a T, or return the given default value
652  //- and add it to dictionary.
653  //- FatalIOError if it is found and the number of tokens is incorrect.
654  //
655  // \param keyword the keyword to search for
656  // \param deflt the default value to use
657  // \param matchOpt search mode (default: non-recursive with patterns)
658  template<class T>
659  T getOrAdd
660  (
661  const word& keyword,
662  const T& deflt,
663  enum keyType::option matchOpt = keyType::REGEX
664  );
665 
666  //- Find entry and assign to T val.
667  //- FatalIOError if it is found and the number of tokens is incorrect,
668  //- or it is mandatory and not found.
669  //
670  // \param keyword the keyword to search for
671  // \param val the value to read into
672  // \param matchOpt search mode (default: non-recursive with patterns)
673  // \param readOpt the entry is required/optional (default: MUST_READ)
674  //
675  // \return true if the entry was read
676  template<class T>
677  bool readEntry
678  (
679  const word& keyword,
680  T& val,
681  enum keyType::option matchOpt = keyType::REGEX,
682  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
683  ) const;
684 
685  //- Find an entry if present, and assign to T val.
686  //- FatalIOError if it is found and the number of tokens is incorrect.
687  //
688  // \param keyword the keyword to search for
689  // \param val the value to read into
690  // \param matchOpt search mode (default: non-recursive with patterns)
691  //
692  // \return true if the entry was read
693  template<class T>
694  bool readIfPresent
695  (
696  const word& keyword,
697  T& val,
698  enum keyType::option matchOpt = keyType::REGEX
699  ) const;
700 
701  //- Find and return a T with additional checking
702  //- FatalIOError if not found, or if the number of tokens is incorrect.
703  //
704  // \param keyword the keyword to search for
705  // \param pred the value check predicate
706  // \param matchOpt search mode (default: non-recursive with patterns)
707  template<class T, class Predicate>
708  T getCheck
709  (
710  const word& keyword,
711  const Predicate& pred,
712  enum keyType::option matchOpt = keyType::REGEX
713  ) const;
714 
715  //- Find and return a T, or return the given default value.
716  //- FatalIOError if it is found and the number of tokens is incorrect.
717  //
718  // \param keyword the keyword to search for
719  // \param deflt the default value to use
720  // \param pred the value check predicate
721  // \param matchOpt search mode (default: non-recursive with patterns)
722  template<class T, class Predicate>
724  (
725  const word& keyword,
726  const T& deflt,
727  const Predicate& pred,
728  enum keyType::option matchOpt = keyType::REGEX
729  ) const;
730 
731  //- Find and return a T, or return the given default value
732  //- and add it to dictionary.
733  //- FatalIOError if it is found and the number of tokens is incorrect.
734  //
735  // \param keyword the keyword to search for
736  // \param deflt the default value to use
737  // \param pred the value check predicate
738  // \param matchOpt search mode (default: non-recursive with patterns)
739  template<class T, class Predicate>
741  (
742  const word& keyword,
743  const T& deflt,
744  const Predicate& pred,
745  enum keyType::option matchOpt = keyType::REGEX
746  );
747 
748  //- Find entry and assign to T val.
749  //- FatalIOError if it is found and the number of tokens is incorrect,
750  //- or it is mandatory and not found.
751  //
752  // \param keyword the keyword to search for
753  // \param val the value to read into
754  // \param pred the value check predicate
755  // \param matchOpt search mode (default: non-recursive with patterns)
756  // \param readOpt the entry is required/optional (default: MUST_READ)
757  //
758  // \return true if the entry was read
759  template<class T, class Predicate>
760  bool readCheck
761  (
762  const word& keyword,
763  T& val,
764  const Predicate& pred,
765  enum keyType::option matchOpt = keyType::REGEX,
766  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
767  ) const;
768 
769  //- Find an entry if present, and assign to T val.
770  //- FatalIOError if it is found and the number of tokens is incorrect.
771  //
772  // \param keyword the keyword to search for
773  // \param val the value to read into
774  // \param pred the value check predicate
775  // \param matchOpt search mode (default: non-recursive with patterns)
776  //
777  // \return true if the entry read
778  template<class T, class Predicate>
779  bool readCheckIfPresent
780  (
781  const word& keyword,
782  T& val,
783  const Predicate& pred,
784  enum keyType::option matchOpt = keyType::REGEX
785  ) const;
786 
787  //- Find and return a sub-dictionary.
788  // Fatal if the entry does not exist or is not a sub-dictionary.
789  //
790  // \param keyword the keyword to search for
791  // \param matchOpt search mode (default: non-recursive with patterns)
792  const dictionary& subDict
793  (
794  const word& keyword,
795  enum keyType::option matchOpt = keyType::REGEX
796  ) const;
797 
798  //- Find and return a sub-dictionary for manipulation.
799  // Fatal if the entry does not exist or is not a sub-dictionary.
800  //
801  // \param keyword the keyword to search for
802  // \param matchOpt search mode (default: non-recursive with patterns)
804  (
805  const word& keyword,
806  enum keyType::option matchOpt = keyType::REGEX
807  );
808 
809  //- Find and return a sub-dictionary for manipulation.
810  // Fatal if the entry exist and is not a sub-dictionary.
811  //
812  // \param keyword the keyword to search for
813  // \param matchOpt search mode (default: non-recursive with patterns)
815  (
816  const word& keyword,
817  enum keyType::option matchOpt = keyType::REGEX
818  );
819 
820  //- Find and return a sub-dictionary as a copy, otherwise return
821  //- an empty dictionary.
822  // Warn if the entry exists but is not a sub-dictionary.
823  //
824  // \param keyword the keyword to search for
825  // \param matchOpt search mode (default: non-recursive with patterns)
826  // \param mandatory the keyword is mandatory (default: false)
828  (
829  const word& keyword,
830  enum keyType::option matchOpt = keyType::REGEX,
831  const bool mandatory = false
832  ) const;
833 
834  //- Find and return a sub-dictionary, otherwise return this dictionary.
835  // Warn if the entry exists but is not a sub-dictionary.
836  //
837  // \param keyword the keyword to search for
838  // \param matchOpt search mode (default: non-recursive with patterns)
840  (
841  const word& keyword,
842  enum keyType::option matchOpt = keyType::REGEX
843  ) const;
844 
845  //- Return the table of contents
846  wordList toc() const;
847 
848  //- Return the sorted table of contents
849  wordList sortedToc() const;
850 
851  //- Return table of contents sorted using the specified comparator
852  template<class Compare>
853  wordList sortedToc(const Compare& comp) const;
854 
855  //- Return the list of available keys or patterns
856  List<keyType> keys(bool patterns = false) const;
857 
858 
859  // Editing
860 
861  //- Substitute the given keyword (which is prefixed by '$')
862  // with the corresponding sub-dictionary entries
863  bool substituteKeyword
864  (
865  const word& keyword,
866  bool mergeEntry = false
867  );
868 
869  //- Substitute the given scoped keyword (which is prefixed by '$')
870  // with the corresponding sub-dictionary entries
872  (
873  const word& keyword,
874  bool mergeEntry = false
875  );
876 
877  //- Add a new entry.
878  //
879  // \param entryPtr the entry to add
880  // \param mergeEntry dictionaries are interwoven and primitive
881  // entries are overwritten (default: false)
882  //
883  // \return pointer to inserted entry, or place of merging
884  // or nullptr on failure
885  entry* add(entry* entryPtr, bool mergeEntry=false);
886 
887  //- Add an entry.
888  //
889  // \param e the entry to add
890  // \param mergeEntry dictionaries are interwoven and primitive
891  // entries are overwritten (default: false)
892  // \return pointer to inserted entry, or place of merging
893  // or nullptr on failure
894  entry* add(const entry& e, bool mergeEntry=false);
895 
896  //- Add a word entry.
897  // \param overwrite force overwrite of an existing entry.
898  // \return pointer to inserted entry or nullptr on failure
899  entry* add(const keyType& k, const word& v, bool overwrite=false);
900 
901  //- Add a string entry.
902  // \param overwrite force overwrite of an existing entry.
903  // \return pointer to inserted entry or nullptr on failure
904  entry* add(const keyType& k, const string& v, bool overwrite=false);
905 
906  //- Add a label entry.
907  // \param overwrite force overwrite of an existing entry.
908  // \return pointer to inserted entry or nullptr on failure
909  entry* add(const keyType& k, const label v, bool overwrite=false);
910 
911  //- Add a scalar entry.
912  // \param overwrite force overwrite of an existing entry.
913  // \return pointer to inserted entry or nullptr on failure
914  entry* add(const keyType& k, const scalar v, bool overwrite=false);
915 
916  //- Add a dictionary entry.
917  // \param mergeEntry merge into an existing sub-dictionary
918  // \return pointer to inserted entry, or place of merging
919  // or nullptr on failure
920  entry* add
921  (
922  const keyType& k,
923  const dictionary& d,
924  bool mergeEntry = false
925  );
926 
927  //- Add a T entry
928  // \param overwrite force overwrite of existing entry
929  // \return pointer to inserted entry or nullptr on failure
930  template<class T>
931  entry* add(const keyType& k, const T& v, bool overwrite=false);
932 
933  //- Assign a new entry, overwriting any existing entry.
934  //
935  // \return pointer to inserted entry or nullptr on failure
936  entry* set(entry* entryPtr);
937 
938  //- Assign a new entry, overwriting any existing entry.
939  //
940  // \return pointer to inserted entry or nullptr on failure
941  entry* set(const entry& e);
942 
943  //- Assign a dictionary entry, overwriting any existing entry.
944  //
945  // \return pointer to inserted entry or nullptr on failure
946  entry* set(const keyType& k, const dictionary& v);
947 
948  //- Assign a T entry, overwriting any existing entry.
949  // \return pointer to inserted entry or nullptr on failure
950  template<class T>
951  entry* set(const keyType& k, const T& v);
952 
953  //- Remove an entry specified by keyword
954  bool remove(const word& keyword);
955 
956  //- Change the keyword for an entry,
957  // \param overwrite force overwrite of an existing entry.
958  bool changeKeyword
959  (
960  const keyType& oldKeyword,
961  const keyType& newKeyword,
962  bool overwrite=false
963  );
964 
965  //- Merge entries from the given dictionary.
966  // Also merge sub-dictionaries as required.
967  bool merge(const dictionary& dict);
968 
969  //- Clear the dictionary
970  void clear();
971 
972  //- Transfer the contents of the argument and annul the argument.
973  void transfer(dictionary& dict);
974 
975 
976  // Read
977 
978  //- Check after reading if the input token stream has unconsumed
979  //- tokens remaining or if there were no tokens in the first place.
980  // Emits FatalIOError
981  void checkITstream(const ITstream& is, const word& keyword) const;
982 
983  //- Read dictionary from Istream (discards the header).
984  //- Reads entries until EOF or when the first token is a
985  //- '{' character, it will stop reading at the matching '}' character.
986  bool read(Istream& is);
987 
988  //- Read dictionary from Istream (optionally keeping the header)
989  //- Reads entries until EOF or when the first token is a
990  //- '{' character, it will stop reading at the matching '}' character.
991  bool read(Istream& is, bool keepHeader);
992 
993 
994  // Write
995 
996  //- Write sub-dictionary with its dictName as its header
997  void writeEntry(Ostream& os) const;
998 
999  //- Write sub-dictionary with the keyword as its header
1000  void writeEntry(const keyType& keyword, Ostream& os) const;
1001 
1002  //- Write dictionary entries.
1003  // \param extraNewLine adds additional newline between entries
1004  // for "top-level" dictionaries
1005  void writeEntries(Ostream& os, const bool extraNewLine=false) const;
1006 
1007  //- Write dictionary, normally with sub-dictionary formatting
1008  void write(Ostream& os, const bool subDict=true) const;
1009 
1010 
1011  // Searching
1012 
1013  //- Search dictionary for given keyword
1014  //
1015  // \param keyword the keyword to search for
1016  // \param matchOpt search mode (default: non-recursive with patterns)
1018  (
1019  const word& keyword,
1020  enum keyType::option matchOpt = keyType::REGEX
1021  ) const;
1022 
1023  //- Search dictionary for given keyword
1024  //
1025  // \param keyword the keyword to search for
1026  // \param matchOpt search mode (default: non-recursive with patterns)
1028  (
1029  const word& keyword,
1030  enum keyType::option matchOpt = keyType::REGEX
1031  ) const;
1032 
1033  //- Search dictionary for given keyword
1034  //
1035  // \param keyword the keyword to search for
1036  // \param matchOpt search mode (default: non-recursive with patterns)
1038  (
1039  const word& keyword,
1040  enum keyType::option matchOpt = keyType::REGEX
1041  );
1042 
1043  //- Search using scoping.
1044  // There are two types of scoping available:
1045  // -# dot-scoping, where a '.' is used to delineate the scope
1046  // -# slash-scoping, where a '/' is used to delineate the scope
1047  //
1048  // For dot-scoping, a leading '^' traverses to the top-level
1049  // dictionary, leading dots mean use the parent dictionary and an
1050  // intermediate dot separates a sub-dictionary or sub-entry.
1051  // However, since the use of dots is ambiguous ("a.b.c" could be
1052  // an entry itself or represent a "bc" entry from dictionary "a" etc),
1053  // the heuristic backtracks and attempts successively longer
1054  // top-level entries until a suitable match is found.
1055  //
1056  // For slash-scoping, semantics similar to directory structures are
1057  // used. A leading '/' traverses to the top-level dictionary,
1058  // a single leading or intermediate '.' references the current
1059  // dictionary level. A '..' pair references the parent dictionary.
1060  // Any doubled slashes are silently ignored.
1061  // Since a slash is not a valid keyword character, there is no
1062  // ambiguity between separator and content.
1063  //
1064  // \param keyword the keyword to search for
1065  // \param matchOpt search mode
1067  (
1068  const word& keyword,
1069  enum keyType::option matchOpt
1070  ) const;
1071 
1072  //- Search using dot or slash scoping.
1073  //
1074  // \param keyword the keyword to search for
1075  // \param matchOpt search mode
1077  (
1078  const word& keyword,
1079  enum keyType::option matchOpt
1080  ) const;
1081 
1082  //- Search using dot or slash scoping.
1083  //
1084  // \param keyword the keyword to search for
1085  // \param matchOpt search mode
1087  (
1088  const word& keyword,
1089  enum keyType::option matchOpt
1090  );
1091 
1092  //- Locate a sub-dictionary using slash-scoping
1093  // \return nullptr if the dictionary path does not exist
1094  const dictionary* cfindScopedDict(const fileName& dictPath) const;
1095 
1096  //- Locate a sub-dictionary using slash-scoping
1097  // \return nullptr if the dictionary path does not exist
1098  const dictionary* findScopedDict(const fileName& dictPath) const;
1099 
1100  //- Locate a sub-dictionary using slash-scoping
1101  // \return nullptr if the dictionary path does not exist
1102  dictionary* findScopedDict(const fileName& dictPath);
1103 
1104  //- Locate existing or create sub-dictionary using slash-scoping
1105  // \return nullptr if the dictionary path could not be created
1106  dictionary* makeScopedDict(const fileName& dictPath);
1107 
1108 
1109  // Compatibility helpers
1110 
1111  //- Search dictionary for given keyword and any compatibility names
1112  //
1113  // \param keyword the keyword to search for
1114  // \param compat list of old compatibility keywords and the last
1115  // OpenFOAM version for which they were used.
1116  // Old version 1600=OpenFOAM-v3.0, 240=OpenFOAM-2.4.x,
1117  // 170=OpenFOAM-1.7.x,...
1118  // \param matchOpt search mode (default: non-recursive with patterns)
1120  (
1121  const word& keyword,
1122  std::initializer_list<std::pair<const char*,int>> compat,
1123  enum keyType::option matchOpt = keyType::REGEX
1124  ) const;
1125 
1126  //- Find and return an entry pointer if present, or return a nullptr,
1127  //- using any compatibility names if needed.
1128  //
1129  // \param keyword the keyword to search for
1130  // \param compat list of old compatibility keywords and the last
1131  // OpenFOAM version for which they were used.
1132  // \param matchOpt search mode
1133  const entry* findCompat
1134  (
1135  const word& keyword,
1136  std::initializer_list<std::pair<const char*,int>> compat,
1137  enum keyType::option matchOpt
1138  ) const;
1139 
1140  //- Search dictionary for given keyword and any compatibility names
1141  //
1142  // \param keyword the keyword to search for
1143  // \param compat list of old compatibility keywords and the last
1144  // OpenFOAM version for which they were used.
1145  // \param matchOpt search mode (default: non-recursive with patterns)
1146  bool foundCompat
1147  (
1148  const word& keyword,
1149  std::initializer_list<std::pair<const char*,int>> compat,
1150  enum keyType::option matchOpt = keyType::REGEX
1151  ) const;
1152 
1153  //- Find and return an entry if present, otherwise FatalIOError,
1154  //- using any compatibility names if needed.
1155  //
1156  // \param keyword the keyword to search for
1157  // \param compat list of old compatibility keywords and the last
1158  // OpenFOAM version for which they were used.
1159  // \param matchOpt search mode
1160  const entry& lookupEntryCompat
1161  (
1162  const word& keyword,
1163  std::initializer_list<std::pair<const char*,int>> compat,
1164  enum keyType::option matchOpt
1165  ) const;
1166 
1167  //- Find and return an entry data stream,
1168  //- using any compatibility names if needed.
1169  //
1170  // \param keyword the keyword to search for
1171  // \param compat list of old compatibility keywords and the last
1172  // OpenFOAM version for which they were used.
1173  // \param matchOpt search mode (default: non-recursive with patterns)
1175  (
1176  const word& keyword,
1177  std::initializer_list<std::pair<const char*,int>> compat,
1178  enum keyType::option matchOpt = keyType::REGEX
1179  ) const;
1180 
1181  //- Find and return a T
1182  //- using any compatibility names if needed.
1183  //- FatalIOError if not found, or if there are excess tokens.
1184  //
1185  // \param keyword the keyword to search for
1186  // \param compat list of old compatibility keywords and the last
1187  // OpenFOAM version for which they were used.
1188  // \param matchOpt search mode (default: non-recursive with patterns)
1189  template<class T>
1190  T getCompat
1191  (
1192  const word& keyword,
1193  std::initializer_list<std::pair<const char*,int>> compat,
1194  enum keyType::option matchOpt = keyType::REGEX
1195  ) const;
1196 
1197  //- Find and return a T, or return the given default value
1198  //- using any compatibility names if needed.
1199  //
1200  // \param keyword the keyword to search for
1201  // \param compat list of old compatibility keywords and the last
1202  // OpenFOAM version for which they were used.
1203  // \param deflt the default value to use
1204  // \param matchOpt search mode (default: non-recursive with patterns)
1205  template<class T>
1207  (
1208  const word& keyword,
1209  std::initializer_list<std::pair<const char*,int>> compat,
1210  const T& deflt,
1211  enum keyType::option matchOpt = keyType::REGEX
1212  ) const;
1213 
1214  //- Find entry and assign to T val
1215  //- using any compatibility names if needed.
1216  //- FatalIOError if there are excess tokens.
1217  //
1218  // \param keyword the keyword to search for
1219  // \param compat list of old compatibility keywords and the last
1220  // OpenFOAM version for which they were used.
1221  // \param val the value to read
1222  // \param matchOpt search mode (default: non-recursive with patterns)
1223  // \param readOpt the entry is required/optional (default: MUST_READ)
1224  //
1225  // \return true if the entry was read
1226  template<class T>
1227  bool readCompat
1228  (
1229  const word& keyword,
1230  std::initializer_list<std::pair<const char*,int>> compat,
1231  T& val,
1232  enum keyType::option matchOpt = keyType::REGEX,
1233  IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
1234  ) const;
1235 
1236  //- Find an entry if present, and assign to T val
1237  //- using any compatibility names if needed.
1238  //- FatalIOError if it is found and there are excess tokens.
1239  //
1240  // \param keyword the keyword to search for
1241  // \param compat list of old compatibility keywords and the last
1242  // OpenFOAM version for which they were used.
1243  // \param val the value to read
1244  // \param matchOpt search mode (default: non-recursive with patterns)
1245  //
1246  // \return true if the entry was found.
1247  template<class T>
1248  bool readIfPresentCompat
1249  (
1250  const word& keyword,
1251  std::initializer_list<std::pair<const char*,int>> compat,
1252  T& val,
1253  enum keyType::option matchOpt = keyType::REGEX
1254  ) const;
1255 
1256 
1257  // Member Operators
1258 
1259  //- Copy assignment
1260  void operator=(const dictionary& rhs);
1261 
1262  //- Include entries from the given dictionary.
1263  // Warn, but do not overwrite existing entries.
1264  void operator+=(const dictionary& rhs);
1265 
1266  //- Conditionally include entries from the given dictionary.
1267  // Do not overwrite existing entries.
1268  void operator|=(const dictionary& rhs);
1269 
1270  //- Unconditionally include entries from the given dictionary.
1271  // Overwrite existing entries.
1272  void operator<<=(const dictionary& rhs);
1273 
1274 
1275  // IOstream operators
1276 
1277  //- Read dictionary from Istream
1278  friend Istream& operator>>(Istream& is, dictionary& dict);
1279 
1280  //- Write dictionary to Ostream
1281  friend Ostream& operator<<(Ostream& os, const dictionary& dict);
1282 
1283 
1284  // Shortcuts - when a templated classes also inherits from a dictionary
1285 
1286  #undef defineDictionaryGetter
1287  #define defineDictionaryGetter(Func, Type) \
1288  \
1289  Type Func \
1290  ( \
1291  const word& keyword, \
1292  enum keyType::option matchOpt = keyType::REGEX \
1293  ) const \
1294  { \
1295  return get<Type>(keyword, matchOpt); \
1296  }
1297 
1304 
1305  #undef defineDictionaryGetter
1306 
1307 
1308  // Housekeeping
1309 
1310  //- Same as getOrDefault()
1311  template<class T>
1312  FOAM_DEPRECATED_STRICT(2019-06, "getOrDefault()")
1314  (
1315  const word& keyword,
1316  const T& deflt,
1317  enum keyType::option matchOpt = keyType::REGEX
1318  ) const
1319  {
1320  return getOrDefault<T>(keyword, deflt, matchOpt);
1321  }
1322 
1323 
1324  //- Same as getOrAdd()
1325  template<class T>
1326  FOAM_DEPRECATED_STRICT(2019-06, "getOrAdd()")
1328  (
1329  const word& keyword,
1330  const T& deflt,
1331  enum keyType::option matchOpt = keyType::REGEX
1332  )
1333  {
1334  return getOrAdd<T>(keyword, deflt, matchOpt);
1335  }
1336 
1337  //- Deprecated(2018-07) - use lookup() method
1338  // \deprecated(2018-07) - use lookup() method
1339  FOAM_DEPRECATED_FOR(2018-07, "lookup() method")
1340  ITstream& operator[](const word& keyword) const
1341  {
1342  return lookup(keyword);
1343  }
1344 
1345  //- Deprecated(2018-10)
1346  // \deprecated(2018-10) - use keyType::option version
1347  FOAM_DEPRECATED_FOR(2018-10, "found(keyType::option)")
1348  bool found
1349  (
1350  const word& keyword,
1351  bool recursive,
1352  bool patternMatch = true
1353  ) const
1354  {
1355  return found(keyword, matchOpt(recursive, patternMatch));
1356  }
1357 
1358  //- Deprecated(2018-10)
1359  // \deprecated(2018-10) - use findEntry() method
1360  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1362  (
1363  const word& keyword,
1364  bool recursive,
1365  bool patternMatch
1366  )
1367  {
1368  return findEntry(keyword, matchOpt(recursive, patternMatch));
1369  }
1370 
1371  //- Deprecated(2018-10)
1372  // \deprecated(2018-10) - use findEntry() method
1373  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1374  const entry* lookupEntryPtr
1375  (
1376  const word& keyword,
1377  bool recursive,
1378  bool patternMatch
1379  ) const
1380  {
1381  return findEntry(keyword, matchOpt(recursive, patternMatch));
1382  }
1383 
1384  //- Deprecated(2018-10)
1385  // \deprecated(2018-10) - use findScoped() method
1386  FOAM_DEPRECATED_FOR(2018-10, "findScoped(keyType::option)")
1388  (
1389  const word& keyword,
1390  bool recursive,
1391  bool patternMatch
1392  ) const
1393  {
1394  return findScoped(keyword, matchOpt(recursive, patternMatch));
1395  }
1396 
1397  //- Deprecated(2018-10)
1398  // Find and return a sub-dictionary pointer if present
1399  // (and a sub-dictionary) otherwise return nullptr.
1400  //
1401  // Search type: non-recursive with patterns.
1402  // \deprecated(2018-10) - use findDict() method
1403  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1404  const dictionary* subDictPtr(const word& keyword) const
1405  {
1406  return findDict(keyword, keyType::REGEX);
1407  }
1408 
1409  //- Deprecated(2018-10)
1410  //- Find and return a sub-dictionary pointer if present
1411  // (and a sub-dictionary) otherwise return nullptr.
1412  //
1413  // Search type: non-recursive with patterns.
1414  // \deprecated(2018-10) - use findDict() method
1415  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1416  dictionary* subDictPtr(const word& keyword)
1417  {
1418  return findDict(keyword, keyType::REGEX);
1419  }
1420 
1421  //- Deprecated(2018-10)
1422  // \deprecated(2018-10) - use keyType::option version
1423  FOAM_DEPRECATED_FOR(2018-10, "lookupEntry(keyType::option)")
1424  const entry& lookupEntry
1425  (
1426  const word& keyword,
1427  bool recursive,
1428  bool patternMatch
1429  ) const
1430  {
1431  return lookupEntry(keyword, matchOpt(recursive, patternMatch));
1432  }
1433 
1434  //- Deprecated(2018-10)
1435  // \deprecated(2018-10) - use keyType::option version
1436  FOAM_DEPRECATED_FOR(2018-10, "lookup(keyType::option)")
1437  ITstream& lookup
1438  (
1439  const word& keyword,
1440  bool recursive,
1441  bool patternMatch = true
1442  ) const
1443  {
1444  return lookup(keyword, matchOpt(recursive, patternMatch));
1445  }
1446 
1447  //- Deprecated(2018-10)
1448  // \deprecated(2018-10) - use keyType::option version
1449  template<class T>
1450  FOAM_DEPRECATED_FOR(2018-10, "getOrDefault(keyType::option)")
1452  (
1453  const word& keyword,
1454  const T& deflt,
1455  bool recursive,
1456  bool patternMatch = true
1457  ) const
1458  {
1459  return getOrDefault(keyword, matchOpt(recursive, patternMatch));
1460  }
1461 
1462  //- Deprecated(2018-10)
1463  // \deprecated(2018-10) - use keyType::option version
1464  template<class T>
1465  FOAM_DEPRECATED_FOR(2018-10, "getOrAdd(keyType::option)")
1467  (
1468  const word& keyword,
1469  const T& deflt,
1470  bool recursive,
1471  bool patternMatch = true
1472  )
1473  {
1474  return getOrAdd(keyword, deflt, matchOpt(recursive, patternMatch));
1475  }
1476 
1477  //- Deprecated(2018-10)
1478  // \deprecated(2018-10) - use keyType::option version
1479  template<class T>
1480  FOAM_DEPRECATED_FOR(2018-10, "readIfPresent(keyType::option)")
1481  bool readIfPresent
1482  (
1483  const word& keyword,
1484  T& val,
1485  bool recursive,
1486  bool patternMatch = true
1487  ) const
1488  {
1489  return
1491  (keyword, val, matchOpt(recursive, patternMatch));
1492  }
1493 
1494 
1495  // More compatibility
1496 
1497  //- Deprecated(2018-10) find and return a T.
1498  // \deprecated(2018-10) - use get() method
1499  template<class T>
1500  FOAM_DEPRECATED_FOR(2018-10, "get() method")
1501  T lookupType
1502  (
1503  const word& keyword,
1504  bool recursive = false,
1505  bool patternMatch = true
1506  ) const
1507  {
1508  return get<T>(keyword, matchOpt(recursive, patternMatch));
1509  }
1510 
1511  #ifdef COMPAT_OPENFOAM_ORG
1512  // Only available if compiled with COMPAT_OPENFOAM_ORG
1514  template<class T>
1515  FOAM_DEPRECATED_FOR(2019-11, "get() method - openfoam.org compat")
1516  T lookup
1517  (
1518  const word& keyword,
1519  bool recursive = false,
1520  bool patternMatch = true
1521  ) const
1522  {
1523  return get<T>(keyword, matchOpt(recursive, patternMatch));
1524  }
1525  #endif
1526 };
1527 
1528 
1529 // Global Operators
1530 
1531 //- Combine dictionaries.
1532 // Starting from the entries in dict1 and then including those from dict2.
1533 // Warn, but do not overwrite the entries from dict1.
1534 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
1535 
1536 //- Combine dictionaries.
1537 // Starting from the entries in dict1 and then including those from dict2.
1538 // Do not overwrite the entries from dict1.
1539 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
1540 
1541 
1542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1543 
1544 } // End namespace Foam
1545 
1546 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1547 
1548 #include "dictionaryI.H"
1549 
1550 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1551 
1552 #ifdef NoRepository
1553  #include "dictionaryTemplates.C"
1554 #endif
1555 
1556 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1557 
1558 #endif
1559 
1560 // ************************************************************************* //
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
Reference the found entry as a dictionary.
Definition: dictionary.H:278
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:1666
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:1740
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:302
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:268
Template class for non-intrusive linked lists.
Definition: LList.H:46
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
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:1697
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:1681
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:694
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:1664
constexpr Searcher() noexcept
Default construct.
Definition: dictionary.H:225
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 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:317
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:479
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:235
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:474
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:1772
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:1667
scalar getScalar(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get< scalar >(const word&, keyType::option)
Definition: dictionary.H:1665
#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.
T & reference
Reference for value_type.
Definition: UILList.H:88
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:312
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:469
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
Find a sub-dictionary.
Definition: dictionaryI.H:144
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.
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:1652
const dictionary * subDictPtr(const word &keyword) const
Deprecated(2018-10)
Definition: dictionary.H:1791
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:325
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:1910
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:1668
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:294
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:1663
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 a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124