dictionary.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::dictionary
26 
27 Description
28  A list of keywords followed by any number of values (e.g. words and
29  numbers) or sub-dictionaries
30 
31  The keywords can represent patterns which are matched using Posix regular
32  expressions. The general order for searching is as follows:
33  - exact match
34  - pattern match (in reverse order)
35  - optional recursion into the enclosing (parent) dictionaries
36 
37  The dictionary class is the base class for IOdictionary.
38  It also serves as a bootstrap dictionary for the objectRegistry data
39  dictionaries since, unlike the IOdictionary class, it does not use an
40  objectRegistry itself to work.
41 
42 SourceFiles
43  dictionaryStatics.C
44  dictionary.C
45  dictionaryIO.C
46  dictionaryTemplates.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef dictionary_H
51 #define dictionary_H
52 
53 #include "className.H"
54 #include "entry.H"
55 #include "IDLList.H"
56 #include "DLList.H"
57 #include "ITstream.H"
58 #include "Pair.H"
59 #include "fieldTypes.H"
60 #include "Tuple3.H"
61 #include <tuple>
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace Foam
66 {
67 
68 // Forward declaration of friend functions and operators
69 class dictionary;
70 class primitiveEntry;
71 class regExp;
72 class SHA1Digest;
73 
74 Istream& operator>>(Istream&, dictionary&);
75 Ostream& operator<<(Ostream&, const dictionary&);
76 
77 /*---------------------------------------------------------------------------*\
78  Class dictionaryName Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class dictionaryName
82 {
83  // Private Data
84 
85  fileName name_;
86 
87 
88 public:
89 
90  // Constructors
91 
92  //- Construct dictionaryName null
94  {}
95 
96  //- Construct dictionaryName as copy of the given fileName
98  :
99  name_(name)
100  {}
101 
102  //- Move constructor
104  :
105  name_(move(name.name_))
106  {}
107 
108 
109  // Member Functions
110 
111  //- Return the dictionary name
112  const fileName& name() const
113  {
114  return name_;
115  }
116 
117  //- Return the dictionary name
118  fileName& name()
119  {
120  return name_;
121  }
122 
123  //- Return the local dictionary name (final part of scoped name)
124  const word dictName() const
125  {
126  const word scopedName = name_.name();
127 
128  const string::size_type i = scopedName.find_last_of("/!");
129 
130  if (i == scopedName.npos)
131  {
132  return scopedName;
133  }
134  else
135  {
136  return scopedName.substr(i + 1, scopedName.npos);
137  }
138  }
139 
140 
141  // Member Operators
142 
143  void operator=(const dictionaryName& name)
144  {
145  name_ = name.name_;
146  }
147 
149  {
150  name_ = move(name.name_);
151  }
152 };
153 
154 
155 /*---------------------------------------------------------------------------*\
156  Class dictionary Declaration
157 \*---------------------------------------------------------------------------*/
158 
159 class dictionary
160 :
161  public dictionaryName,
162  public IDLList<entry>
163 {
164  // Private Data
165 
166  //- HashTable of the entries held on the DL-list for quick lookup
167  HashTable<entry*> hashedEntries_;
168 
169  //- Parent dictionary
170  const dictionary& parent_;
171 
172  //- Current stream/file pointer
173  mutable const Istream* filePtr_;
174 
175  //- Entries of matching patterns
176  DLList<entry*> patternEntries_;
177 
178  //- Patterns as precompiled regular expressions
179  DLList<autoPtr<regExp>> patternRegexps_;
180 
181 
182  // Private Member Functions
183 
184  //- Construct the path name from the name of the parent dictionary
185  // and the given name.
186  // A '/' separator is used unless the parent dictionary is top-level
187  // and hence has the name of the file in which case a '!' is used
188  static fileName pathName
189  (
190  const dictionary& parentDict,
191  const fileName& name
192  );
193 
194  //- Find and return an entry data stream pointer if present
195  // otherwise return nullptr.
196  // Allows scoping using '/' with special handling for '!' and '..'.
197  const entry* lookupScopedSubEntryPtr
198  (
199  const word&,
200  bool recursive,
201  bool patternMatch
202  ) const;
203 
204  //- Search patterns table for exact match or regular expression match
205  bool findInPatterns
206  (
207  const bool patternMatch,
208  const word& Keyword,
211  ) const;
212 
213  //- Search patterns table for exact match or regular expression match
214  bool findInPatterns
215  (
216  const bool patternMatch,
217  const word& Keyword,
218  DLList<entry*>::iterator& wcLink,
220  );
221 
222  //- Return true if there is a defaults dictionary corresponding to the
223  // given dictionary if printDictionary is active
224  static bool haveDefaults(const dictionary& dict);
225 
226  //- Return the defaults dictionary corresponding to the given dictionary
227  // if printDictionary is active
228  static dictionary& defaults(const dictionary& dict);
229 
230  //- Assign multiple entries, overwriting any existing entries
231  template<class ... Entries, size_t ... Indices>
232  void set
233  (
234  const std::tuple<const Entries& ...>&,
235  const std::integer_sequence<size_t, Indices ...>&
236  );
237 
238  //- Assign multiple entries, overwriting any existing entries
239  template<class ... Entries>
240  void set(const std::tuple<const Entries& ...>&);
241 
242 
243  // Private Classes
244 
245  //- ...
246  class includedDictionary;
247 
248 
249 public:
250 
251  //- Declare friendship with the entry class for IO
252  friend class entry;
253 
254 
255  // Declare name of the class and its debug switch
256  TypeName("dictionary");
257 
258 
259  // Public static data
260 
261  //- Null dictionary
262  static const dictionary null;
263 
264 
265  // Static Member Functions
266 
267  //- Construct an entries tuple from which to make a dictionary
268  template<class ... Entries>
269  static std::tuple<const Entries& ...> entries(const Entries& ...);
270 
271 
272  // Constructors
273 
274  //- Construct top-level dictionary null
275  dictionary();
276 
277  //- Construct top-level empty dictionary with given name
278  dictionary(const fileName& name);
279 
280  //- Construct an empty sub-dictionary with given name and parent
281  dictionary(const fileName& name, const dictionary& parentDict);
282 
283  //- Construct given the name, parent dictionary and Istream,
284  // reading entries until lastEntry or EOF
285  dictionary
286  (
287  const fileName& name,
288  const dictionary& parentDict,
289  Istream&
290  );
291 
292  //- Construct top-level dictionary from Istream,
293  // reading entries until EOF, optionally keeping the header
294  dictionary(Istream&, const bool keepHeader=false);
295 
296  //- Construct as copy given the parent dictionary
297  dictionary(const dictionary& parentDict, const dictionary&);
298 
299  //- Construct top-level dictionary as copy
300  dictionary(const dictionary&);
301 
302  //- Construct top-level dictionary as copy from pointer to dictionary.
303  // A null pointer is treated like an empty dictionary.
304  dictionary(const dictionary*);
305 
306  //- Construct top-level dictionary with given entries
307  template<class ... Entries>
308  dictionary(const std::tuple<const Entries& ...>&);
309 
310  //- Construct top-level dictionary with given name and entries
311  template<class ... Entries>
312  dictionary
313  (
314  const fileName& name,
315  const std::tuple<const Entries& ...>&
316  );
317 
318  //- Construct dictionary with given name, parent and entries
319  template<class ... Entries>
320  dictionary
321  (
322  const fileName& name,
323  const dictionary& parentDict,
324  const std::tuple<const Entries& ...>&
325  );
326 
327  //- Construct dictionary as copy and add a list of entries
328  template<class ... Entries>
329  dictionary
330  (
331  const dictionary& dict,
332  const std::tuple<const Entries& ...>&
333  );
334 
335  //- Construct and return clone
336  autoPtr<dictionary> clone() const;
337 
338  //- Construct top-level dictionary on freestore from Istream
340 
341 
342  //- Destructor
343  virtual ~dictionary();
344 
345 
346  // Member Functions
347 
348  //- Return the parent dictionary
349  const dictionary& parent() const
350  {
351  return parent_;
352  }
353 
354  //- Return whether this dictionary is null
355  bool isNull() const
356  {
357  return this == &null;
358  }
359 
360  //- Return the top of the tree
361  const dictionary& topDict() const;
362 
363  //- Return the scoped keyword with which this dictionary can be
364  // accessed from the top dictionary in the tree
365  word topDictKeyword() const;
366 
367  //- Return the dictionary name, or the name of the file if the
368  // dictionary is currently reading
369  const fileName& currentName() const;
370 
371  //- Return line number of first token in dictionary
372  virtual label startLineNumber() const;
373 
374  //- Return line number of last token in dictionary
375  virtual label endLineNumber() const;
376 
377  //- Return the SHA1 digest of the dictionary contents
378  SHA1Digest digest() const;
379 
380  //- Return the dictionary as a list of tokens
381  tokenList tokens() const;
382 
383 
384  // Search and lookup
385 
386  //- Search dictionary for given keyword
387  // If recursive, search parent dictionaries
388  // If patternMatch, use regular expressions
389  bool found
390  (
391  const word&,
392  bool recursive=false,
393  bool patternMatch=true
394  ) const;
395 
396  //- Find and return an entry data stream pointer if present
397  // otherwise return nullptr.
398  // If recursive, search parent dictionaries.
399  // If patternMatch, use regular expressions
400  const entry* lookupEntryPtr
401  (
402  const word&,
403  bool recursive,
404  bool patternMatch
405  ) const;
406 
407  //- Find and return an entry data stream pointer for manipulation
408  // if present otherwise return nullptr.
409  // If recursive, search parent dictionaries.
410  // If patternMatch, use regular expressions.
412  (
413  const word&,
414  bool recursive,
415  bool patternMatch
416  );
417 
418  //- Find and return an entry data stream if present, trying a list
419  // of keywords in sequence, otherwise return nullptr.
420  // If recursive, search parent dictionaries.
421  // If patternMatch, use regular expressions
423  (
424  const wordList&,
425  bool recursive,
426  bool patternMatch
427  ) const;
428 
429  //- Find and return an entry data stream if present otherwise error.
430  // If recursive, search parent dictionaries.
431  // If patternMatch, use regular expressions.
432  const entry& lookupEntry
433  (
434  const word&,
435  bool recursive,
436  bool patternMatch
437  ) const;
438 
439  //- Find and return an entry data stream if present, trying a list
440  // of keywords in sequence, otherwise error.
441  // If recursive, search parent dictionaries.
442  // If patternMatch, use regular expressions
444  (
445  const wordList&,
446  bool recursive,
447  bool patternMatch
448  ) const;
449 
450  //- Find and return an entry data stream
451  // If recursive, search parent dictionaries.
452  // If patternMatch, use regular expressions.
454  (
455  const word&,
456  bool recursive=false,
457  bool patternMatch=true
458  ) const;
459 
460  //- Find and return an entry data stream, trying a list of keywords
461  // in sequence
462  // if not found throw a fatal error relating to the first keyword
463  // If recursive, search parent dictionaries.
464  // If patternMatch, use regular expressions.
466  (
467  const wordList&,
468  bool recursive=false,
469  bool patternMatch=true
470  ) const;
471 
472  //- Find and return a T, if not found throw a fatal error.
473  // If recursive, search parent dictionaries.
474  // If patternMatch, use regular expressions.
475  template<class T>
476  T lookup
477  (
478  const word&,
479  bool recursive=false,
480  bool patternMatch=true
481  ) const;
482 
483  //- Find and return a T, with dimension checking and unit
484  // conversions, and if not found throw a fatal error.
485  // If recursive, search parent dictionaries.
486  // If patternMatch, use regular expressions.
487  template<class T, class DefaultUnits>
488  T lookup
489  (
490  const word&,
491  const DefaultUnits&,
492  bool recursive=false,
493  bool patternMatch=true
494  ) const;
495 
496  //- Find and return a T, trying a list of keywords in sequence,
497  // and if not found throw a fatal error relating to the first
498  // (preferred) keyword.
499  // If recursive, search parent dictionaries.
500  // If patternMatch, use regular expressions.
501  template<class T>
503  (
504  const wordList&,
505  bool recursive=false,
506  bool patternMatch=true
507  ) const;
508 
509  //- Find and return a T, with dimension checking and unit
510  // conversions, trying a list of keywords in sequence, and if not
511  // found throw a fatal error relating to the first (preferred)
512  // keyword.
513  // If recursive, search parent dictionaries.
514  // If patternMatch, use regular expressions.
515  template<class T, class DefaultUnits>
517  (
518  const wordList&,
519  const DefaultUnits&,
520  bool recursive=false,
521  bool patternMatch=true
522  ) const;
523 
524  //- Find and return a T, if not found return the given default
525  // value.
526  template<class T>
527  T lookupOrDefault(const word&, const T&) const;
528 
529  //- Find and return a T with dimension checking and unit
530  // conversions, and if not found return the given default value.
531  // If recursive, search parent dictionaries.
532  // If patternMatch, use regular expressions.
533  template<class T, class DefaultUnits>
534  T lookupOrDefault(const word&, const DefaultUnits&, const T&) const;
535 
536  //- Find and return a T, trying a list of keywords in sequence,
537  // and if not found throw a fatal error relating to the first
538  // (preferred) keyword
539  // If recursive, search parent dictionaries.
540  // If patternMatch, use regular expressions.
541  template<class T>
543  (
544  const wordList&,
545  const T&
546  ) const;
547 
548  //- Find and return a T, with dimension checking and unit
549  // conversions, trying a list of keywords in sequence, and if not
550  // found throw a fatal error relating to the first (preferred)
551  // keyword
552  // If recursive, search parent dictionaries.
553  // If patternMatch, use regular expressions.
554  template<class T, class DefaultUnits>
556  (
557  const wordList&,
558  const DefaultUnits&,
559  const T&
560  ) const;
561 
562  //- Find and return a T, if not found return the given
563  // default value, and add to dictionary.
564  // If recursive, search parent dictionaries.
565  // If patternMatch, use regular expressions.
566  template<class T>
568  (
569  const word&,
570  const T&
571  );
572 
573  //- Find an entry if present, and assign to T.
574  // Returns true if the entry was found.
575  // If recursive, search parent dictionaries.
576  // If patternMatch, use regular expressions.
577  template<class T>
578  bool readIfPresent
579  (
580  const word&,
581  T&,
582  bool recursive=false,
583  bool patternMatch=true
584  ) const;
585 
586  //- Find an entry if present, and assign to T, with dimension
587  // checking and unit conversions.
588  // Returns true if the entry was found.
589  // If recursive, search parent dictionaries.
590  // If patternMatch, use regular expressions.
591  template<class T, class DefaultUnits>
592  bool readIfPresent
593  (
594  const word&,
595  const DefaultUnits&,
596  T&,
597  bool recursive=false,
598  bool patternMatch=true
599  ) const;
600 
601  //- Find and return an entry data stream pointer if present,
602  // otherwise return nullptr.
603  // If recursive, search parent dictionaries.
604  // If patternMatch, use regular expressions.
605  // Allows scoping using '/' with special handling for '!' and '..'.
607  (
608  const word&,
609  bool recursive,
610  bool patternMatch
611  ) const;
612 
613  //- Find and return a T,
614  // if not found throw a fatal error.
615  // If recursive, search parent dictionaries.
616  // If patternMatch, use regular expressions.
617  // Allows scoping using '/' with special handling for '!' and '..'.
618  template<class T>
620  (
621  const word&,
622  bool recursive=false,
623  bool patternMatch=true
624  ) const;
625 
626  //- Find return the reference to the compound T,
627  // if not found or not a compound throw a fatal error.
628  // If recursive, search parent dictionaries.
629  // If patternMatch, use regular expressions.
630  // Allows scoping using '/' with special handling for '!' and '..'.
631  template<class T>
632  const T& lookupCompoundScoped
633  (
634  const word& keyword,
635  bool recursive,
636  bool patternMatch
637  ) const;
638 
639  //- Check if entry is a sub-dictionary
640  bool isDict(const word&) const;
641 
642  //- Find and return a sub-dictionary pointer if present
643  // otherwise return nullptr.
644  const dictionary* subDictPtr(const word&) const;
645 
646  //- Find and return a sub-dictionary pointer if present
647  // otherwise return nullptr.
648  dictionary* subDictPtr(const word&);
649 
650  //- Find and return a sub-dictionary
651  const dictionary& subDict(const word&) const;
652 
653  //- Find and return a sub-dictionary for manipulation
654  dictionary& subDict(const word&);
655 
656  //- Find and return a sub-dictionary, trying a list of keywords in
657  // sequence, otherwise error.
658  const dictionary& subDictBackwardsCompatible(const wordList&) const;
659 
660  //- Find and return a sub-dictionary
661  // or empty dictionary if the sub-dictionary does not exist
663  (
664  const word&,
665  const bool mustRead = false
666  ) const;
667 
668  //- Find and return a sub-dictionary if found
669  // otherwise return this dictionary
670  const dictionary& optionalSubDict(const word&) const;
671 
672  //- Find and return a type sub-dictionary
673  // looked-up from typeName with optional "Coeffs" appended
674  const dictionary& typeDict(const word& typeName) const;
675 
676  //- Find and return a type sub-dictionary
677  // looked-up from typeName with optional "Coeffs" appended
678  // or empty dictionary if the sub-dictionary does not exist
679  const dictionary& typeOrEmptyDict(const word& typeName) const;
680 
681  //- Find and return an optional type sub-dictionary
682  // looked-up from typeName with optional "Coeffs" appended
683  const dictionary& optionalTypeDict(const word& typeName) const;
684 
685  //- Find and return a sub-dictionary by scoped lookup
686  // i.e. the keyword may contain scope characters.
687  // If the keyword is null this dictionary is returned
688  const dictionary& scopedDict(const word&) const;
689 
690  //- Find and return a sub-dictionary by scoped lookup
691  // i.e. the keyword may contain scope characters.
692  // If the keyword is null this dictionary is returned
693  dictionary& scopedDict(const word&);
694 
695  //- Return the table of contents
696  wordList toc() const;
697 
698  //- Return the sorted table of contents
699  wordList sortedToc() const;
700 
701  //- Return the list of available keys or patterns
702  List<keyType> keys(bool patterns=false) const;
703 
704 
705  // Editing
706 
707  //- Substitute the given keyword prepended by '$' with the
708  // corresponding sub-dictionary entries
709  bool substituteKeyword(const word& keyword);
710 
711  //- Add a new entry
712  // With the merge option, dictionaries are interwoven and
713  // primitive entries are overwritten
714  bool add(entry*, bool mergeEntry=false);
715 
716  //- Add an entry
717  // With the merge option, dictionaries are interwoven and
718  // primitive entries are overwritten
719  void add(const entry&, bool mergeEntry=false);
720 
721  //- Add a word entry
722  // optionally overwrite an existing entry
723  void add(const keyType&, const word&, bool overwrite=false);
724 
725  //- Add a string entry
726  // optionally overwrite an existing entry
727  void add(const keyType&, const string&, bool overwrite=false);
728 
729  //- Add a label entry
730  // optionally overwrite an existing entry
731  void add(const keyType&, const label, bool overwrite=false);
732 
733  //- Add a scalar entry
734  // optionally overwrite an existing entry
735  void add(const keyType&, const scalar, bool overwrite=false);
736 
737  //- Add a dictionary entry
738  // optionally merge with an existing sub-dictionary
739  void add
740  (
741  const keyType&,
742  const dictionary&,
743  bool mergeEntry=false
744  );
745 
746  //- Add a T entry
747  // optionally overwrite an existing entry
748  template<class T>
749  void add(const keyType&, const T&, bool overwrite=false);
750 
751  //- Assign a new entry, overwrite any existing entry
752  void set(entry*);
753 
754  //- Assign a new entry, overwrite any existing entry
755  void set(const entry&);
756 
757  //- Assign a dictionary entry, overwrite any existing entry
758  void set(const keyType&, const dictionary&);
759 
760  //- Assign a dictionary entry, overwrite any existing entry
761  template<class ... Entries>
762  void set(const keyType&, const std::tuple<const Entries& ...>&);
763 
764  //- Assign a T entry, overwrite any existing entry
765  template<class T>
766  void set(const keyType&, const T&);
767 
768  //- Assign multiple entries, overwriting any existing entries
769  template<class ... Entries>
770  void set(const entry& e, const Entries& ...);
771 
772  //- Assign multiple T entries, overwriting any existing entries
773  template<class T, class ... Entries>
774  void set(const keyType&, const T&, const Entries& ...);
775 
776  //- Remove an entry specified by keyword
777  bool remove(const word&);
778 
779  //- Remove entries specified by keywords
780  void remove(const wordList&);
781 
782  //- Change the keyword for an entry,
783  // optionally forcing overwrite of an existing entry
784  bool changeKeyword
785  (
786  const keyType& oldKeyword,
787  const keyType& newKeyword,
788  bool forceOverwrite=false
789  );
790 
791  //- Merge entries from the given dictionary.
792  // Also merge sub-dictionaries as required.
793  bool merge(const dictionary&);
794 
795  //- Clear the dictionary
796  void clear();
797 
798  //- Transfer the contents of the argument and annul the argument.
799  void transfer(dictionary&);
800 
801 
802  // Read
803 
804  //- Read dictionary from Istream, optionally keeping the header
805  bool read(Istream&, const bool keepHeader=false);
806 
807  //- Return true if the dictionary global,
808  // i.e. the same on all processors.
809  // Defaults to false, must be overridden by global IO dictionaries
810  virtual bool global() const;
811 
812 
813  // Write
814 
815  //- Write dictionary, normally with sub-dictionary formatting
816  void write(Ostream&, const bool subDict=true) const;
817 
818 
819  // Member Operators
820 
821  //- Find and return entry
822  ITstream& operator[](const word&) const;
823 
824  void operator=(const dictionary&);
825 
826  //- Include entries from the given dictionary.
827  // Warn, but do not overwrite existing entries.
828  void operator+=(const dictionary&);
829 
830  //- Conditionally include entries from the given dictionary.
831  // Do not overwrite existing entries.
832  void operator|=(const dictionary&);
833 
834  //- Unconditionally include entries from the given dictionary.
835  // Overwrite existing entries.
836  void operator<<=(const dictionary&);
837 
838 
839  // IOstream Operators
840 
841  //- Read dictionary from Istream
842  friend Istream& operator>>(Istream&, dictionary&);
843 
844  //- Write dictionary to Ostream
845  friend Ostream& operator<<(Ostream&, const dictionary&);
846 };
847 
848 
849 // Private Classes
850 
852 :
853  public dictionary
854 {
855  // Private Data
856 
857  //- Global IO status inherited from the parent dictionary
858  bool global_;
859 
860 
861 public:
862 
863  // Constructors
864 
865  //- Construct an included dictionary for the given parent
866  // setting the "global" status dictionary without setting the parent
868  (
869  const fileName& fName,
870  const dictionary& parentDict
871  );
872 
873 
874  //- Destructor
875  virtual ~includedDictionary()
876  {}
877 
878 
879  // Member Functions
880 
881  //- Return true if the dictionary global,
882  // i.e. the same on all processors.
883  // Inherited from the parent dictionary into which this is included
884  virtual bool global() const
885  {
886  return global_;
887  }
888 };
889 
890 
891 // Global Operators
892 
893 //- Combine dictionaries.
894 // Starting from the entries in dict1 and then including those from dict2.
895 // Warn, but do not overwrite the entries from dict1.
896 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
897 
898 //- Combine dictionaries.
899 // Starting from the entries in dict1 and then including those from dict2.
900 // Do not overwrite the entries from dict1.
901 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
902 
903 
904 // Global Functions
905 
906 //- Parse dictionary substitution argument list
907 void dictArgList
908 (
909  const Tuple2<string, label>& argString,
910  word& configName,
913 );
914 
915 //- Parse dictionary substitution argument list
916 void dictArgList
917 (
918  const Tuple2<string, label>& argString,
921 );
922 
923 //- Extracts dict name and keyword
924 Pair<word> dictAndKeyword(const word& scopedName);
925 
926 //- Return the list of configuration files in
927 // user/group/shipped directories.
928 // The search scheme allows for version-specific and
929 // version-independent files using the following hierarchy:
930 // - \b user settings:
931 // - ~/.OpenFOAM/<VERSION>/caseDicts/functions
932 // - ~/.OpenFOAM/caseDicts/functions
933 // - \b group (site) settings (when $WM_PROJECT_SITE is set):
934 // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/functions
935 // - $WM_PROJECT_SITE/etc/caseDicts/functions
936 // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
937 // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
938 // caseDicts/functions
939 // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/functions
940 // - \b other (shipped) settings:
941 // - $WM_PROJECT_DIR/etc/caseDicts/functions
943 (
944  const fileName& configFilesPath
945 );
946 
947 //- Search for configuration file for given region
948 // and if not present also search the case directory as well as the
949 // user/group/shipped directories.
950 // The search scheme allows for version-specific and
951 // version-independent files using the following hierarchy:
952 // - \b user settings:
953 // - ~/.OpenFOAM/<VERSION>/caseDicts/functions
954 // - ~/.OpenFOAM/caseDicts/functions
955 // - \b group (site) settings (when $WM_PROJECT_SITE is set):
956 // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/functions
957 // - $WM_PROJECT_SITE/etc/caseDicts/functions
958 // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
959 // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
960 // caseDicts/functions
961 // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/functions
962 // - \b other (shipped) settings:
963 // - $WM_PROJECT_DIR/etc/caseDicts/functions
964 //
965 // \return The path of the configuration file if found
966 // otherwise null
968 (
969  const word& configName,
970  const fileName& configFilesPath,
971  const word& configFilesDir,
972  const word& region = word::null
973 );
974 
975 //- Expand arg within the dict context and return
976 string expandArg
977 (
978  const string& arg,
979  dictionary& dict,
980  const label lineNumber
981 );
982 
983 //- Add the keyword value pair to dict
984 // setting the given lineNumber for the entry
985 void addArgEntry
986 (
987  dictionary& dict,
988  const word& keyword,
989  const string& value,
990  const label lineNumber
991 );
992 
993 //- Read the specified configuration file
994 // parsing the optional arguments included in the string
995 // 'argString', inserting 'field' or 'fields' entries as required
996 // and merging the resulting configuration dictionary into
997 // 'parentDict'.
998 //
999 // Parses the optional arguments:
1000 // 'Q(U)' -> configFileName = Q; args = (U)
1001 // -> field U;
1002 //
1003 // Supports named arguments:
1004 // 'patchAverage(patch=inlet, p,U)'
1005 // or
1006 // 'patchAverage(patch=inlet, field=(p U))'
1007 // -> configFileName = patchAverage;
1008 // args = (patch=inlet, p,U)
1009 // -> patch inlet;
1010 // fields (p U);
1011 bool readConfigFile
1012 (
1013  const word& configType,
1014  const Tuple2<string, label>& argString,
1015  dictionary& parentDict,
1016  const fileName& configFilesPath,
1017  const word& configFilesDir,
1018  const word& region = word::null,
1019  const string& command = string::null
1020 );
1021 
1022 //- Write a dictionary entry
1023 void writeEntry(Ostream& os, const dictionary& dict);
1024 
1025 //- Helper function to write the keyword and entry
1026 template<class EntryType>
1027 void writeEntry(Ostream& os, const word& entryName, const EntryType& value);
1028 
1029 //- Helper function to write the keyword and entry
1030 template<class EntryType, class DefaultUnits>
1031 void writeEntry
1032 (
1033  Ostream& os,
1034  const word& entryName,
1035  const DefaultUnits& defaultUnits,
1036  const EntryType& value
1037 );
1038 
1039 //- Helper function to write the keyword and entry only if the
1040 // values are not equal. The value is then output as value2
1041 template<class EntryType>
1043 (
1044  Ostream& os,
1045  const word& entryName,
1046  const EntryType& value1,
1047  const EntryType& value2
1048 );
1049 
1050 //- Helper function to write the keyword and entry only if the
1051 // values are not equal. The value is then output as value2
1052 template<class EntryType, class DefaultUnits>
1054 (
1055  Ostream& os,
1056  const word& entryName,
1057  const DefaultUnits& defaultUnits,
1058  const EntryType& value1,
1059  const EntryType& value2
1060 );
1061 
1062 
1063 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1064 
1065 } // End namespace Foam
1066 
1067 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1068 
1069 #ifdef NoRepository
1070  #include "dictionaryTemplates.C"
1071 #endif
1072 
1073 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1074 
1075 #endif
1076 
1077 // ************************************************************************* //
Non-intrusive doubly-linked list.
Intrusive doubly-linked list.
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
An STL-conforming hash table.
Definition: HashTable.H:127
Template class for intrusive linked lists.
Definition: ILList.H:67
Input token stream.
Definition: ITstream.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An STL-conforming const_iterator.
Definition: LList.H:300
An STL-conforming iterator.
Definition: LList.H:249
Template class for non-intrusive linked lists.
Definition: LList.H:76
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
The SHA1 message digest.
Definition: SHA1Digest.H:63
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
A 3-tuple for storing three objects of different types.
Definition: Tuple3.H:60
An STL-conforming const_iterator.
Definition: UILList.H:237
An STL-conforming iterator.
Definition: UILList.H:188
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:123
void operator=(const dictionaryName &name)
Definition: dictionary.H:142
dictionaryName()
Construct dictionaryName null.
Definition: dictionary.H:92
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
includedDictionary(const fileName &fName, const dictionary &parentDict)
Construct an included dictionary for the given parent.
Definition: dictionaryIO.C:69
virtual ~includedDictionary()
Destructor.
Definition: dictionary.H:874
virtual bool global() const
Return true if the dictionary global,.
Definition: dictionary.H:883
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:341
ITstream & operator[](const word &) const
Find and return entry.
Definition: dictionary.C:1382
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:255
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:327
virtual bool global() const
Return true if the dictionary global,.
Definition: dictionaryIO.C:159
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1448
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1367
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Definition: dictionaryIO.C:105
const dictionary & subDictBackwardsCompatible(const wordList &) const
Find and return a sub-dictionary, trying a list of keywords in.
Definition: dictionary.C:809
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:507
const dictionary & subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary.
Definition: dictionary.C:829
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
Definition: dictionary.C:1224
const dictionary & typeDict(const word &typeName) const
Find and return a type sub-dictionary.
Definition: dictionary.C:874
T lookupOrAddDefault(const word &, const T &)
Find and return a T, if not found return the given.
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:448
const fileName & currentName() const
Return the dictionary name, or the name of the file if the.
Definition: dictionary.C:376
bool substituteKeyword(const word &keyword)
Substitute the given keyword prepended by '$' with the.
Definition: dictionaryIO.C:172
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:214
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:626
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:1001
T lookupOrDefaultBackwardsCompatible(const wordList &, const T &) const
Find and return a T, trying a list of keywords in sequence,.
void operator+=(const dictionary &)
Include entries from the given dictionary.
Definition: dictionary.C:1411
TypeName("dictionary")
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:856
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present,.
Definition: dictionary.C:696
word topDictKeyword() const
Return the scoped keyword with which this dictionary can be.
Definition: dictionary.C:356
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:1182
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:732
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:348
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:778
const entry & lookupEntryBackwardsCompatible(const wordList &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present, trying a list.
Definition: dictionary.C:647
virtual label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:414
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:995
const dictionary & typeOrEmptyDict(const word &typeName) const
Find and return a type sub-dictionary.
Definition: dictionary.C:898
friend Istream & operator>>(Istream &, dictionary &)
Read dictionary from Istream.
const entry * lookupEntryPtrBackwardsCompatible(const wordList &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present, trying a list.
Definition: dictionary.C:590
bool isNull() const
Return whether this dictionary is null.
Definition: dictionary.H:354
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:1428
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1019
void clear()
Clear the dictionary.
Definition: dictionary.C:1358
virtual ~dictionary()
Destructor.
Definition: dictionary.C:335
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:680
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:748
void operator=(const dictionary &)
Definition: dictionary.C:1388
wordList toc() const
Return the table of contents.
Definition: dictionary.C:981
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:468
const T & lookupCompoundScoped(const word &keyword, bool recursive, bool patternMatch) const
Find return the reference to the compound T,.
const dictionary & scopedDict(const word &) const
Find and return a sub-dictionary by scoped lookup.
Definition: dictionary.C:943
virtual label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:401
friend Ostream & operator<<(Ostream &, const dictionary &)
Write dictionary to Ostream.
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:97
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1313
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
const dictionary & optionalTypeDict(const word &typeName) const
Find and return an optional type sub-dictionary.
Definition: dictionary.C:921
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:434
T lookupScoped(const word &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
A class for handling file names.
Definition: fileName.H:82
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
A class for handling keywords in dictionaries.
Definition: keyType.H:69
static const string null
An empty string.
Definition: string.H:88
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Include the header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
fileName findConfigFile(const word &configName, const fileName &configFilesPath, const word &configFilesDir, const word &region=word::null)
Search for configuration file for given region.
Definition: dictionaryIO.C:361
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
void dictArgList(const Tuple2< string, label > &argString, word &configName, List< Tuple2< wordRe, label >> &args, List< Tuple3< word, string, label >> &namedArgs)
Parse dictionary substitution argument list.
Definition: dictionary.C:1494
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:59
wordList listAllConfigFiles(const fileName &configFilesPath)
Return the list of configuration files in.
Definition: dictionaryIO.C:418
tmp< DimensionedField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, Field > > operator+(const DimensionedField< Type1, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< Type2, GeoMesh, PrimitiveField2 > &df2)
const fvMesh & region(const dictionary &dict)
Cast the give dictionary to the corresponding region fvMesh.
Definition: fvMesh.C:1834
Pair< word > dictAndKeyword(const word &scopedName)
Extracts dict name and keyword.
Definition: dictionary.C:1683
void addArgEntry(dictionary &dict, const word &keyword, const string &value, const label lineNumber)
Add the keyword value pair to dict.
Definition: dictionaryIO.C:456
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
HashSet< Key, Hash > operator|(const HashSet< Key, Hash > &hash1, const HashSet< Key, Hash > &hash2)
Combine entries from HashSets.
string expandArg(const string &arg, dictionary &dict, const label lineNumber)
Expand arg within the dict context and return.
Definition: dictionaryIO.C:436
bool readConfigFile(const word &configType, const Tuple2< string, label > &argString, dictionary &parentDict, const fileName &configFilesPath, const word &configFilesDir, const word &region=word::null, const string &command=string::null)
Read the specified configuration file.
Definition: dictionaryIO.C:482
dictionary dict
const bool overwrite
Definition: setNoOverwrite.H:1
Foam::argList args(argc, argv)