Loading...
Searching...
No Matches
dictionary.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::dictionary
29
30Description
31 A list of keyword definitions, which are a keyword followed by a number
32 of values (eg, words and numbers) or by a sub-dictionary.
33 Since the dictionary format is used extensively throughout OpenFOAM for
34 input/output files, there are many examples of its use.
35
36 Dictionary keywords are a plain word or a pattern (regular expression).
37 The general order for searching is as follows:
38 - exact match
39 - pattern match (in reverse order)
40 - optional recursion into the enclosing (parent) dictionaries
41
42 The dictionary class is the base class for IOdictionary and also serves
43 as a bootstrap dictionary for the objectRegistry data dictionaries.
44
45Note
46 Within dictionaries, entries can be referenced by using the
47 \c '$' syntax familiar from shell programming.
48 Similarly, the \c '/' separator is used when referencing
49 sub-dictionary entries:
50 - <b> "./" </b> : the current dictionary
51 - <b> "../" </b> : the parent dictionary
52 - <b> "../../" </b> : the grandparent dictionary
53 .
54
55 An initial \c '/' anchor specifies that the path starts from the
56 top-level entry. It is also possible to use the '${}' syntax for clarity.
57
58 For example,
59 \verbatim
60 key1 val1;
61 key2 $key1; // Use key1 value from current scope
62 key3 $./key1; // Use key1 value from current scope
63
64 subdict1
65 {
66 key1 val1b;
67 key2 $../key1; // Use key1 value from parent
68 subdict2
69 {
70 key2 val2;
71 key3 $../../key1; // Use key1 value from grandparent
72 }
73 }
74
75 key4 $/subdict1/subdict2/key3; // Lookup with absolute scoping
76 \endverbatim
77
78 Prior to OpenFOAM-v1712, a dot-scoping (.) syntax was used, which is
79 still supported (AUG-2023) but deprecated in favour of the
80 less ambiguous slash-scoping (/) syntax.
81 With dot-scoping, an initial \c '^' anchor, or an initial (:), was used
82 to specify that the path starts from the top-level entry.
83
84
85SourceFiles
86 dictionary.C
87 dictionaryIO.C
88 dictionarySearch.C
89
90SeeAlso
91 - Foam::entry
92 - Foam::dictionaryEntry
93 - Foam::primitiveEntry
94
95\*---------------------------------------------------------------------------*/
96
97#ifndef Foam_dictionary_H
98#define Foam_dictionary_H
99
100#include <type_traits>
101#include "entry.H"
102#include "IDLList.H"
103#include "DLList.H"
104#include "fileName.H"
105#include "ITstream.H"
106#include "HashTable.H"
107#include "wordList.H"
108#include "className.H"
109#include "refPtr.H"
110#include "IOobjectOption.H"
111
112// Some common data types
113#include "label.H"
114#include "scalar.H"
115#include "regExpFwd.H"
116#include "Switch.H"
117
118// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119
120namespace Foam
121{
122
123// Forward Declarations
124class dictionary;
125class OSstream;
126class SHA1Digest;
127
131/*---------------------------------------------------------------------------*\
132 Class dictionary Declaration
133\*---------------------------------------------------------------------------*/
134
135class dictionary
136:
137 public IDLList<entry>
138{
139public:
140
141 // Searching
142
143 //- Generic const/non-const dictionary entry %searcher.
144 // A %searcher provides a uniform means of finding and returning
145 // an entry pointer as well as the dictionary \a context in which
146 // the entry was located.
147 //
148 // Note that the constructors and set methods are protected such
149 // that only friends of the class can set things. This safeguards
150 // against inconsistencies in context/entry.
151 template<bool Const>
152 class Searcher
154 public:
155 friend dictionary;
156
157 //- The const/non-const type for the context and sub-dictionaries
158 using dict_type =
159 std::conditional_t<Const, const dictionary, dictionary>;
160
161 //- The const/non-const type for entries
162 using value_type =
163 std::conditional_t<Const, const entry, entry>;
165 //- A pointer to a const/non-const dictionary
166 using dict_pointer = dict_type*;
167
168 //- A reference to a const/non-const dictionary
169 using dict_reference = dict_type&;
171 //- A pointer to a const/non-const entry
172 using pointer = value_type*;
173
174 //- A reference to a const/non-const entry
176
177
178 protected:
179
180 //- The dictionary context for the entry
182
183 //- The entry or nullptr
186
187 //- Implicit construct for the given dictionary context
189 :
190 dict_(dict),
191 eptr_(nullptr)
192 {}
194 //- Assign the entry
195 void set(pointer eptr) noexcept
196 {
197 eptr_ = eptr;
199
200
201 public:
202
203 //- Default construct
204 constexpr Searcher() noexcept
205 :
206 dict_(nullptr),
207 eptr_(nullptr)
208 {}
209
210
211 //- True if entry was found
212 bool good() const noexcept { return eptr_; }
214 //- True if entry was found
215 // \deprecated(2019-01) - prefer good() method
216 bool found() const noexcept { return eptr_; }
217
218 //- The containing dictionary context
219 dict_reference context() const { return *dict_; }
220
221 //- A pointer to the entry (nullptr if not found)
222 pointer ptr() const noexcept { return eptr_; }
223
224 //- A reference to the entry (Error if not found)
225 reference ref() const { return *eptr_; }
226
227 //- True if found entry is a dictionary.
228 bool isDict() const noexcept
229 {
230 return (eptr_ && eptr_->dictPtr());
231 }
232
233 //- True if found entry is a stream.
234 bool isStream() const noexcept
235 {
236 return (eptr_ && eptr_->streamPtr());
237 }
238
239 //- Pointer to the found entry as a dictionary, nullptr otherwise
242 return (eptr_ ? eptr_->dictPtr() : nullptr);
243 }
244
245 //- Pointer to the found entry as a stream, nullptr otherwise
247 {
248 return (eptr_ ? eptr_->streamPtr() : nullptr);
249 }
250
251 //- Return the found entry as a dictionary.
252 //- Error if not found, or not a dictionary.
253 dict_reference dict() const { return eptr_->dict(); }
254
255 //- Return the found entry as a ITstream.
256 //- Error if not found, or not a stream.
257 ITstream& stream() const { return eptr_->stream(); }
258
259 //- Permit an explicit cast to the other (const/non-const) searcher
260 explicit operator const Searcher<!Const>&() const
262 return *reinterpret_cast<const Searcher<!Const>*>(this);
263 }
264
265 //- A pointer to the entry (nullptr if not found)
266 pointer operator->() const noexcept { return eptr_; }
267
268 //- A reference to the entry (Error if not found)
269 reference operator*() const { return *eptr_; }
270 };
271
272
273 //- Searcher with const access
274 typedef Searcher<true> const_searcher;
275
276 //- Searcher with non-const access
278
279
280 // Friends
281
282 //- Declare friendship with the entry class for IO
283 friend class entry;
284
285 //- Declare friendship with the searcher classes
286 friend const_searcher;
287 friend searcher;
288
289
290private:
291
292 // Private Data
293
294 //- The dictionary name
295 fileName name_;
296
297 //- Parent dictionary
298 const dictionary& parent_;
299
300 //- Quick lookup of the entries held on the IDLList
301 HashTable<entry*> hashedEntries_;
302
303 //- Entries of matching patterns
304 DLList<entry*> patterns_;
306 //- Patterns as precompiled regular expressions
307 DLList<autoPtr<regExp>> regexps_;
308
309
310 // Typedefs
311
312 //- The storage container
313 typedef IDLList<entry> parent_type;
314
315
316 // Private Member Functions
317
318 //- Convert old-style (1806) boolean search specification to enum
319 //
320 // \param recursive search parent dictionaries
321 // \param pattern match using regular expressions as well
322 inline static enum keyType::option
323 matchOpt(bool recursive, bool pattern)
324 {
325 return
327 (
328 (pattern ? keyType::REGEX : keyType::LITERAL)
329 | (recursive ? keyType::RECURSIVE : 0)
330 );
331 }
332
333 //- Search using a '.' for scoping.
334 // A leading dot means to use the parent dictionary.
335 // An intermediate dot separates a sub-dictionary or sub-entry.
336 // However, the use of dots is unfortunately ambiguous.
337 // The value "a.b.c.d" could be a first-level entry, a second-level
338 // entry (eg, "a" with "b.c.d", "a.b" with "c.d" etc),
339 // or just about any other combination.
340 // The heuristic tries successively longer top-level entries
341 // until there is a suitable match.
342 //
343 // \param keyword the keyword to search for
344 // \param matchOpt the search mode
345 const_searcher csearchDotScoped
346 (
347 const word& keyword,
348 enum keyType::option matchOpt
349 ) const;
350
351 //- Search using a '/' for scoping.
352 // Semantics as per normal files: an intermediate "." is the current
353 // dictionary level, an intermediate ".." is the parent dictionary.
354 // Note that since a slash is not a valid word character, there is no
355 // ambiguity between separator and content.
356 // No possibility or need for recursion.
357 //
358 // \param keyword the keyword to search for
359 // \param matchOpt the search mode. Recursive is ignored.
360 const_searcher csearchSlashScoped
361 (
362 const word& keyword,
363 enum keyType::option matchOpt
364 ) const;
365
366
367 //- Emit IOError about bad input for the entry
368 void raiseBadInput(const ITstream& is, const word& keyword) const;
369
370 //- The currently known executable name,
371 //- obtained from argList envExecutable
372 static word executableName();
373
374 //- Report (usually stderr) that the keyword default value was used,
375 //- or FatalIOError when writeOptionalEntries greater than 1
376 template<class T>
377 void reportDefault
378 (
379 const word& keyword,
380 const T& deflt,
381 const bool added = false // Value was added to the dictionary
382 ) const;
383
384
385public:
386
387 // Declare name of the class and its debug switch
388 ClassName("dictionary");
389
390 // Static Data
391
392 //- Report optional keywords and values if not present in dictionary
393 // For value greater than 1: fatal.
394 // Set/unset via an InfoSwitch or -info-switch at the command-line
395 static int writeOptionalEntries;
396
397 //- An empty dictionary, which is also the parent for all dictionaries
398 static const dictionary null;
399
400 //- Output location when reporting default values
402
403
404 // Static Member Functions
405
406 //- Return the state of reporting optional (default) entries
407 // 0: no reporting, 1: report, 2: fatal if not set
408 inline static int reportOptional() noexcept;
409
410 //- Change the state of reporting optional (default) entries
411 // 0: no reporting, 1: report, 2: fatal if not set
412 // \return old level
413 inline static int reportOptional(const int level) noexcept;
414
415
416 // Constructors
417
418 //- Default construct, a top-level empty dictionary
419 dictionary();
420
421 //- Construct top-level empty dictionary with given name
422 explicit dictionary(const fileName& name);
423
424 //- Construct given the entry name, parent dictionary and Istream,
425 //- reading entries until EOF, optionally keeping the header
427 (
428 const fileName& name,
429 const dictionary& parentDict,
430 Istream& is,
431 bool keepHeader = false
432 );
433
434 //- Construct top-level dictionary from Istream (discards the header).
435 //- Reads entries until EOF or when the first token is a
436 //- '{' character, it will stop reading at the matching '}' character.
437 // \note this constructor should be explicit
438 dictionary(Istream& is);
439
440 //- Construct top-level dictionary from Istream,
441 //- reading entries until EOF, optionally keeping the header
442 dictionary(Istream& is, bool keepHeader);
443
444 //- Copy construct given the parent dictionary
445 dictionary(const dictionary& parentDict, const dictionary& dict);
446
447 //- Copy construct top-level dictionary
448 dictionary(const dictionary& dict);
449
450 //- Construct top-level dictionary as copy from pointer to dictionary.
451 // A null pointer is treated like an empty dictionary.
452 explicit dictionary(const dictionary* dict);
453
454 //- Move construct for given parent dictionary
455 dictionary(const dictionary& parentDict, dictionary&& dict);
456
457 //- Move construct top-level dictionary
459
460 //- Construct and return clone
461 autoPtr<dictionary> clone() const;
462
463 //- Construct top-level dictionary on freestore from Istream
464 static autoPtr<dictionary> New(Istream& is);
465
466
467 //- Destructor
468 virtual ~dictionary();
469
470
471 // Member Functions
473 // Access
474
475 //- The dictionary name
476 inline const fileName& name() const noexcept;
477
478 //- The dictionary name for modification (use with caution).
479 inline fileName& name() noexcept;
480
481 //- The local dictionary name (final part of scoped name)
482 inline word dictName() const;
483
484 //- The dictionary name relative to the case.
485 // Uses argList::envRelativePath to obtain FOAM_CASE
486 //
487 // \param caseTag replace globalPath with <case> for later
488 // use with expand(), or prefix <case> if the file name was
489 // not an absolute location
490 fileName relativeName(const bool caseTag = false) const;
491
492 //- The dictionary is actually dictionary::null (root dictionary)
493 inline bool isNullDict() const noexcept;
494
495 //- Return the parent dictionary
496 inline const dictionary& parent() const noexcept;
497
498 //- Return the top of the tree
499 const dictionary& topDict() const;
500
501 //- Return line number of first token in dictionary
502 label startLineNumber() const;
503
504 //- Return line number of last token in dictionary
505 label endLineNumber() const;
506
507 //- Return the SHA1 digest of the dictionary contents
508 SHA1Digest digest() const;
509
510 //- Return the dictionary as a list of tokens
511 tokenList tokens() const;
512
513
514 // Searching
515
516 //- Find an entry (const access) with the given keyword.
517 //
518 // \param keyword the keyword to search for
519 // \param matchOpt search mode (default: non-recursive with patterns)
520 //
521 // \return pointer to the entry found or a nullptr.
522 inline const entry* findEntry
523 (
524 const word& keyword,
525 enum keyType::option matchOpt = keyType::REGEX
526 ) const;
527
528 //- Find an entry (non-const access) with the given keyword.
529 //
530 // \param keyword the keyword to search for
531 // \param matchOpt search mode (default: non-recursive with patterns)
532 //
533 // \return pointer to the entry found or a nullptr.
534 inline entry* findEntry
535 (
536 const word& keyword,
537 enum keyType::option matchOpt = keyType::REGEX
538 );
539
540 //- Find an entry (const access) with the given keyword.
541 //
542 // \param keyword the keyword to search for
543 // \param matchOpt search mode (default: non-recursive with patterns)
544 //
545 // \return True if entry was found
546 inline bool found
547 (
548 const word& keyword,
549 enum keyType::option matchOpt = keyType::REGEX
550 ) const;
551
552 //- Search for a scoped entry (const access) with the given keyword.
553 // Allows scoping using '.'.
554 // Special handling for an absolute anchor (^) at start of the keyword
555 // and for '..' to ascend into the parent dictionaries.
556 //
557 // \param keyword the keyword to search for
558 // \param matchOpt search mode (default: non-recursive with patterns)
559 //
560 // \return pointer to the entry found or a nullptr.
561 inline const entry* findScoped
562 (
563 const word& keyword,
564 enum keyType::option matchOpt = keyType::REGEX
565 ) const;
566
567 //- Find and return a sub-dictionary pointer if present
568 //- (and it is a dictionary) otherwise return nullptr.
569 //
570 // \param keyword the keyword to search for
571 // \param matchOpt search mode (default: non-recursive with patterns)
572 //
573 // \return pointer to sub-dictionary found or a nullptr.
574 inline const dictionary* findDict
575 (
576 const word& keyword,
577 enum keyType::option matchOpt = keyType::REGEX
578 ) const;
579
580 //- Find and return a sub-dictionary pointer if present
581 //- (and it is a dictionary) otherwise return nullptr.
582 //
583 // \param keyword the keyword to search for
584 // \param matchOpt search mode (default: non-recursive with patterns)
585 //
586 // \return pointer to sub-dictionary found or a nullptr.
587 inline dictionary* findDict
588 (
589 const word& keyword,
590 enum keyType::option matchOpt = keyType::REGEX
591 );
592
593 //- Find and return an entry stream if present
594 //- (and it is a stream) otherwise return nullptr.
595 //
596 // \param keyword the keyword to search for
597 // \param matchOpt search mode (default: non-recursive with patterns)
598 //
599 // \return pointer to ITstream or a nullptr
600 inline ITstream* findStream
601 (
602 const word& keyword,
603 enum keyType::option matchOpt = keyType::REGEX
604 ) const;
605
606
607 // Lookup
608
609 //- Search for an entry (const access) with the given keyword.
610 //
611 // \param keyword the keyword to search for
612 // \param matchOpt search mode
613 //
614 // \return return an entry if present, otherwise FatalIOError.
615 const entry& lookupEntry
616 (
617 const word& keyword,
618 enum keyType::option matchOpt
619 ) const;
620
621 //- Find and return an entry data stream.
622 //- FatalIOError if not found, or not a stream
623 //
624 // \param keyword the keyword to search for
625 // \param matchOpt search mode (default: non-recursive with patterns)
626 //
627 // \return entry stream or FatalIOError
629 (
630 const word& keyword,
631 enum keyType::option matchOpt = keyType::REGEX
632 ) const;
633
634 //- Find and return a T.
635 //- FatalIOError if not found, or if the number of tokens is incorrect.
636 //
637 // \param keyword the keyword to search for
638 // \param matchOpt search mode (default: non-recursive with patterns)
639 template<class T>
640 T get
641 (
642 const word& keyword,
643 enum keyType::option matchOpt = keyType::REGEX
644 ) const;
645
646 //- Find and return a T, or return the given default value.
647 //- FatalIOError if it is found and the number of tokens is incorrect.
648 //
649 // \param keyword the keyword to search for
650 // \param deflt the default value to use
651 // \param matchOpt search mode (default: non-recursive with patterns)
652 template<class T>
654 (
655 const word& keyword,
656 const T& deflt,
657 enum keyType::option matchOpt = keyType::REGEX
658 ) const;
659
660 //- Find and return a T, or return the given default value
661 //- and add it to dictionary.
662 //- FatalIOError if it is found and the number of tokens is incorrect.
663 //
664 // \param keyword the keyword to search for
665 // \param deflt the default value to use
666 // \param matchOpt search mode (default: non-recursive with patterns)
667 template<class T>
668 T getOrAdd
669 (
670 const word& keyword,
671 const T& deflt,
672 enum keyType::option matchOpt = keyType::REGEX
673 );
674
675 //- Find entry and assign to T val.
676 //- FatalIOError if it is found and the number of tokens is incorrect,
677 //- or it is mandatory and not found.
678 //
679 // \param keyword the keyword to search for
680 // \param val the value to read into
681 // \param matchOpt search mode (default: non-recursive with patterns)
682 // \param readOpt the entry is required/optional (default: MUST_READ)
683 //
684 // \return true if the entry was read
685 template<class T>
686 bool readEntry
687 (
688 const word& keyword,
689 T& val,
690 enum keyType::option matchOpt = keyType::REGEX,
691 IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
692 ) const;
693
694 //- Find an entry if present, and assign to T val.
695 //- FatalIOError if it is found and the number of tokens is incorrect.
696 //
697 // \param keyword the keyword to search for
698 // \param val the value to read into
699 // \param matchOpt search mode (default: non-recursive with patterns)
700 //
701 // \return true if the entry was read
702 template<class T>
703 bool readIfPresent
704 (
705 const word& keyword,
706 T& val,
707 enum keyType::option matchOpt = keyType::REGEX
708 ) const;
709
710 //- Find and return a T with additional checking
711 //- FatalIOError if not found, or if the number of tokens is incorrect.
712 //
713 // \param keyword the keyword to search for
714 // \param pred the value check predicate
715 // \param matchOpt search mode (default: non-recursive with patterns)
716 template<class T, class Predicate>
717 T getCheck
718 (
719 const word& keyword,
720 const Predicate& pred,
721 enum keyType::option matchOpt = keyType::REGEX
722 ) const;
723
724 //- Find and return a T, or return the given default value.
725 //- FatalIOError if it is found and the number of tokens is incorrect.
726 //
727 // \param keyword the keyword to search for
728 // \param deflt the default value to use
729 // \param pred the value check predicate
730 // \param matchOpt search mode (default: non-recursive with patterns)
731 template<class T, class Predicate>
733 (
734 const word& keyword,
735 const T& deflt,
736 const Predicate& pred,
737 enum keyType::option matchOpt = keyType::REGEX
738 ) const;
739
740 //- Find and return a T, or return the given default value
741 //- and add it to dictionary.
742 //- FatalIOError if it is found and the number of tokens is incorrect.
743 //
744 // \param keyword the keyword to search for
745 // \param deflt the default value to use
746 // \param pred the value check predicate
747 // \param matchOpt search mode (default: non-recursive with patterns)
748 template<class T, class Predicate>
750 (
751 const word& keyword,
752 const T& deflt,
753 const Predicate& pred,
754 enum keyType::option matchOpt = keyType::REGEX
755 );
756
757 //- Find entry and assign to T val.
758 //- FatalIOError if it is found and the number of tokens is incorrect,
759 //- or it is mandatory and not found.
760 //
761 // \param keyword the keyword to search for
762 // \param val the value to read into
763 // \param pred the value check predicate
764 // \param matchOpt search mode (default: non-recursive with patterns)
765 // \param readOpt the entry is required/optional (default: MUST_READ)
766 //
767 // \return true if the entry was read
768 template<class T, class Predicate>
769 bool readCheck
770 (
771 const word& keyword,
772 T& val,
773 const Predicate& pred,
774 enum keyType::option matchOpt = keyType::REGEX,
775 IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
776 ) const;
777
778 //- Find an entry if present, and assign to T val.
779 //- FatalIOError if it is found and the number of tokens is incorrect.
780 //
781 // \param keyword the keyword to search for
782 // \param val the value to read into
783 // \param pred the value check predicate
784 // \param matchOpt search mode (default: non-recursive with patterns)
785 //
786 // \return true if the entry read
787 template<class T, class Predicate>
789 (
790 const word& keyword,
791 T& val,
792 const Predicate& pred,
793 enum keyType::option matchOpt = keyType::REGEX
794 ) const;
795
796 //- Find and return a sub-dictionary.
797 // Fatal if the entry does not exist or is not a sub-dictionary.
798 //
799 // \param keyword the keyword to search for
800 // \param matchOpt search mode (default: non-recursive with patterns)
801 const dictionary& subDict
802 (
803 const word& keyword,
804 enum keyType::option matchOpt = keyType::REGEX
805 ) const;
806
807 //- Find and return a sub-dictionary for manipulation.
808 // Fatal if the entry does not exist or is not a sub-dictionary.
809 //
810 // \param keyword the keyword to search for
811 // \param matchOpt search mode (default: non-recursive with patterns)
813 (
814 const word& keyword,
815 enum keyType::option matchOpt = keyType::REGEX
816 );
817
818 //- Find and return a sub-dictionary for manipulation.
819 // Fatal if the entry exist and is not a sub-dictionary.
820 //
821 // \param keyword the keyword to search for
822 // \param matchOpt search mode (default: non-recursive with patterns)
824 (
825 const word& keyword,
826 enum keyType::option matchOpt = keyType::REGEX
827 );
828
829 //- Find and return a sub-dictionary as a copy, otherwise return
830 //- an empty dictionary.
831 // Warn if the entry exists but is not a sub-dictionary.
832 //
833 // \param keyword the keyword to search for
834 // \param matchOpt search mode (default: non-recursive with patterns)
835 // \param mandatory the keyword is mandatory (default: false)
837 (
838 const word& keyword,
839 enum keyType::option matchOpt = keyType::REGEX,
840 const bool mandatory = false
841 ) const;
842
843 //- Find and return a sub-dictionary, otherwise return this dictionary.
844 // Warn if the entry exists but is not a sub-dictionary.
845 //
846 // \param keyword the keyword to search for
847 // \param matchOpt search mode (default: non-recursive with patterns)
849 (
850 const word& keyword,
851 enum keyType::option matchOpt = keyType::REGEX
852 ) const;
853
854 //- Return the table of contents
855 wordList toc() const;
856
857 //- Return the sorted table of contents
858 wordList sortedToc() const;
859
860 //- Return table of contents sorted using the specified comparator
861 template<class Compare>
862 wordList sortedToc(const Compare& comp) const;
863
864 //- Return the list of available keys or patterns
865 List<keyType> keys(bool patterns = false) const;
866
867
868 // Editing
869
870 //- Substitute the given keyword (which is prefixed by '$')
871 // with the corresponding sub-dictionary entries
873 (
874 const word& keyword,
875 bool mergeEntry = false
876 );
877
878 //- Substitute the given scoped keyword (which is prefixed by '$')
879 // with the corresponding sub-dictionary entries
881 (
882 const word& keyword,
883 bool mergeEntry = false
884 );
885
886 //- Add a new entry.
887 //
888 // \param entryPtr the entry to add
889 // \param mergeEntry dictionaries are interwoven and primitive
890 // entries are overwritten (default: false)
891 //
892 // \return pointer to inserted entry, or place of merging
893 // or nullptr on failure
894 entry* add(entry* entryPtr, bool mergeEntry=false);
895
896 //- Add an entry.
897 //
898 // \param e the entry to add
899 // \param mergeEntry dictionaries are interwoven and primitive
900 // entries are overwritten (default: false)
901 // \return pointer to inserted entry, or place of merging
902 // or nullptr on failure
903 entry* add(const entry& e, bool mergeEntry=false);
904
905 //- Add a word entry.
906 // \param overwrite force overwrite of an existing entry.
907 // \return pointer to inserted entry or nullptr on failure
908 entry* add(const keyType& k, const word& v, bool overwrite=false);
909
910 //- Add a string entry.
911 // \param overwrite force overwrite of an existing entry.
912 // \return pointer to inserted entry or nullptr on failure
913 entry* add(const keyType& k, const string& v, bool overwrite=false);
914
915 //- Add a label entry.
916 // \param overwrite force overwrite of an existing entry.
917 // \return pointer to inserted entry or nullptr on failure
918 entry* add(const keyType& k, const label v, bool overwrite=false);
919
920 //- Add a scalar entry.
921 // \param overwrite force overwrite of an existing entry.
922 // \return pointer to inserted entry or nullptr on failure
923 entry* add(const keyType& k, const scalar v, bool overwrite=false);
924
925 //- Add a dictionary entry.
926 // \param mergeEntry merge into an existing sub-dictionary
927 // \return pointer to inserted entry, or place of merging
928 // or nullptr on failure
929 entry* add
930 (
931 const keyType& k,
932 const dictionary& d,
933 bool mergeEntry = false
934 );
935
936 //- Add a T entry
937 // \param overwrite force overwrite of existing entry
938 // \return pointer to inserted entry or nullptr on failure
939 template<class T>
940 entry* add(const keyType& k, const T& v, bool overwrite=false);
941
942 //- Assign a new entry, overwriting any existing entry.
943 //
944 // \return pointer to inserted entry or nullptr on failure
945 entry* set(entry* entryPtr);
946
947 //- Assign a new entry, overwriting any existing entry.
948 //
949 // \return pointer to inserted entry or nullptr on failure
950 entry* set(const entry& e);
951
952 //- Assign a dictionary entry, overwriting any existing entry.
953 //
954 // \return pointer to inserted entry or nullptr on failure
955 entry* set(const keyType& k, const dictionary& v);
956
957 //- Assign an empty primitive entry,
958 //- overwriting any existing entry.
959 // \return pointer to entry or nullptr on failure
960 entry* set(const keyType& k, std::nullptr_t);
961
962 //- Assign a primitive entry from a list of tokens,
963 //- overwriting any existing entry.
964 // \return pointer to entry or nullptr on failure
965 entry* set(const keyType& k, const UList<token>& tokens);
966
967 //- Assign a primitive entry from a list of tokens,
968 //- overwriting any existing entry.
969 // \return pointer to entry or nullptr on failure
970 entry* set(const keyType& k, List<token>&& tokens);
971
972 //- Assign a T entry, overwriting any existing entry.
973 // \return pointer to inserted entry or nullptr on failure
974 template<class T>
975 entry* set(const keyType& k, const T& v);
976
977 //- Remove an entry specified by keyword
978 bool remove(const word& keyword);
979
980 //- Change the keyword for an entry,
981 // \param overwrite force overwrite of an existing entry.
982 bool changeKeyword
983 (
984 const keyType& oldKeyword,
985 const keyType& newKeyword,
986 bool overwrite=false
987 );
988
989 //- Merge entries from the given dictionary.
990 // Also merge sub-dictionaries as required.
991 bool merge(const dictionary& dict);
992
993 //- Clear the dictionary
994 void clear();
995
996 //- Transfer the contents of the argument and annul the argument.
997 void transfer(dictionary& dict);
998
999
1000 // Read
1001
1002 //- Check after reading if the input token stream has unconsumed
1003 //- tokens remaining or if there were no tokens in the first place.
1004 // Emits FatalIOError
1005 void checkITstream(const ITstream& is, const word& keyword) const;
1006
1007 //- Read dictionary from Istream (discards the header).
1008 //- Reads entries until EOF or when the first token is a
1009 //- '{' character, it will stop reading at the matching '}' character.
1010 bool read(Istream& is);
1011
1012 //- Read dictionary from Istream (optionally keeping the header)
1013 //- Reads entries until EOF or when the first token is a
1014 //- '{' character, it will stop reading at the matching '}' character.
1015 bool read(Istream& is, bool keepHeader);
1016
1017
1018 // Write
1019
1020 //- Write sub-dictionary with its dictName as its header
1021 void writeEntry(Ostream& os) const;
1022
1023 //- Write sub-dictionary with the keyword as its header
1024 void writeEntry(const keyType& keyword, Ostream& os) const;
1025
1026 //- Write dictionary entries.
1027 // \param extraNewLine adds additional newline between entries
1028 // for "top-level" dictionaries
1029 void writeEntries(Ostream& os, const bool extraNewLine=false) const;
1030
1031 //- Write dictionary, normally with sub-dictionary formatting
1032 void write(Ostream& os, const bool subDict=true) const;
1033
1034
1035 // Searching
1036
1037 //- Search dictionary for given keyword
1038 //
1039 // \param keyword the keyword to search for
1040 // \param matchOpt search mode (default: non-recursive with patterns)
1042 (
1043 const word& keyword,
1044 enum keyType::option matchOpt = keyType::REGEX
1045 ) const;
1046
1047 //- Search dictionary for given keyword
1048 //
1049 // \param keyword the keyword to search for
1050 // \param matchOpt search mode (default: non-recursive with patterns)
1052 (
1053 const word& keyword,
1054 enum keyType::option matchOpt = keyType::REGEX
1055 ) const;
1056
1057 //- Search dictionary for given keyword
1058 //
1059 // \param keyword the keyword to search for
1060 // \param matchOpt search mode (default: non-recursive with patterns)
1062 (
1063 const word& keyword,
1064 enum keyType::option matchOpt = keyType::REGEX
1065 );
1066
1067 //- Search using scoping.
1068 // There are two types of scoping available:
1069 // -# dot-scoping, where a '.' is used to delineate the scope
1070 // -# slash-scoping, where a '/' is used to delineate the scope
1071 //
1072 // For dot-scoping, a leading '^' traverses to the top-level
1073 // dictionary, leading dots mean use the parent dictionary and an
1074 // intermediate dot separates a sub-dictionary or sub-entry.
1075 // However, since the use of dots is ambiguous ("a.b.c" could be
1076 // an entry itself or represent a "bc" entry from dictionary "a" etc),
1077 // the heuristic backtracks and attempts successively longer
1078 // top-level entries until a suitable match is found.
1079 //
1080 // For slash-scoping, semantics similar to directory structures are
1081 // used. A leading '/' traverses to the top-level dictionary,
1082 // a single leading or intermediate '.' references the current
1083 // dictionary level. A '..' pair references the parent dictionary.
1084 // Any doubled slashes are silently ignored.
1085 // Since a slash is not a valid keyword character, there is no
1086 // ambiguity between separator and content.
1087 //
1088 // \param keyword the keyword to search for
1089 // \param matchOpt search mode
1091 (
1092 const word& keyword,
1093 enum keyType::option matchOpt
1094 ) const;
1095
1096 //- Search using dot or slash scoping.
1097 //
1098 // \param keyword the keyword to search for
1099 // \param matchOpt search mode
1101 (
1102 const word& keyword,
1103 enum keyType::option matchOpt
1104 ) const;
1105
1106 //- Search using dot or slash scoping.
1107 //
1108 // \param keyword the keyword to search for
1109 // \param matchOpt search mode
1111 (
1112 const word& keyword,
1113 enum keyType::option matchOpt
1114 );
1115
1116 //- Locate a sub-dictionary using slash-scoping
1117 // \return nullptr if the dictionary path does not exist
1118 const dictionary* cfindScopedDict(const fileName& dictPath) const;
1119
1120 //- Locate a sub-dictionary using slash-scoping
1121 // \return nullptr if the dictionary path does not exist
1122 const dictionary* findScopedDict(const fileName& dictPath) const;
1123
1124 //- Locate a sub-dictionary using slash-scoping
1125 // \return nullptr if the dictionary path does not exist
1127
1128 //- Locate existing or create sub-dictionary using slash-scoping
1129 // \return nullptr if the dictionary path could not be created
1131
1132
1133 // Compatibility helpers
1134
1135 //- Search dictionary for given keyword and any compatibility names
1136 //
1137 // \param keyword the keyword to search for
1138 // \param compat list of old compatibility keywords and the last
1139 // OpenFOAM version for which they were used.
1140 // Old version 1600=OpenFOAM-v3.0, 240=OpenFOAM-2.4.x,
1141 // 170=OpenFOAM-1.7.x,...
1142 // \param matchOpt search mode (default: non-recursive with patterns)
1144 (
1145 const word& keyword,
1146 std::initializer_list<std::pair<const char*,int>> compat,
1147 enum keyType::option matchOpt = keyType::REGEX
1148 ) const;
1149
1150 //- Find and return an entry pointer if present, or return a nullptr,
1151 //- using any compatibility names if needed.
1152 //
1153 // \param keyword the keyword to search for
1154 // \param compat list of old compatibility keywords and the last
1155 // OpenFOAM version for which they were used.
1156 // \param matchOpt search mode
1157 const entry* findCompat
1158 (
1159 const word& keyword,
1160 std::initializer_list<std::pair<const char*,int>> compat,
1161 enum keyType::option matchOpt
1162 ) const;
1163
1164 //- Search dictionary for given keyword and any compatibility names
1165 //
1166 // \param keyword the keyword to search for
1167 // \param compat list of old compatibility keywords and the last
1168 // OpenFOAM version for which they were used.
1169 // \param matchOpt search mode (default: non-recursive with patterns)
1170 bool foundCompat
1171 (
1172 const word& keyword,
1173 std::initializer_list<std::pair<const char*,int>> compat,
1174 enum keyType::option matchOpt = keyType::REGEX
1175 ) const;
1176
1177 //- Find and return an entry if present, otherwise FatalIOError,
1178 //- using any compatibility names if needed.
1179 //
1180 // \param keyword the keyword to search for
1181 // \param compat list of old compatibility keywords and the last
1182 // OpenFOAM version for which they were used.
1183 // \param matchOpt search mode
1185 (
1186 const word& keyword,
1187 std::initializer_list<std::pair<const char*,int>> compat,
1188 enum keyType::option matchOpt
1189 ) const;
1190
1191 //- Find and return an entry data stream,
1192 //- using any compatibility names if needed.
1193 //
1194 // \param keyword the keyword to search for
1195 // \param compat list of old compatibility keywords and the last
1196 // OpenFOAM version for which they were used.
1197 // \param matchOpt search mode (default: non-recursive with patterns)
1199 (
1200 const word& keyword,
1201 std::initializer_list<std::pair<const char*,int>> compat,
1202 enum keyType::option matchOpt = keyType::REGEX
1203 ) const;
1204
1205 //- Find and return a T
1206 //- using any compatibility names if needed.
1207 //- FatalIOError if not found, or if there are excess tokens.
1208 //
1209 // \param keyword the keyword to search for
1210 // \param compat list of old compatibility keywords and the last
1211 // OpenFOAM version for which they were used.
1212 // \param matchOpt search mode (default: non-recursive with patterns)
1213 template<class T>
1214 T getCompat
1215 (
1216 const word& keyword,
1217 std::initializer_list<std::pair<const char*,int>> compat,
1218 enum keyType::option matchOpt = keyType::REGEX
1219 ) const;
1220
1221 //- Find and return a T, or return the given default value
1222 //- using any compatibility names if needed.
1223 //
1224 // \param keyword the keyword to search for
1225 // \param compat list of old compatibility keywords and the last
1226 // OpenFOAM version for which they were used.
1227 // \param deflt the default value to use
1228 // \param matchOpt search mode (default: non-recursive with patterns)
1229 template<class T>
1231 (
1232 const word& keyword,
1233 std::initializer_list<std::pair<const char*,int>> compat,
1234 const T& deflt,
1235 enum keyType::option matchOpt = keyType::REGEX
1236 ) const;
1237
1238 //- Find entry and assign to T val
1239 //- using any compatibility names if needed.
1240 //- FatalIOError if there are excess tokens.
1241 //
1242 // \param keyword the keyword to search for
1243 // \param compat list of old compatibility keywords and the last
1244 // OpenFOAM version for which they were used.
1245 // \param val the value to read
1246 // \param matchOpt search mode (default: non-recursive with patterns)
1247 // \param readOpt the entry is required/optional (default: MUST_READ)
1248 //
1249 // \return true if the entry was read
1250 template<class T>
1251 bool readCompat
1252 (
1253 const word& keyword,
1254 std::initializer_list<std::pair<const char*,int>> compat,
1255 T& val,
1256 enum keyType::option matchOpt = keyType::REGEX,
1257 IOobjectOption::readOption readOpt = IOobjectOption::MUST_READ
1258 ) const;
1259
1260 //- Find an entry if present, and assign to T val
1261 //- using any compatibility names if needed.
1262 //- FatalIOError if it is found and there are excess tokens.
1263 //
1264 // \param keyword the keyword to search for
1265 // \param compat list of old compatibility keywords and the last
1266 // OpenFOAM version for which they were used.
1267 // \param val the value to read
1268 // \param matchOpt search mode (default: non-recursive with patterns)
1269 //
1270 // \return true if the entry was found.
1271 template<class T>
1273 (
1274 const word& keyword,
1275 std::initializer_list<std::pair<const char*,int>> compat,
1276 T& val,
1277 enum keyType::option matchOpt = keyType::REGEX
1278 ) const;
1279
1280
1281 // Member Operators
1282
1283 //- Copy assignment
1284 void operator=(const dictionary& rhs);
1285
1286 //- Include entries from the given dictionary.
1287 // Warn, but do not overwrite existing entries.
1288 void operator+=(const dictionary& rhs);
1289
1290 //- Conditionally include entries from the given dictionary.
1291 // Do not overwrite existing entries.
1292 void operator|=(const dictionary& rhs);
1293
1294 //- Unconditionally include entries from the given dictionary.
1295 // Overwrite existing entries.
1296 void operator<<=(const dictionary& rhs);
1297
1298
1299 // IOstream operators
1300
1301 //- Read dictionary from Istream
1302 friend Istream& operator>>(Istream& is, dictionary& dict);
1303
1304 //- Write dictionary to Ostream
1305 friend Ostream& operator<<(Ostream& os, const dictionary& dict);
1306
1307
1308 // Shortcuts - when a templated classes also inherits from a dictionary
1309
1310 #undef defineDictionaryGetter
1311 #define defineDictionaryGetter(Func, Type) \
1312 \
1313 Type Func \
1314 ( \
1315 const word& keyword, \
1316 enum keyType::option matchOpt = keyType::REGEX \
1317 ) const \
1318 { \
1319 return get<Type>(keyword, matchOpt); \
1320 }
1321
1328
1329 #undef defineDictionaryGetter
1330
1331
1332 // Housekeeping
1333
1334 //- Check for existence of a sub-dictionary.
1335 //- Generally prefer findDict() for more flexibility.
1336 FOAM_DEPRECATED_STRICT(2024-05, "findDict()")
1337 bool isDict
1338 (
1339 const word& keyword,
1340 enum keyType::option matchOpt = keyType::REGEX
1341 ) const
1342 {
1343 return static_cast<bool>(findDict(keyword, matchOpt));
1344 }
1345
1346 //- Same as getOrDefault()
1347 template<class T>
1348 FOAM_DEPRECATED_STRICT(2019-06, "getOrDefault()")
1350 (
1351 const word& keyword,
1352 const T& deflt,
1353 enum keyType::option matchOpt = keyType::REGEX
1354 ) const
1355 {
1356 return getOrDefault<T>(keyword, deflt, matchOpt);
1357 }
1358
1359 //- Same as getOrAdd()
1360 template<class T>
1361 FOAM_DEPRECATED_STRICT(2019-06, "getOrAdd()")
1363 (
1364 const word& keyword,
1365 const T& deflt,
1366 enum keyType::option matchOpt = keyType::REGEX
1367 )
1368 {
1369 return getOrAdd<T>(keyword, deflt, matchOpt);
1370 }
1371
1372 //- Deprecated(2018-07) - use lookup() method
1373 // \deprecated(2018-07) - use lookup() method
1374 FOAM_DEPRECATED_FOR(2018-07, "lookup() method")
1375 ITstream& operator[](const word& keyword) const
1376 {
1377 return lookup(keyword);
1378 }
1379
1380 //- Deprecated(2018-10)
1381 // \deprecated(2018-10) - use keyType::option version
1382 FOAM_DEPRECATED_FOR(2018-10, "found(keyType::option)")
1383 bool found
1384 (
1385 const word& keyword,
1386 bool recursive,
1387 bool patternMatch = true
1388 ) const
1389 {
1390 return found(keyword, matchOpt(recursive, patternMatch));
1391 }
1392
1393 //- Deprecated(2018-10)
1394 // \deprecated(2018-10) - use findEntry() method
1395 FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1397 (
1398 const word& keyword,
1399 bool recursive,
1400 bool patternMatch
1401 )
1402 {
1403 return findEntry(keyword, matchOpt(recursive, patternMatch));
1404 }
1405
1406 //- Deprecated(2018-10)
1407 // \deprecated(2018-10) - use findEntry() method
1408 FOAM_DEPRECATED_FOR(2018-10, "findEntry(keyType::option)")
1409 const entry* lookupEntryPtr
1410 (
1411 const word& keyword,
1412 bool recursive,
1413 bool patternMatch
1414 ) const
1415 {
1416 return findEntry(keyword, matchOpt(recursive, patternMatch));
1417 }
1418
1419 //- Deprecated(2018-10)
1420 // \deprecated(2018-10) - use findScoped() method
1421 FOAM_DEPRECATED_FOR(2018-10, "findScoped(keyType::option)")
1423 (
1424 const word& keyword,
1425 bool recursive,
1426 bool patternMatch
1427 ) const
1428 {
1429 return findScoped(keyword, matchOpt(recursive, patternMatch));
1430 }
1431
1432 //- Deprecated(2018-10)
1433 // Find and return a sub-dictionary pointer if present
1434 // (and a sub-dictionary) otherwise return nullptr.
1435 //
1436 // Search type: non-recursive with patterns.
1437 // \deprecated(2018-10) - use findDict() method
1438 FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1439 const dictionary* subDictPtr(const word& keyword) const
1440 {
1441 return findDict(keyword, keyType::REGEX);
1442 }
1443
1444 //- Deprecated(2018-10)
1445 //- Find and return a sub-dictionary pointer if present
1446 // (and a sub-dictionary) otherwise return nullptr.
1447 //
1448 // Search type: non-recursive with patterns.
1449 // \deprecated(2018-10) - use findDict() method
1450 FOAM_DEPRECATED_FOR(2018-10, "findDict() method")
1451 dictionary* subDictPtr(const word& keyword)
1452 {
1453 return findDict(keyword, keyType::REGEX);
1454 }
1455
1456 //- Deprecated(2018-10)
1457 // \deprecated(2018-10) - use keyType::option version
1458 FOAM_DEPRECATED_FOR(2018-10, "lookupEntry(keyType::option)")
1459 const entry& lookupEntry
1460 (
1461 const word& keyword,
1462 bool recursive,
1463 bool patternMatch
1464 ) const
1465 {
1466 return lookupEntry(keyword, matchOpt(recursive, patternMatch));
1467 }
1468
1469 //- Deprecated(2018-10)
1470 // \deprecated(2018-10) - use keyType::option version
1471 FOAM_DEPRECATED_FOR(2018-10, "lookup(keyType::option)")
1472 ITstream& lookup
1473 (
1474 const word& keyword,
1475 bool recursive,
1476 bool patternMatch = true
1477 ) const
1478 {
1479 return lookup(keyword, matchOpt(recursive, patternMatch));
1480 }
1481
1482 //- Deprecated(2018-10)
1483 // \deprecated(2018-10) - use keyType::option version
1484 template<class T>
1485 FOAM_DEPRECATED_FOR(2018-10, "getOrDefault(keyType::option)")
1487 (
1488 const word& keyword,
1489 const T& deflt,
1490 bool recursive,
1491 bool patternMatch = true
1492 ) const
1493 {
1494 return getOrDefault(keyword, matchOpt(recursive, patternMatch));
1495 }
1496
1497 //- Deprecated(2018-10)
1498 // \deprecated(2018-10) - use keyType::option version
1499 template<class T>
1500 FOAM_DEPRECATED_FOR(2018-10, "getOrAdd(keyType::option)")
1502 (
1503 const word& keyword,
1504 const T& deflt,
1505 bool recursive,
1506 bool patternMatch = true
1507 )
1508 {
1509 return getOrAdd(keyword, deflt, matchOpt(recursive, patternMatch));
1510 }
1511
1512 //- Deprecated(2018-10)
1513 // \deprecated(2018-10) - use keyType::option version
1514 template<class T>
1515 FOAM_DEPRECATED_FOR(2018-10, "readIfPresent(keyType::option)")
1516 bool readIfPresent
1517 (
1518 const word& keyword,
1519 T& val,
1520 bool recursive,
1521 bool patternMatch = true
1522 ) const
1523 {
1524 return
1526 (keyword, val, matchOpt(recursive, patternMatch));
1527 }
1528
1529
1530 // More compatibility
1531
1532 //- Deprecated(2018-10) find and return a T.
1533 // \deprecated(2018-10) - use get() method
1534 template<class T>
1535 FOAM_DEPRECATED_FOR(2018-10, "get() method")
1537 (
1538 const word& keyword,
1539 bool recursive = false,
1540 bool patternMatch = true
1541 ) const
1542 {
1543 return get<T>(keyword, matchOpt(recursive, patternMatch));
1544 }
1545
1546 #ifdef COMPAT_OPENFOAM_ORG
1548 // Only available if compiled with COMPAT_OPENFOAM_ORG
1549 template<class T>
1550 FOAM_DEPRECATED_FOR(2019-11, "get() method - openfoam.org compat")
1551 T lookup
1552 (
1553 const word& keyword,
1554 bool recursive = false,
1555 bool patternMatch = true
1556 ) const
1557 {
1558 return get<T>(keyword, matchOpt(recursive, patternMatch));
1559 }
1560 #endif
1561};
1562
1563
1564// Global Operators
1565
1566//- Combine dictionaries.
1567// Starting from the entries in dict1 and then including those from dict2.
1568// Warn, but do not overwrite the entries from dict1.
1569dictionary operator+(const dictionary& dict1, const dictionary& dict2);
1570
1571//- Combine dictionaries.
1572// Starting from the entries in dict1 and then including those from dict2.
1573// Do not overwrite the entries from dict1.
1574dictionary operator|(const dictionary& dict1, const dictionary& dict2);
1575
1576
1577// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1578
1579} // End namespace Foam
1580
1581// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1582
1583#include "dictionaryI.H"
1584
1585// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1586
1587#ifdef NoRepository
1588 #include "dictionaryTemplates.C"
1589#endif
1590
1591// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1592
1593#endif
1594
1595// ************************************************************************* //
Non-intrusive doubly-linked list.
Intrusive doubly-linked list.
label k
bool found
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
An input stream of tokens.
Definition ITstream.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
Generic output stream using a standard (STL) stream.
Definition OSstream.H:53
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
The SHA1 message digest.
Definition SHA1Digest.H:58
friend Ostream & operator(Ostream &os, const UILList< DLListBase, T > &lst)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Generic const/non-const dictionary entry searcher.
Definition dictionary.H:151
void set(pointer eptr) noexcept
Assign the entry.
Definition dictionary.H:213
dict_type & dict_reference
A reference to a const/non-const dictionary.
Definition dictionary.H:175
bool found() const noexcept
True if entry was found.
Definition dictionary.H:241
value_type * pointer
A pointer to a const/non-const entry.
Definition dictionary.H:180
bool good() const noexcept
True if entry was found.
Definition dictionary.H:234
std::conditional_t< Const, const dictionary, dictionary > dict_type
The const/non-const type for the context and sub-dictionaries.
Definition dictionary.H:158
value_type & reference
A reference to a const/non-const entry.
Definition dictionary.H:185
pointer ptr() const noexcept
A pointer to the entry (nullptr if not found).
Definition dictionary.H:251
dict_reference dict() const
Definition dictionary.H:294
bool isDict() const noexcept
True if found entry is a dictionary.
Definition dictionary.H:261
dict_type * dict_pointer
A pointer to a const/non-const dictionary.
Definition dictionary.H:170
dict_reference context() const
The containing dictionary context.
Definition dictionary.H:246
Searcher(dict_pointer dict) noexcept
Implicit construct for the given dictionary context.
Definition dictionary.H:204
std::conditional_t< Const, const entry, entry > value_type
The const/non-const type for entries.
Definition dictionary.H:164
reference operator*() const
A reference to the entry (Error if not found).
Definition dictionary.H:318
ITstream * streamPtr() const noexcept
Pointer to the found entry as a stream, nullptr otherwise.
Definition dictionary.H:285
pointer operator->() const noexcept
A pointer to the entry (nullptr if not found).
Definition dictionary.H:313
bool isStream() const noexcept
True if found entry is a stream.
Definition dictionary.H:269
ITstream & stream() const
Return the found entry as a ITstream. Error if not found, or not a stream.
Definition dictionary.H:300
constexpr Searcher() noexcept
Default construct.
Definition dictionary.H:224
reference ref() const
A reference to the entry (Error if not found).
Definition dictionary.H:256
dict_pointer dictPtr() const noexcept
Pointer to the found entry as a dictionary, nullptr otherwise.
Definition dictionary.H:277
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary.
Definition dictionary.C:521
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt) const
Find and return an entry pointer if present, or return a nullptr, using any compatibility names if ne...
bool foundCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
void transfer(dictionary &dict)
Transfer the contents of the argument and annul the argument.
Definition dictionary.C:871
bool isNullDict() const noexcept
The dictionary is actually dictionary::null (root dictionary).
Definition dictionaryI.H:71
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition dictionary.C:560
static int reportOptional() noexcept
Return the state of reporting optional (default) entries.
Definition dictionaryI.H:25
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool overwrite=false)
Change the keyword for an entry,.
const fileName & name() const noexcept
The dictionary name.
Definition dictionaryI.H:41
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
bool readIfPresentCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val using any compatibility names if needed....
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition dictionary.C:481
void checkITstream(const ITstream &is, const word &keyword) const
Check after reading if the input token stream has unconsumed tokens remaining or if there were no tok...
Definition dictionary.C:251
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect,...
fileName getFileName(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<fileName>(const word&, keyType::option).
const entry * lookupScopedEntryPtr(const word &keyword, bool recursive, bool patternMatch) const
Deprecated(2018-10).
const dictionary & topDict() const
Return the top of the tree.
Definition dictionary.C:185
bool readCheck(const word &keyword, T &val, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect,...
static refPtr< OSstream > reportingOutput
Output location when reporting default values.
Definition dictionary.H:492
T lookupType(const word &keyword, bool recursive=false, bool patternMatch=true) const
Deprecated(2018-10) find and return a T.
bool substituteKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given keyword (which is prefixed by '$').
Definition dictionary.C:377
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
ClassName("dictionary")
dictionary()
Default construct, a top-level empty dictionary.
Definition dictionary.C:68
autoPtr< dictionary > clone() const
Construct and return clone.
Definition dictionary.C:165
entry * lookupEntryPtr(const word &keyword, bool recursive, bool patternMatch)
Deprecated(2018-10).
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition dictionary.H:482
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition dictionary.C:179
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T using any compatibility names if needed. FatalIOError if not found,...
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition dictionary.C:817
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition dictionaryI.H:84
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Same as getOrDefault().
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value using any compatibility names if needed.
string getString(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<string>(const word&, keyType::option).
word getWord(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<word>(const word&, keyType::option).
const_searcher csearchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using scoping.
const dictionary * findScopedDict(const fileName &dictPath) const
Locate a sub-dictionary using slash-scoping.
bool remove(const word &keyword)
Remove an entry specified by keyword.
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition dictionary.C:234
static autoPtr< dictionary > New(Istream &is)
Construct top-level dictionary on freestore from Istream.
label getLabel(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<label>(const word&, keyType::option).
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition dictionary.C:607
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T with additional checking FatalIOError if not found, or if the number of tokens is...
T lookupOrAddDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Same as getOrAdd().
const dictionary * subDictPtr(const word &keyword) const
Deprecated(2018-10).
friend class entry
Declare friendship with the entry class for IO.
Definition dictionary.H:338
dictionary * makeScopedDict(const fileName &dictPath)
Locate existing or create sub-dictionary using slash-scoping.
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream.
Definition dictionary.C:367
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
T getCheckOrDefault(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
bool readCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val using any compatibility names if needed. FatalIOError if there are exc...
const_searcher search(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
label endLineNumber() const
Return line number of last token in dictionary.
Definition dictionary.C:209
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by '$').
Definition dictionary.C:409
void writeEntries(Ostream &os, const bool extraNewLine=false) const
Write dictionary entries.
wordList sortedToc() const
Return the sorted table of contents.
Definition dictionary.C:601
ITstream & lookupCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream, using any compatibility names if needed.
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
const dictionary * cfindScopedDict(const fileName &dictPath) const
Locate a sub-dictionary using slash-scoping.
scalar getScalar(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<scalar>(const word&, keyType::option).
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition dictionaryI.H:77
const entry & lookupEntry(const word &keyword, enum keyType::option matchOpt) const
Search for an entry (const access) with the given keyword.
Definition dictionary.C:347
const entry & lookupEntryCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt) const
Find and return an entry if present, otherwise FatalIOError, using any compatibility names if needed.
const_searcher csearch(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
Searcher< false > searcher
Searcher with non-const access.
Definition dictionary.H:330
Searcher< true > const_searcher
Searcher with const access.
Definition dictionary.H:325
void clear()
Clear the dictionary.
Definition dictionary.C:862
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check for existence of a sub-dictionary. Generally prefer findDict() for more flexibility.
ITstream * findStream(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry stream if present (and it is a stream) otherwise return nullptr.
T getOrAdd(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX)
Find and return a T, or return the given default value and add it to dictionary. FatalIOError if it i...
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition dictionary.C:625
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
wordList toc() const
Return the table of contents.
Definition dictionary.C:587
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition dictionary.C:765
bool read(Istream &is)
Read dictionary from Istream (discards the header). Reads entries until EOF or when the first token i...
label startLineNumber() const
Return line number of first token in dictionary.
Definition dictionary.C:198
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
const_searcher searchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using dot or slash scoping.
bool readCheckIfPresent(const word &keyword, T &val, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
T getCheckOrAdd(const word &keyword, const T &deflt, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX)
Find and return a T, or return the given default value and add it to dictionary. FatalIOError if it i...
word dictName() const
The local dictionary name (final part of scoped name).
Definition dictionaryI.H:53
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition dictionary.C:220
bool getBool(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Same as get<bool>(const word&, keyType::option).
A class for handling file names.
Definition fileName.H:75
A class for handling keywords in dictionaries.
Definition keyType.H:69
option
Enumeration for the data type and search/match modes (bitmask).
Definition keyType.H:80
@ LITERAL
String literal.
Definition keyType.H:82
@ REGEX
Regular expression.
Definition keyType.H:83
@ RECURSIVE
Recursive search (eg, in dictionary).
Definition keyType.H:86
Lookup type of boundary radiation properties.
Definition lookup.H:60
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
A token holds an item read from Istream.
Definition token.H:70
A class for handling words, derived from Foam::string.
Definition word.H:66
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
const volScalarField & T
#define defineDictionaryGetter(Func, Type)
OBJstream os(runTime.globalPath()/outputName)
fileName dictPath(runTime.system()/regionDir/faMesh::prefix()/areaRegionDir/dictName)
Namespace for OpenFOAM.
ILList< DLListBase, T > IDLList
Definition IDLList.H:39
List< word > wordList
List of word.
Definition fileName.H:60
bitSet operator|(const bitSet &a, const bitSet &b)
Bitwise-OR of two bitsets.
Definition bitSetI.H:692
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
List< token > tokenList
List of token, used for dictionary primitive entry (for example).
Definition tokenList.H:32
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
LList< DLListBase, T > DLList
Definition DLList.H:39
dictionary dict
volScalarField & e
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition stdFoam.H:53