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-2024 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 keyword definitions, which are a keyword followed by any number
29  of values (e.g. words and numbers). The keywords can represent patterns
30  which are matched using Posix regular expressions. The general order for
31  searching is as follows:
32  - exact match
33  - pattern match (in reverse order)
34  - optional recursion into the enclosing (parent) dictionaries
35 
36  The dictionary class is the base class for IOdictionary.
37  It also serves as a bootstrap dictionary for the objectRegistry data
38  dictionaries since, unlike the IOdictionary class, it does not use an
39  objectRegistry itself to work.
40 
41  To add - a merge() member function with a non-const dictionary parameter?
42  This would avoid unnecessary cloning in the add(entry*, bool) method.
43 
44 SourceFiles
45  dictionary.C
46  dictionaryIO.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef dictionary_H
51 #define dictionary_H
52 
53 #include "entry.H"
54 #include "IDLList.H"
55 #include "DLList.H"
56 #include "HashSet.H"
57 #include "ITstream.H"
58 #include "wordReList.H"
59 #include "Pair.H"
60 #include "className.H"
61 #include "fieldTypes.H"
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 namespace Foam
66 {
67 
68 // Forward declaration of friend functions and operators
69 class dictionary;
70 class regExp;
71 class SHA1Digest;
72 class unitConversion;
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  string::size_type i = scopedName.rfind('/');
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  //- Entries of matching patterns
173  DLList<entry*> patternEntries_;
174 
175  //- Patterns as precompiled regular expressions
176  DLList<autoPtr<regExp>> patternRegexps_;
177 
178 
179  // Private Member Functions
180 
181  //- Find and return an entry data stream pointer if present
182  // otherwise return nullptr.
183  // Allows scoping using '/' with special handling for '!' and '..'.
184  const entry* lookupScopedSubEntryPtr
185  (
186  const word&,
187  bool recursive,
188  bool patternMatch
189  ) const;
190 
191  //- Search patterns table for exact match or regular expression match
192  bool findInPatterns
193  (
194  const bool patternMatch,
195  const word& Keyword,
198  ) const;
199 
200  //- Search patterns table for exact match or regular expression match
201  bool findInPatterns
202  (
203  const bool patternMatch,
204  const word& Keyword,
205  DLList<entry*>::iterator& wcLink,
207  );
208 
209  //- Check that no unit conversions are being performed
210  void assertNoConvertUnits
211  (
212  const char* typeName,
213  const word& keyword,
214  const unitConversion& defaultUnits,
215  ITstream& is
216  ) const;
217 
218  //- Read a value, check its dimensions and convert its units
219  template<class T>
220  T readTypeAndConvertUnits
221  (
222  const word& keyword,
223  const unitConversion& defaultUnits,
224  ITstream& is
225  ) const;
226 
227  //- Read a value from the token stream
228  template<class T>
229  T readType
230  (
231  const word& keyword,
232  const unitConversion& defaultUnits,
233  ITstream& is
234  ) const;
235 
236  //- Read a value from the token stream
237  template<class T>
238  T readType(const word& keyword, ITstream& is) const;
239 
240 
241  // Private Classes
242 
243  class includedDictionary;
244 
245 
246 public:
247 
248  //- Declare friendship with the entry class for IO
249  friend class entry;
250 
251 
252  // Declare name of the class and its debug switch
253  ClassName("dictionary");
254 
255 
256  // Public static data
257 
258  //- Null dictionary
259  static const dictionary null;
260 
261  //- If true write optional keywords and values
262  // if not present in dictionary
263  static bool writeOptionalEntries;
264 
265 
266  // Constructors
267 
268  //- Construct top-level dictionary null
269  dictionary();
270 
271  //- Construct top-level empty dictionary with given name
272  dictionary(const fileName& name);
273 
274  //- Construct given the entry name, parent dictionary and Istream,
275  // reading entries until lastEntry or EOF
276  dictionary
277  (
278  const fileName& name,
279  const dictionary& parentDict,
280  Istream&
281  );
282 
283  //- Construct top-level dictionary from Istream,
284  // reading entries until EOF, optionally keeping the header
285  dictionary(Istream&, const bool keepHeader=false);
286 
287  //- Construct top-level dictionary with given T entries
288  template<class T, class ... KeysAndTs>
289  dictionary
290  (
291  const keyType& k,
292  const T& t,
293  const KeysAndTs& ... keysAndTs
294  );
295 
296  //- Construct top-level dictionary with given name and T entries
297  template<class T, class ... KeysAndTs>
298  dictionary
299  (
300  const fileName& name,
301  const keyType& k,
302  const T& t,
303  const KeysAndTs& ... keysAndTs
304  );
305 
306  //- Construct as copy given the parent dictionary
307  dictionary(const dictionary& parentDict, const dictionary&);
308 
309  //- Construct top-level dictionary as copy
310  dictionary(const dictionary&);
311 
312  //- Construct top-level dictionary as copy from pointer to dictionary.
313  // A null pointer is treated like an empty dictionary.
314  dictionary(const dictionary*);
315 
316  //- Construct and return clone
317  autoPtr<dictionary> clone() const;
318 
319  //- Construct top-level dictionary on freestore from Istream
321 
322 
323  //- Destructor
324  virtual ~dictionary();
325 
326 
327  // Member Functions
328 
329  //- Return the parent dictionary
330  const dictionary& parent() const
331  {
332  return parent_;
333  }
334 
335  //- Return whether this dictionary is null
336  bool isNull() const
337  {
338  return this == &null;
339  }
340 
341  //- Return the top of the tree
342  const dictionary& topDict() const;
343 
344  //- Return the scoped keyword with which this dictionary can be
345  // accessed from the top dictionary in the tree
346  word topDictKeyword() const;
347 
348  //- Return line number of first token in dictionary
349  label startLineNumber() const;
350 
351  //- Return line number of last token in dictionary
352  label endLineNumber() const;
353 
354  //- Return the SHA1 digest of the dictionary contents
355  SHA1Digest digest() const;
356 
357  //- Return the dictionary as a list of tokens
358  tokenList tokens() const;
359 
360 
361  // Search and lookup
362 
363  //- Search dictionary for given keyword
364  // If recursive, search parent dictionaries
365  // If patternMatch, use regular expressions
366  bool found
367  (
368  const word&,
369  bool recursive=false,
370  bool patternMatch=true
371  ) const;
372 
373  //- Find and return an entry data stream pointer if present
374  // otherwise return nullptr.
375  // If recursive, search parent dictionaries.
376  // If patternMatch, use regular expressions
377  const entry* lookupEntryPtr
378  (
379  const word&,
380  bool recursive,
381  bool patternMatch
382  ) const;
383 
384  //- Find and return an entry data stream pointer for manipulation
385  // if present otherwise return nullptr.
386  // If recursive, search parent dictionaries.
387  // If patternMatch, use regular expressions.
389  (
390  const word&,
391  bool recursive,
392  bool patternMatch
393  );
394 
395  //- Find and return an entry data stream if present, trying a list
396  // of keywords in sequence, otherwise return nullptr.
397  // If recursive, search parent dictionaries.
398  // If patternMatch, use regular expressions
400  (
401  const wordList&,
402  bool recursive,
403  bool patternMatch
404  ) const;
405 
406  //- Find and return an entry data stream if present otherwise error.
407  // If recursive, search parent dictionaries.
408  // If patternMatch, use regular expressions.
409  const entry& lookupEntry
410  (
411  const word&,
412  bool recursive,
413  bool patternMatch
414  ) const;
415 
416  //- Find and return an entry data stream if present, trying a list
417  // of keywords in sequence, otherwise error.
418  // If recursive, search parent dictionaries.
419  // If patternMatch, use regular expressions
421  (
422  const wordList&,
423  bool recursive,
424  bool patternMatch
425  ) const;
426 
427  //- Find and return an entry data stream
428  // If recursive, search parent dictionaries.
429  // If patternMatch, use regular expressions.
431  (
432  const word&,
433  bool recursive=false,
434  bool patternMatch=true
435  ) const;
436 
437  //- Find and return an entry data stream, trying a list of keywords
438  // in sequence
439  // if not found throw a fatal error relating to the first keyword
440  // If recursive, search parent dictionaries.
441  // If patternMatch, use regular expressions.
443  (
444  const wordList&,
445  bool recursive=false,
446  bool patternMatch=true
447  ) const;
448 
449  //- Find and return a T, if not found throw a fatal error.
450  // If recursive, search parent dictionaries.
451  // If patternMatch, use regular expressions.
452  template<class T>
453  T lookup
454  (
455  const word&,
456  bool recursive=false,
457  bool patternMatch=true
458  ) const;
459 
460  //- Find and return a T, with dimension checking and unit
461  // conversions, and if not found throw a fatal error.
462  // If recursive, search parent dictionaries.
463  // If patternMatch, use regular expressions.
464  template<class T>
465  T lookup
466  (
467  const word&,
468  const unitConversion&,
469  bool recursive=false,
470  bool patternMatch=true
471  ) const;
472 
473  //- Find and return a T, trying a list of keywords in sequence,
474  // and if not found throw a fatal error relating to the first
475  // (preferred) keyword.
476  // If recursive, search parent dictionaries.
477  // If patternMatch, use regular expressions.
478  template<class T>
480  (
481  const wordList&,
482  bool recursive=false,
483  bool patternMatch=true
484  ) const;
485 
486  //- Find and return a T, with dimension checking and unit
487  // conversions, trying a list of keywords in sequence, and if not
488  // found throw a fatal error relating to the first (preferred)
489  // keyword.
490  // If recursive, search parent dictionaries.
491  // If patternMatch, use regular expressions.
492  template<class T>
494  (
495  const wordList&,
496  const unitConversion&,
497  bool recursive=false,
498  bool patternMatch=true
499  ) const;
500 
501  //- Find and return a T, if not found return the given default
502  // value.
503  // If recursive, search parent dictionaries.
504  // If patternMatch, use regular expressions.
505  template<class T>
507  (
508  const word&,
509  const T&,
510  bool recursive=false,
511  bool patternMatch=true
512  ) const;
513 
514  //- Find and return a T with dimension checking and unit
515  // conversions, and if not found return the given default value.
516  // If recursive, search parent dictionaries.
517  // If patternMatch, use regular expressions.
518  template<class T>
520  (
521  const word&,
522  const unitConversion&,
523  const T&,
524  bool recursive=false,
525  bool patternMatch=true
526  ) const;
527 
528  //- Find and return a T, trying a list of keywords in sequence,
529  // and if not found throw a fatal error relating to the first
530  // (preferred) keyword
531  // If recursive, search parent dictionaries.
532  // If patternMatch, use regular expressions.
533  template<class T>
535  (
536  const wordList&,
537  const T&,
538  bool recursive=false,
539  bool patternMatch=true
540  ) const;
541 
542  //- Find and return a T, with dimension checking and unit
543  // conversions, trying a list of keywords in sequence, and if not
544  // found throw a fatal error relating to the first (preferred)
545  // keyword
546  // If recursive, search parent dictionaries.
547  // If patternMatch, use regular expressions.
548  template<class T>
550  (
551  const wordList&,
552  const unitConversion&,
553  const T&,
554  bool recursive=false,
555  bool patternMatch=true
556  ) const;
557 
558  //- Find and return a T, if not found return the given
559  // default value, and add to dictionary.
560  // If recursive, search parent dictionaries.
561  // If patternMatch, use regular expressions.
562  template<class T>
564  (
565  const word&,
566  const T&,
567  bool recursive=false,
568  bool patternMatch=true
569  );
570 
571  //- Find an entry if present, and assign to T.
572  // Returns true if the entry was found.
573  // If recursive, search parent dictionaries.
574  // If patternMatch, use regular expressions.
575  template<class T>
576  bool readIfPresent
577  (
578  const word&,
579  T&,
580  bool recursive=false,
581  bool patternMatch=true
582  ) const;
583 
584  //- Find an entry if present, and assign to T, with dimension
585  // checking and unit conversions.
586  // Returns true if the entry was found.
587  // If recursive, search parent dictionaries.
588  // If patternMatch, use regular expressions.
589  template<class T>
590  bool readIfPresent
591  (
592  const word&,
593  const unitConversion&,
594  T&,
595  bool recursive=false,
596  bool patternMatch=true
597  ) const;
598 
599  //- Find and return an entry data stream pointer if present,
600  // otherwise return nullptr.
601  // If recursive, search parent dictionaries.
602  // If patternMatch, use regular expressions.
603  // Allows scoping using '/' with special handling for '!' and '..'.
605  (
606  const word&,
607  bool recursive,
608  bool patternMatch
609  ) const;
610 
611  //- Find and return a T,
612  // if not found throw a fatal error.
613  // If recursive, search parent dictionaries.
614  // If patternMatch, use regular expressions.
615  // Allows scoping using '/' with special handling for '!' and '..'.
616  template<class T>
618  (
619  const word&,
620  bool recursive=false,
621  bool patternMatch=true
622  ) const;
623 
624  //- Find return the reference to the compound T,
625  // if not found or not a compound throw a fatal error.
626  // If recursive, search parent dictionaries.
627  // If patternMatch, use regular expressions.
628  // Allows scoping using '/' with special handling for '!' and '..'.
629  template<class T>
630  const T& lookupCompoundScoped
631  (
632  const word& keyword,
633  bool recursive,
634  bool patternMatch
635  ) const;
636 
637  //- Check if entry is a sub-dictionary
638  bool isDict(const word&) const;
639 
640  //- Find and return a sub-dictionary pointer if present
641  // otherwise return nullptr.
642  const dictionary* subDictPtr(const word&) const;
643 
644  //- Find and return a sub-dictionary pointer if present
645  // otherwise return nullptr.
646  dictionary* subDictPtr(const word&);
647 
648  //- Find and return a sub-dictionary
649  const dictionary& subDict(const word&) const;
650 
651  //- Find and return a sub-dictionary for manipulation
652  dictionary& subDict(const word&);
653 
654  //- Find and return a sub-dictionary, trying a list of keywords in
655  // sequence, otherwise error.
656  const dictionary& subDictBackwardsCompatible(const wordList&) const;
657 
658  //- Find and return a sub-dictionary as a copy, or
659  // return an empty dictionary if the sub-dictionary does not exist
661  (
662  const word&,
663  const bool mustRead = false
664  ) const;
665 
666  //- Find and return a sub-dictionary if found
667  // otherwise return this dictionary
668  const dictionary& optionalSubDict(const word&) const;
669 
670  //- Find and return a sub-dictionary by scoped lookup
671  // i.e. the keyword may contain scope characters.
672  // If the keyword is null this dictionary is returned
673  const dictionary& scopedDict(const word&) const;
674 
675  //- Find and return a sub-dictionary by scoped lookup
676  // i.e. the keyword may contain scope characters.
677  // If the keyword is null this dictionary is returned
678  dictionary& scopedDict(const word&);
679 
680  //- Return the table of contents
681  wordList toc() const;
682 
683  //- Return the sorted table of contents
684  wordList sortedToc() const;
685 
686  //- Return the list of available keys or patterns
687  List<keyType> keys(bool patterns=false) const;
688 
689 
690  // Editing
691 
692  //- Substitute the given keyword prepended by '$' with the
693  // corresponding sub-dictionary entries
694  bool substituteKeyword(const word& keyword);
695 
696  //- Substitute the given scoped keyword prepended by '$' with the
697  // corresponding sub-dictionary entries
698  bool substituteScopedKeyword(const word& keyword);
699 
700  //- Add a new entry
701  // With the merge option, dictionaries are interwoven and
702  // primitive entries are overwritten
703  bool add(entry*, bool mergeEntry=false);
704 
705  //- Add an entry
706  // With the merge option, dictionaries are interwoven and
707  // primitive entries are overwritten
708  void add(const entry&, bool mergeEntry=false);
709 
710  //- Add a word entry
711  // optionally overwrite an existing entry
712  void add(const keyType&, const word&, bool overwrite=false);
713 
714  //- Add a string entry
715  // optionally overwrite an existing entry
716  void add(const keyType&, const string&, bool overwrite=false);
717 
718  //- Add a label entry
719  // optionally overwrite an existing entry
720  void add(const keyType&, const label, bool overwrite=false);
721 
722  //- Add a scalar entry
723  // optionally overwrite an existing entry
724  void add(const keyType&, const scalar, bool overwrite=false);
725 
726  //- Add a dictionary entry
727  // optionally merge with an existing sub-dictionary
728  void add
729  (
730  const keyType&,
731  const dictionary&,
732  bool mergeEntry=false
733  );
734 
735  //- Add a T entry
736  // optionally overwrite an existing entry
737  template<class T>
738  void add(const keyType&, const T&, bool overwrite=false);
739 
740  //- Assign a new entry, overwrite any existing entry
741  void set(entry*);
742 
743  //- Assign a new entry, overwrite any existing entry
744  void set(const entry&);
745 
746  //- Assign a dictionary entry, overwrite any existing entry
747  void set(const keyType&, const dictionary&);
748 
749  //- Assign a T entry, overwrite any existing entry
750  template<class T>
751  void set(const keyType&, const T&);
752 
753  //- Assign multiple T entries, overwriting any existing entries
754  template<class T, class ... KeysAndTs>
755  void set(const keyType&, const T&, const KeysAndTs& ...);
756 
757  //- Remove an entry specified by keyword
758  bool remove(const word&);
759 
760  //- Change the keyword for an entry,
761  // optionally forcing overwrite of an existing entry
762  bool changeKeyword
763  (
764  const keyType& oldKeyword,
765  const keyType& newKeyword,
766  bool forceOverwrite=false
767  );
768 
769  //- Merge entries from the given dictionary.
770  // Also merge sub-dictionaries as required.
771  bool merge(const dictionary&);
772 
773  //- Clear the dictionary
774  void clear();
775 
776  //- Transfer the contents of the argument and annul the argument.
777  void transfer(dictionary&);
778 
779 
780  // Read
781 
782  //- Read dictionary from Istream, optionally keeping the header
783  bool read(Istream&, const bool keepHeader=false);
784 
785  //- Return true if the dictionary global,
786  // i.e. the same on all processors.
787  // Defaults to false, must be overridden by global IO dictionaries
788  virtual bool global() const;
789 
790 
791  // Write
792 
793  //- Write dictionary, normally with sub-dictionary formatting
794  void write(Ostream&, const bool subDict=true) const;
795 
796 
797  // Member Operators
798 
799  //- Find and return entry
800  ITstream& operator[](const word&) const;
801 
802  void operator=(const dictionary&);
803 
804  //- Include entries from the given dictionary.
805  // Warn, but do not overwrite existing entries.
806  void operator+=(const dictionary&);
807 
808  //- Conditionally include entries from the given dictionary.
809  // Do not overwrite existing entries.
810  void operator|=(const dictionary&);
811 
812  //- Unconditionally include entries from the given dictionary.
813  // Overwrite existing entries.
814  void operator<<=(const dictionary&);
815 
816 
817  // IOstream Operators
818 
819  //- Read dictionary from Istream
820  friend Istream& operator>>(Istream&, dictionary&);
821 
822  //- Write dictionary to Ostream
823  friend Ostream& operator<<(Ostream&, const dictionary&);
824 };
825 
826 
827 // Private Classes
828 
830 :
831  public dictionary
832 {
833  // Private Data
834 
835  //- Global IO status inherited from the parent dictionary
836  bool global_;
837 
838 
839 public:
840 
841  // Constructors
842 
843  //- Construct an included dictionary for the given parent
844  // setting the "global" status dictionary without setting the parent
846  (
847  const fileName& fName,
848  const dictionary& parentDict
849  );
850 
851 
852  //- Destructor
853  virtual ~includedDictionary()
854  {}
855 
856 
857  // Member Functions
858 
859  //- Return true if the dictionary global,
860  // i.e. the same on all processors.
861  // Inherited from the parent dictionary into which this is included
862  virtual bool global() const
863  {
864  return global_;
865  }
866 };
867 
868 
869 // Template Specialisations
870 
871 //- Specialise readType for types for which unit conversions can be performed
872 #define DECLARE_SPECIALISED_READ_TYPE(T, nullArg) \
873  \
874  template<> \
875  T Foam::dictionary::readType \
876  ( \
877  const word& keyword, \
878  const unitConversion& defaultUnits, \
879  ITstream& is \
880  ) const; \
881  \
882  template<> \
883  T Foam::dictionary::readType \
884  ( \
885  const word& keyword, \
886  ITstream& is \
887  ) const;
888 
889 #define DECLARE_SPECIALISED_READ_LIST_TYPE(T, nullArg) \
890  DECLARE_SPECIALISED_READ_TYPE(List<T>, nullArg)
891 
894 
895 #undef DECLARE_SPECIALISED_READ_TYPE
896 #undef DECLARE_SPECIALISED_READ_FIELD_TYPE
897 
898 
899 // Global Operators
900 
901 //- Combine dictionaries.
902 // Starting from the entries in dict1 and then including those from dict2.
903 // Warn, but do not overwrite the entries from dict1.
904 dictionary operator+(const dictionary& dict1, const dictionary& dict2);
905 
906 //- Combine dictionaries.
907 // Starting from the entries in dict1 and then including those from dict2.
908 // Do not overwrite the entries from dict1.
909 dictionary operator|(const dictionary& dict1, const dictionary& dict2);
910 
911 
912 // Global Functions
913 
914 //- Parse dictionary substitution argument list
915 void dictArgList
916 (
917  const string& argString,
918  word& configName,
919  wordReList& args,
920  List<Tuple2<word, string>>& namedArgs
921 );
922 
923 //- Parse dictionary substitution argument list
924 void dictArgList
925 (
926  const string& argString,
927  wordReList& args,
928  List<Tuple2<word, string>>& namedArgs
929 );
930 
931 //- Extracts dict name and keyword
932 Pair<word> dictAndKeyword(const word& scopedName);
933 
934 //- Return the list of configuration files in
935 // user/group/shipped directories.
936 // The search scheme allows for version-specific and
937 // version-independent files using the following hierarchy:
938 // - \b user settings:
939 // - ~/.OpenFOAM/<VERSION>/caseDicts/functions
940 // - ~/.OpenFOAM/caseDicts/functions
941 // - \b group (site) settings (when $WM_PROJECT_SITE is set):
942 // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/functions
943 // - $WM_PROJECT_SITE/etc/caseDicts/functions
944 // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
945 // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
946 // caseDicts/functions
947 // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/functions
948 // - \b other (shipped) settings:
949 // - $WM_PROJECT_DIR/etc/caseDicts/functions
951 (
952  const fileName& configFilesPath
953 );
954 
955 //- Search for configuration file for given region
956 // and if not present also search the case directory as well as the
957 // user/group/shipped directories.
958 // The search scheme allows for version-specific and
959 // version-independent files using the following hierarchy:
960 // - \b user settings:
961 // - ~/.OpenFOAM/<VERSION>/caseDicts/functions
962 // - ~/.OpenFOAM/caseDicts/functions
963 // - \b group (site) settings (when $WM_PROJECT_SITE is set):
964 // - $WM_PROJECT_SITE/<VERSION>/etc/caseDicts/functions
965 // - $WM_PROJECT_SITE/etc/caseDicts/functions
966 // - \b group (site) settings (when $WM_PROJECT_SITE is not set):
967 // - $WM_PROJECT_INST_DIR/site/<VERSION>/etc/
968 // caseDicts/functions
969 // - $WM_PROJECT_INST_DIR/site/etc/caseDicts/functions
970 // - \b other (shipped) settings:
971 // - $WM_PROJECT_DIR/etc/caseDicts/functions
972 //
973 // \return The path of the configuration file if found
974 // otherwise null
976 (
977  const word& configName,
978  const fileName& configFilesPath,
979  const word& configFilesDir,
980  const word& region = word::null
981 );
982 
983 //- Read the specified configuration file
984 // parsing the optional arguments included in the string
985 // 'argString', inserting 'field' or 'fields' entries as required
986 // and merging the resulting configuration dictionary into
987 // 'parentDict'.
988 //
989 // Parses the optional arguments:
990 // 'Q(U)' -> configFileName = Q; args = (U)
991 // -> field U;
992 //
993 // Supports named arguments:
994 // 'patchAverage(patch=inlet, p,U)'
995 // or
996 // 'patchAverage(patch=inlet, field=(p U))'
997 // -> configFileName = patchAverage;
998 // args = (patch=inlet, p,U)
999 // -> patch inlet;
1000 // fields (p U);
1001 bool readConfigFile
1002 (
1003  const word& configType,
1004  const string& argString,
1005  dictionary& parentDict,
1006  const fileName& configFilesPath,
1007  const word& configFilesDir,
1008  const Pair<string>& contextTypeAndValue,
1009  const word& region = word::null
1010 );
1011 
1012 //- Write a dictionary entry
1013 void writeEntry(Ostream& os, const dictionary& dict);
1014 
1015 //- Helper function to write the keyword and entry
1016 template<class EntryType>
1017 void writeEntry(Ostream& os, const word& entryName, const EntryType& value);
1018 
1019 //- Helper function to write the keyword and entry
1020 template<class EntryType>
1021 void writeEntry
1022 (
1023  Ostream& os,
1024  const word& entryName,
1025  const unitConversion& defaultUnits,
1026  const EntryType& value
1027 );
1028 
1029 //- Helper function to write the keyword and entry only if the
1030 // values are not equal. The value is then output as value2
1031 template<class EntryType>
1033 (
1034  Ostream& os,
1035  const word& entryName,
1036  const EntryType& value1,
1037  const EntryType& value2
1038 );
1039 
1040 //- Helper function to write the keyword and entry only if the
1041 // values are not equal. The value is then output as value2
1042 template<class EntryType>
1044 (
1045  Ostream& os,
1046  const word& entryName,
1047  const unitConversion& defaultUnits,
1048  const EntryType& value1,
1049  const EntryType& value2
1050 );
1051 
1052 
1053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1054 
1055 } // End namespace Foam
1056 
1057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1058 
1059 #ifdef NoRepository
1060  #include "dictionaryTemplates.C"
1061 #endif
1062 
1063 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1064 
1065 #endif
1066 
1067 // ************************************************************************* //
Non-intrusive doubly-linked list.
Intrusive doubly-linked list.
label k
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:53
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
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:72
virtual ~includedDictionary()
Destructor.
Definition: dictionary.H:852
virtual bool global() const
Return true if the dictionary global,.
Definition: dictionary.H:861
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefaultBackwardsCompatible(const wordList &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, trying a list of keywords in sequence,.
bool substituteScopedKeyword(const word &keyword)
Substitute the given scoped keyword prepended by '$' with the.
Definition: dictionary.C:773
static bool writeOptionalEntries
If true write optional keywords and values.
Definition: dictionary.H:262
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:414
ITstream & operator[](const word &) const
Find and return entry.
Definition: dictionary.C:1368
ClassName("dictionary")
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:894
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:320
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:398
virtual bool global() const
Return true if the dictionary global,.
Definition: dictionaryIO.C:153
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1434
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1353
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Definition: dictionaryIO.C:108
const dictionary & subDictBackwardsCompatible(const wordList &) const
Find and return a sub-dictionary, trying a list of keywords in.
Definition: dictionary.C:874
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:548
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:710
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
Definition: dictionary.C:1210
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:489
bool substituteKeyword(const word &keyword)
Substitute the given keyword prepended by '$' with the.
Definition: dictionaryIO.C:166
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:1152
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:211
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:667
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:996
void operator+=(const dictionary &)
Include entries from the given dictionary.
Definition: dictionary.C:1397
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:921
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present,.
Definition: dictionary.C:737
word topDictKeyword() const
Return the scoped keyword with which this dictionary can be.
Definition: dictionary.C:429
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:1177
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:797
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:329
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
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:688
T lookupOrAddDefault(const word &, const T &, bool recursive=false, bool patternMatch=true)
Find and return a T, if not found return the given.
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:462
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:990
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:631
bool isNull() const
Return whether this dictionary is null.
Definition: dictionary.H:335
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:1414
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
void clear()
Clear the dictionary.
Definition: dictionary.C:1344
virtual ~dictionary()
Destructor.
Definition: dictionary.C:406
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:721
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:813
void operator=(const dictionary &)
Definition: dictionary.C:1374
wordList toc() const
Return the table of contents.
Definition: dictionary.C:976
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
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:938
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:449
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:100
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1299
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:475
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
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define DECLARE_SPECIALISED_READ_LIST_TYPE(T, nullArg)
Definition: dictionary.H:888
#define DECLARE_SPECIALISED_READ_TYPE(T, nullArg)
Specialise readType for types for which unit conversions can be performed.
Definition: dictionary.H:871
Include the header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
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:358
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
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
bool readConfigFile(const word &configType, const string &argString, dictionary &parentDict, const fileName &configFilesPath, const word &configFilesDir, const Pair< string > &contextTypeAndValue, const word &region=word::null)
Read the specified configuration file.
Definition: dictionaryIO.C:433
void dictArgList(const string &argString, word &configName, wordReList &args, List< Tuple2< word, string >> &namedArgs)
Parse dictionary substitution argument list.
Definition: dictionary.C:1480
wordList listAllConfigFiles(const fileName &configFilesPath)
Return the list of configuration files in.
Definition: dictionaryIO.C:415
Pair< word > dictAndKeyword(const word &scopedName)
Extracts dict name and keyword.
Definition: dictionary.C:1639
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
HashSet< Key, Hash > operator|(const HashSet< Key, Hash > &hash1, const HashSet< Key, Hash > &hash2)
Combine entries from HashSets.
dictionary dict
Foam::argList args(argc, argv)