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