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