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