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-2019 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  //- Construct null
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 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  //- Construct top-level dictionary null
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 the keyword as its header
941  void writeEntry(const keyType& keyword, Ostream& os) const;
942 
943  //- Write dictionary entries.
944  // \param extraNewLine adds additional newline\n between entries
945  // for "top-level" dictionaries
946  void writeEntries(Ostream& os, const bool extraNewLine=false) const;
947 
948  //- Write dictionary, normally with sub-dictionary formatting
949  void write(Ostream& os, const bool subDict=true) const;
950 
951 
952  // Searching
953 
954  //- Search dictionary for given keyword
955  // Default search: non-recursive with patterns.
956  //
957  // \param recursive search parent dictionaries
958  // \param patternMatch use regular expressions
960  (
961  const word& keyword,
963  ) const;
964 
965  //- Search dictionary for given keyword
966  // Default search: non-recursive with patterns.
967  //
968  // \param recursive search parent dictionaries
969  // \param patternMatch use regular expressions
971  (
972  const word& keyword,
974  ) const;
975 
976  //- Search dictionary for given keyword
977  // Default search: non-recursive with patterns.
978  //
979  // \param recursive search parent dictionaries
980  // \param patternMatch use regular expressions
982  (
983  const word& keyword,
985  );
986 
987  //- Search using scoping.
988  // There are two types of scoping available:
989  // -# dot-scoping, where a '.' is used to delineate the scope
990  // -# slash-scoping, where a '/' is used to delineate the scope
991  //
992  // For dot-scoping, a leading '^' traverses to the top-level
993  // dictionary, leading dots mean use the parent dictionary and an
994  // intermediate dot separates a sub-dictionary or sub-entry.
995  // However, since the use of dots is ambiguous ("a.b.c" could be
996  // an entry itself or represent a "bc" entry from dictionary "a" etc),
997  // the heuristic backtracks and attempts successively longer
998  // top-level entries until a suitable match is found.
999  //
1000  // For slash-scoping, semantics similar to directory structures are
1001  // used. A leading '/' traverses to the top-level dictionary,
1002  // a single leading or intermediate '.' references the current
1003  // dictionary level. A '..' pair references the parent dictionary.
1004  // Any doubled slashes are silently ignored.
1005  // Since a slash is not a valid keyword character, there is no
1006  // ambiguity between separator and content.
1007  //
1008  // \param recursive search parent dictionaries
1009  // \param patternMatch use regular expressions
1011  (
1012  const word& keyword,
1013  enum keyType::option
1014  ) const;
1015 
1016  //- Search using dot or slash scoping.
1017  //
1018  // \param recursive search parent dictionaries
1019  // \param patternMatch use regular expressions
1021  (
1022  const word& keyword,
1023  enum keyType::option
1024  ) const;
1025 
1026  //- Search using dot or slash scoping.
1027  //
1028  // \param recursive search parent dictionaries
1029  // \param patternMatch use regular expressions
1031  (
1032  const word& keyword,
1033  enum keyType::option
1034  );
1035 
1036  //- Locate a sub-dictionary using slash-scoping
1037  // \return nullptr if the dictionary path does not exist
1038  const dictionary* cfindScopedDict(const fileName& dictPath) const;
1039 
1040  //- Locate a sub-dictionary using slash-scoping
1041  // \return nullptr if the dictionary path does not exist
1042  const dictionary* findScopedDict(const fileName& dictPath) const;
1043 
1044  //- Locate a sub-dictionary using slash-scoping
1045  // \return nullptr if the dictionary path does not exist
1046  dictionary* findScopedDict(const fileName& dictPath);
1047 
1048  //- Locate existing or create sub-dictionary using slash-scoping
1049  // \return nullptr if the dictionary path could not be created
1050  dictionary* makeScopedDict(const fileName& dictPath);
1051 
1052 
1053  // Compatibility helpers
1054 
1055  //- Search dictionary for given keyword and any compatibility names
1056  // Default search: non-recursive with patterns.
1057  //
1058  // \param compat list of old compatibility keywords and the last
1059  // OpenFOAM version for which they were used.
1060  // Old version 1600=OpenFOAM-v3.0, 240=OpenFOAM-2.4.x,
1061  // 170=OpenFOAM-1.7.x,...
1062  //
1063  // \param recursive search parent dictionaries
1064  // \param patternMatch use regular expressions
1066  (
1067  const word& keyword,
1068  std::initializer_list<std::pair<const char*,int>> compat,
1070  ) const;
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  // \param recursive search parent dictionaries
1078  // \param patternMatch use regular expressions
1079  bool foundCompat
1080  (
1081  const word& keyword,
1082  std::initializer_list<std::pair<const char*,int>> compat,
1084  ) const;
1085 
1086  //- Find and return an entry pointer if present, or return a nullptr,
1087  //- using any compatibility names if needed.
1088  //
1089  // \param compat list of old compatibility keywords and the last
1090  // OpenFOAM version for which they were used.
1091  // \param recursive search parent dictionaries
1092  // \param patternMatch use regular expressions
1093  const entry* findCompat
1094  (
1095  const word& keyword,
1096  std::initializer_list<std::pair<const char*,int>> compat,
1097  enum keyType::option
1098  ) const;
1099 
1100  //- Find and return an entry if present, otherwise FatalIOError,
1101  //- using any compatibility names if needed.
1102  //
1103  // \param compat list of old compatibility keywords and the last
1104  // OpenFOAM version for which they were used.
1105  // \param recursive search parent dictionaries
1106  // \param patternMatch use regular expressions
1107  const entry& lookupEntryCompat
1108  (
1109  const word& keyword,
1110  std::initializer_list<std::pair<const char*,int>> compat,
1111  enum keyType::option
1112  ) const;
1113 
1114  //- Find and return an entry data stream,
1115  //- using any compatibility names if needed.
1116  // Default search: non-recursive with patterns.
1117  //
1118  // \param compat list of old compatibility keywords and the last
1119  // OpenFOAM version for which they were used.
1120  // \param recursive search parent dictionaries
1121  // \param patternMatch use regular expressions
1123  (
1124  const word& keyword,
1125  std::initializer_list<std::pair<const char*,int>> compat,
1127  ) const;
1128 
1129  //- Find and return a T
1130  //- using any compatibility names if needed.
1131  //- FatalIOError if not found, or if there are excess tokens.
1132  // Default search: non-recursive with patterns.
1133  //
1134  // \param compat list of old compatibility keywords and the last
1135  // OpenFOAM version for which they were used.
1136  // \param recursive search parent dictionaries
1137  // \param patternMatch use regular expressions
1138  template<class T>
1139  T getCompat
1140  (
1141  const word& keyword,
1142  std::initializer_list<std::pair<const char*,int>> compat,
1144  ) const;
1145 
1146  //- Find and return a T, or return the given default value
1147  //- using any compatibility names if needed.
1148  // Default search: non-recursive with patterns.
1149  //
1150  // \param compat list of old compatibility keywords and the last
1151  // OpenFOAM version for which they were used.
1152  // \param recursive search parent dictionaries
1153  // \param patternMatch use regular expressions
1154  template<class T>
1156  (
1157  const word& keyword,
1158  std::initializer_list<std::pair<const char*,int>> compat,
1159  const T& deflt,
1161  ) const;
1162 
1163  //- Find entry and assign to T val
1164  //- using any compatibility names if needed.
1165  //- FatalIOError if there are excess tokens.
1166  // Default search: non-recursive with patterns.
1167  //
1168  // \param compat list of old compatibility keywords and the last
1169  // OpenFOAM version for which they were used.
1170  // \param val the value to read
1171  // \param recursive search parent dictionaries
1172  // \param patternMatch use regular expressions
1173  //
1174  // \return true if the entry was found.
1175  template<class T>
1176  bool readCompat
1177  (
1178  const word& keyword,
1179  std::initializer_list<std::pair<const char*,int>> compat,
1180  T& val,
1182  bool mandatory = true
1183  ) const;
1184 
1185  //- Find an entry if present, and assign to T val
1186  //- using any compatibility names if needed.
1187  //- FatalIOError if it is found and there are excess tokens.
1188  // Default search: non-recursive with patterns.
1189  //
1190  // \param compat list of old compatibility keywords and the last
1191  // OpenFOAM version for which they were used.
1192  // \param val the value to read
1193  // \param recursive search parent dictionaries
1194  // \param patternMatch use regular expressions
1195  //
1196  // \return true if the entry was found.
1197  template<class T>
1198  bool readIfPresentCompat
1199  (
1200  const word& keyword,
1201  std::initializer_list<std::pair<const char*,int>> compat,
1202  T& val,
1204  ) const;
1205 
1206 
1207  // Member Operators
1208 
1209  //- Copy assignment
1210  void operator=(const dictionary& rhs);
1211 
1212  //- Include entries from the given dictionary.
1213  // Warn, but do not overwrite existing entries.
1214  void operator+=(const dictionary& rhs);
1215 
1216  //- Conditionally include entries from the given dictionary.
1217  // Do not overwrite existing entries.
1218  void operator|=(const dictionary& rhs);
1219 
1220  //- Unconditionally include entries from the given dictionary.
1221  // Overwrite existing entries.
1222  void operator<<=(const dictionary& rhs);
1223 
1224 
1225  // IOstream operators
1226 
1227  //- Read dictionary from Istream
1228  friend Istream& operator>>(Istream& is, dictionary& dict);
1229 
1230  //- Write dictionary to Ostream
1231  friend Ostream& operator<<(Ostream& os, const dictionary& dict);
1232 
1233 
1234  // Housekeeping
1235 
1236  //- Find and return a T, or return the given default value.
1237  //- FatalIOError if it is found and the number of tokens is incorrect.
1238  //
1239  // \param matchOpt the default search is non-recursive with patterns
1240  template<class T>
1242  (
1243  const word& keyword,
1244  const T& deflt,
1245  enum keyType::option matchOpt = keyType::REGEX
1246  ) const
1247  {
1248  return getOrDefault<T>(keyword, deflt, matchOpt);
1249  }
1250 
1251 
1252  //- Find and return a T, or return the given default value
1253  //- and add it to dictionary.
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  )
1264  {
1265  return getOrAdd<T>(keyword, deflt, matchOpt);
1266  }
1267 
1268  //- Find and return a T, or return the given default value
1269  //- using any compatibility names if needed.
1270  // Default search: non-recursive with patterns.
1271  //
1272  // \param compat list of old compatibility keywords and the last
1273  // OpenFOAM version for which they were used.
1274  // \param recursive search parent dictionaries
1275  // \param patternMatch use regular expressions
1276  template<class T>
1278  (
1279  const word& keyword,
1280  std::initializer_list<std::pair<const char*,int>> compat,
1281  const T& deflt,
1282  enum keyType::option matchOpt = keyType::REGEX
1283  ) const
1284  {
1285  return getOrDefaultCompat<T>(keyword, compat, deflt, matchOpt);
1286  }
1287 
1288  //- Deprecated(2018-07) find and return an entry data stream
1289  //
1290  // \deprecated(2018-07) - use lookup() method
1291  ITstream& FOAM_DEPRECATED_FOR(2018-07, "lookup() method")
1292  operator[](const word& keyword) const
1293  {
1294  return lookup(keyword);
1295  }
1296 
1297  //- Deprecated(2018-10) find and return a T.
1298  // \deprecated(2018-10) - use get() method
1299  template<class T>
1300  T FOAM_DEPRECATED_FOR(2018-10, "get() method")
1301  lookupType
1302  (
1303  const word& keyword,
1304  bool recursive = false,
1305  bool patternMatch = true
1306  ) const
1307  {
1308  return get<T>(keyword, matchOpt(recursive, patternMatch));
1309  }
1310 
1311  //- Deprecated(2018-10)
1312  // \deprecated(2018-10) - use keyType::option version
1313  bool FOAM_DEPRECATED_FOR(2018-10, "found(keyType::option)")
1314  found
1315  (
1316  const word& keyword,
1317  bool recursive,
1318  bool patternMatch = true
1319  ) const
1320  {
1321  return found(keyword, matchOpt(recursive, patternMatch));
1322  }
1323 
1324  //- Deprecated(2018-10)
1325  // \deprecated(2018-10) - use keyType::option version
1326  entry*
1327  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1328  lookupEntryPtr
1329  (
1330  const word& keyword,
1331  bool recursive,
1332  bool patternMatch
1333  )
1334  {
1335  return findEntry(keyword, matchOpt(recursive, patternMatch));
1336  }
1337 
1338  //- Deprecated(2018-10)
1339  // \deprecated(2018-10) - use keyType::option version
1340  const entry*
1341  FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1342  lookupEntryPtr
1343  (
1344  const word& keyword,
1345  bool recursive,
1346  bool patternMatch
1347  ) const
1348  {
1349  return findEntry(keyword, matchOpt(recursive, patternMatch));
1350  }
1351 
1352  //- Deprecated(2018-10)
1353  // \deprecated(2018-10) - use keyType::option version
1354  const entry*
1355  FOAM_DEPRECATED_FOR(2018-10, "findScoped(keyType::option)")
1356  lookupScopedEntryPtr
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  const dictionary*
1373  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1374  subDictPtr(const word& keyword) const
1375  {
1376  return findDict(keyword, keyType::REGEX);
1377  }
1378 
1379  //- Deprecated(2018-10)
1380  //- Find and return a sub-dictionary pointer if present
1381  // (and a sub-dictionary) otherwise return nullptr.
1382  //
1383  // Search type: non-recursive with patterns.
1384  // \deprecated(2018-10) - use findDict() method
1385  dictionary*
1386  FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1387  subDictPtr(const word& keyword)
1388  {
1389  return findDict(keyword, keyType::REGEX);
1390  }
1391 
1392  //- Deprecated(2018-10)
1393  // \deprecated(2018-10) - use keyType::option version
1394  const entry&
1395  FOAM_DEPRECATED_FOR(2018-10, "lookupEntry(keyType::option)")
1396  lookupEntry
1397  (
1398  const word& keyword,
1399  bool recursive,
1400  bool patternMatch
1401  ) const
1402  {
1403  return lookupEntry(keyword, matchOpt(recursive, patternMatch));
1404  }
1405 
1406  //- Deprecated(2018-10)
1407  // \deprecated(2018-10) - use keyType::option version
1408  ITstream&
1409  FOAM_DEPRECATED_FOR(2018-10, "lookup(keyType::option)")
1410  lookup
1411  (
1412  const word& keyword,
1413  bool recursive,
1414  bool patternMatch = true
1415  ) const
1416  {
1417  return lookup(keyword, matchOpt(recursive, patternMatch));
1418  }
1419 
1420  //- Deprecated(2018-10)
1421  // \deprecated(2018-10) - use keyType::option version
1422  template<class T>
1423  T FOAM_DEPRECATED_FOR(2018-10, "lookupOrDefault(keyType::option)")
1425  (
1426  const word& keyword,
1427  const T& deflt,
1428  bool recursive,
1429  bool patternMatch = true
1430  ) const
1431  {
1432  return
1434  (keyword, matchOpt(recursive, patternMatch));
1435  }
1436 
1437  //- Deprecated(2018-10)
1438  // \deprecated(2018-10) - use keyType::option version
1439  template<class T>
1440  T FOAM_DEPRECATED_FOR(2018-10, "lookupOrAddDefault(keyType::option)")
1442  (
1443  const word& keyword,
1444  const T& deflt,
1445  bool recursive,
1446  bool patternMatch = true
1447  )
1448  {
1449  return
1451  (keyword, deflt, matchOpt(recursive, patternMatch));
1452  }
1453 
1454  //- Deprecated(2018-10)
1455  // \deprecated(2018-10) - use keyType::option version
1456  template<class T>
1457  bool
1458  FOAM_DEPRECATED_FOR(2018-10, "readIfPresent(keyType::option)")
1460  (
1461  const word& keyword,
1462  T& val,
1463  bool recursive,
1464  bool patternMatch = true
1465  ) const
1466  {
1467  return
1469  (keyword, val, matchOpt(recursive, patternMatch));
1470  }
1471 
1472 
1473  // Shortcuts - when a templated classes also inherits from a dictionary
1474 
1475  #undef defineDictionaryGetter
1476  #define defineDictionaryGetter(Func, Type) \
1477  \
1478  Type Func \
1479  ( \
1480  const word& keyword, \
1481  enum keyType::option matchOpt = keyType::REGEX \
1482  ) const \
1483  { \
1484  return get<Type>(keyword, matchOpt); \
1485  }
1486 
1487  defineDictionaryGetter(getBool, bool);
1493 
1494  #undef defineDictionaryGetter
1495 };
1496 
1497 
1498 // Global Operators
1499 
1500 //- Combine dictionaries.
1501 // Starting from the entries in dict1 and then including those from dict2.
1502 // Warn, but do not overwrite the entries from dict1.
1503 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
1504 
1505 //- Combine dictionaries.
1506 // Starting from the entries in dict1 and then including those from dict2.
1507 // Do not overwrite the entries from dict1.
1508 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
1509 
1510 
1511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1512 
1513 } // End namespace Foam
1514 
1515 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1516 
1517 #ifdef NoRepository
1518  #include "dictionaryTemplates.C"
1519 #endif
1520 
1521 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1522 
1523 #endif
1524 
1525 // ************************************************************************* //
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:503
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::val
label ListType::const_reference val
Definition: ListOps.H:407
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::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:1277
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:1488
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::FOAM_DEPRECATED_FOR
ITstream & FOAM_DEPRECATED_FOR(2018-07, "lookup() method") operator[](const word &keyword) const
Deprecated(2018-07) find and return an entry data stream.
Definition: dictionary.H:1290
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:359
Foam::dictionary::checkITstream
void checkITstream(const ITstream &is, const word &keyword) const
Definition: dictionary.C:258
Foam::dictionary::dictionary
dictionary()
Construct top-level dictionary null.
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:980
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:1489
Foam::dictionary::lookupOrAddDefault
T lookupOrAddDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Definition: dictionary.H:1258
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:228
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:842
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
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:399
Foam::dictionary::operator+=
void operator+=(const dictionary &rhs)
Include entries from the given dictionary.
Definition: dictionary.C:963
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:563
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:429
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:928
Foam::dictionary::Searcher::context
dict_reference context() const
The containing dictionary context.
Definition: dictionary.H:210
Foam::dictionary::recursive
T bool recursive
Definition: dictionary.H:1303
Foam::dictionary::keys
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:685
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:1491
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::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:1000
Foam::dictionary::merge
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:874
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(const keyType &keyword, Ostream &os) const
Write sub-dictionary with the keyword as its header.
Definition: dictionaryIO.C:164
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:523
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::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:419
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:172
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()
Construct null.
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:1490
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:603
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:1487
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::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:493
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
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:389
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:198
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: HashTable.H:102
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)
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:943
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:369
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
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::dictionary::substituteScopedKeyword
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by '$')
Definition: dictionary.C:461
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:640
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:703
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:665
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::patternMatch
T bool bool patternMatch
Definition: dictionary.H:1304
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::operator|
bitSet operator|(const bitSet &a, const bitSet &b)
Bitwise-OR of two bitsets.
Definition: bitSetI.H:750
Foam::dictionary::searcher
friend searcher
Definition: dictionary.H:280
Foam::dictionary::clear
void clear()
Clear the dictionary.
Definition: dictionary.C:919
Foam::dictionary::sortedToc
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:679
Foam::dictionary::Searcher::ref
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:222
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
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