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