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