dictionary.C
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) 2015-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "dictionary.H"
30 #include "error.H"
31 #include "JobInfo.H"
32 #include "primitiveEntry.H"
33 #include "dictionaryEntry.H"
34 #include "regExp.H"
35 #include "OSHA1stream.H"
36 #include "OSstream.H"
37 #include "argList.H"
38 #include "registerSwitch.H"
39 
40 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
41 
42 namespace Foam
43 {
44  defineTypeNameAndDebug(dictionary, 0);
45 }
46 
48 
50 
52 (
53  Foam::debug::infoSwitch("writeOptionalEntries", 0)
54 );
55 
56 
58 (
59  "writeOptionalEntries",
60  int,
62 );
63 
64 
65 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
66 
67 Foam::word Foam::dictionary::executableName()
68 {
69  return argList::envExecutable();
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 :
77  name_(),
78  parent_(dictionary::null)
79 {}
80 
81 
83 :
84  name_(name),
85  parent_(dictionary::null)
86 {}
87 
88 
90 (
91  const dictionary& parentDict,
92  const dictionary& dict
93 )
94 :
95  parent_type(dict, *this),
96  name_(dict.name()),
97  parent_(parentDict)
98 {
99  for (entry& e : *this)
100  {
101  hashedEntries_.insert(e.keyword(), &e);
102 
103  if (e.keyword().isPattern())
104  {
105  patterns_.push_front(&e);
106  regexps_.push_front(autoPtr<regExp>::New(e.keyword()));
107  }
108  }
109 }
110 
111 
113 (
114  const dictionary& dict
115 )
116 :
117  parent_type(dict, *this),
118  name_(dict.name()),
119  parent_(dictionary::null)
120 {
121  for (entry& e : *this)
122  {
123  hashedEntries_.insert(e.keyword(), &e);
124 
125  if (e.keyword().isPattern())
126  {
127  patterns_.push_front(&e);
128  regexps_.push_front(autoPtr<regExp>::New(e.keyword()));
129  }
130  }
131 }
132 
133 
134 Foam::dictionary::dictionary(const dictionary* dict)
135 :
136  name_(),
137  parent_(dictionary::null)
138 {
139  if (dict)
140  {
141  operator=(*dict);
142  }
143 }
144 
145 
147 (
148  const dictionary& parentDict,
149  dictionary&& dict
150 )
151 :
152  name_(),
153  parent_(parentDict)
154 {
155  transfer(dict);
156  name() = fileName::concat(parentDict.name(), name(), '/');
157 }
158 
159 
161 (
162  dictionary&& dict
163 )
164 :
165  name_(),
166  parent_(dictionary::null)
167 {
168  transfer(dict);
169 }
170 
171 
173 {
174  return autoPtr<dictionary>::New(*this);
175 }
176 
177 
178 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 Foam::fileName Foam::dictionary::relativeName(const bool caseTag) const
187 {
188  return argList::envRelativePath(name(), caseTag);
189 }
190 
191 
193 {
194  const dictionary& p = parent();
195 
196  if (&p != this && !p.name().empty())
197  {
198  return p.topDict();
199  }
200 
201  return *this;
202 }
203 
204 
205 Foam::label Foam::dictionary::startLineNumber() const
206 {
207  return
208  (
210  ? -1
211  : IDLList<entry>::front()->startLineNumber()
212  );
213 }
214 
215 
216 Foam::label Foam::dictionary::endLineNumber() const
217 {
218  return
219  (
221  ? -1
222  : IDLList<entry>::back()->endLineNumber()
223  );
224 }
225 
226 
228 {
229  OSHA1stream os;
230 
231  // Process entries
232  for (const entry& e : *this)
233  {
234  os << e;
235  }
236 
237  return os.digest();
238 }
239 
240 
242 {
243  // Serialize dictionary entries into a string
244  OStringStream os;
245 
246  // Process entries
247  for (const entry& e : *this)
248  {
249  os << e;
250  }
252  // String re-parsed as a list of tokens
253  return ITstream::parse(os.str());
254 }
255 
256 
258 (
259  const ITstream& is,
260  const word& keyword
261 ) const
262 {
263  const label remaining = (is.size() ? is.nRemainingTokens() : -100);
264 
265  if (!remaining)
266  {
267  return;
268  }
269 
270  // Similar to SafeFatalIOError
272  {
273  OSstream& err =
275  (
276  "", // functionName
277  "", // sourceFileName
278  0, // sourceFileLineNumber
279  relativeName(), // ioFileName == dictionary name
280  is.lineNumber() // ioStartLineNumber
281  );
282 
283  if (remaining > 0)
284  {
285  err
286  << "Entry '" << keyword << "' has "
287  << remaining << " excess tokens in stream" << nl << nl
288  << " ";
289  is.writeList(err, 0); // <- flatOutput
290  }
291  else
292  {
293  err << "Entry '" << keyword
294  << "' had no tokens in stream" << nl << nl;
295  }
296 
297  err << exit(FatalIOError);
298  }
299  else
300  {
301  // Not yet constructed
302 
303  std::cerr
304  << nl
305  << "--> FOAM FATAL IO ERROR:" << nl;
306 
307  if (remaining > 0)
308  {
309  std::cerr
310  << "Entry '" << keyword << "' has "
311  << remaining << " excess tokens in stream" << nl << nl;
312  }
313  else
314  {
315  std::cerr
316  << "Entry '" << keyword
317  << "' had no tokens in stream" << nl << nl;
318  }
319 
320  std::cerr
321  // ioFileName == dictionary name
322  << "file: " << relativeName()
323  << " at line " << is.lineNumber() << '.' << nl
324  << std::endl;
325 
326  std::exit(1);
327  }
328 }
329 
330 
331 void Foam::dictionary::raiseBadInput
332 (
333  const ITstream& is,
334  const word& keyword
335 ) const
336 {
337  // Can use FatalIOError instead of SafeFatalIOError
338  // since predicate checks are not used at the earliest stages
340  (
341  "", // functionName
342  "", // sourceFileName
343  0, // sourceFileLineNumber
344  relativeName(), // ioFileName == dictionary name
345  is.lineNumber(), // ioStartLineNumber
346  -1 // ioEndLineNumber
347  )
348  << "Entry '" << keyword << "' with invalid input" << nl
349  << exit(FatalIOError);
350 }
351 
352 
354 (
355  const word& keyword,
356  enum keyType::option matchOpt
357 ) const
358 {
359  const entry* eptr = findEntry(keyword, matchOpt);
360 
361  if (!eptr)
362  {
364  << "Entry '" << keyword << "' not found in dictionary "
365  << relativeName() << nl
366  << exit(FatalIOError);
367  }
368 
369  return *eptr;
370 }
371 
372 
374 (
375  const word& keyword,
376  enum keyType::option matchOpt
377 ) const
378 {
379  return lookupEntry(keyword, matchOpt).stream();
380 }
381 
382 
384 (
385  const word& keyword,
386  bool mergeEntry
387 )
388 {
389  if (keyword.size() < 2)
390  {
391  return false;
392  }
393 
394  // Drop leading '$' to get the var-name, already validated as word.
395  const word varName(keyword.substr(1), false);
396 
397  // Lookup the variable name in the given dictionary
398  const const_searcher finder(csearch(varName, keyType::REGEX_RECURSIVE));
399 
400  // If defined insert its entries into this dictionary
401  if (finder.good())
402  {
403  for (const entry& e : finder.dict())
404  {
405  add(e, mergeEntry);
406  }
407 
408  return true;
409  }
410 
411  return false;
412 }
413 
414 
416 (
417  const word& keyword,
418  bool mergeEntry
419 )
420 {
421  if (keyword.size() < 2)
422  {
423  return false;
424  }
425 
426  // Drop leading '$' to get the var-name, already validated as word.
427  const word varName(keyword.substr(1), false);
428 
429  // Lookup the variable name in the given dictionary
430  const auto finder(csearchScoped(varName, keyType::REGEX_RECURSIVE));
431 
432  // If defined insert its entries into this dictionary
433  if (finder.good())
434  {
435  for (const entry& e : finder.dict())
436  {
437  add(e, mergeEntry);
438  }
439 
440  return true;
441  }
442 
443  return false;
444 }
445 
446 
448 (
449  const word& keyword,
450  enum keyType::option matchOpt
451 ) const
452 {
453  const const_searcher finder(csearch(keyword, matchOpt));
454 
455  if (!finder.good())
456  {
458  << "Entry '" << keyword << "' not found in dictionary "
459  << relativeName() << nl
460  << exit(FatalIOError);
461  }
462 
463  return finder.dict();
464 }
465 
466 
468 (
469  const word& keyword,
470  enum keyType::option matchOpt
471 )
472 {
473  searcher finder(search(keyword, matchOpt));
474 
475  if (!finder.good())
476  {
478  << "Entry '" << keyword << "' not found in dictionary "
479  << relativeName() << nl
480  << exit(FatalIOError);
481  }
482 
483  return finder.dict();
484 }
485 
486 
488 (
489  const word& keyword,
490  enum keyType::option matchOpt
491 )
492 {
493  searcher finder(search(keyword, matchOpt));
494 
495  dictionary* dictPtr = finder.dictPtr();
496 
497  if (dictPtr)
498  {
499  // Found and a sub-dictionary
500  return *dictPtr;
501  }
502 
503  if (finder.good())
504  {
506  << "Entry '" << keyword
507  << "' is not a sub-dictionary in dictionary "
508  << relativeName() << nl
509  << exit(FatalIOError);
510  }
511 
512  dictPtr = this->set(keyword, dictionary())->dictPtr();
513 
514  if (!dictPtr)
515  {
517  << "Failed to insert sub-dictionary '" << keyword
518  << "' in dictionary "
519  << relativeName() << nl
520  << exit(FatalIOError);
521  }
522 
523  return *dictPtr;
524 }
525 
526 
528 (
529  const word& keyword,
530  enum keyType::option matchOpt,
531  const bool mandatory
532 ) const
533 {
534  const const_searcher finder(csearch(keyword, matchOpt));
535 
536  const dictionary* dictPtr = finder.dictPtr();
537 
538  if (dictPtr)
539  {
540  // Found and a sub-dictionary
541  return *dictPtr;
542  }
543 
544  if (mandatory)
545  {
547  << "Entry '" << keyword
548  << "' is not a sub-dictionary in dictionary "
549  << relativeName() << nl
550  << exit(FatalIOError);
551  }
552 
553  if (finder.good())
554  {
555  IOWarningInFunction(*this)
556  << "Entry '" << keyword
557  << "' found but not a sub-dictionary in dictionary "
558  << relativeName() << endl;
559  }
561  // The move constructor properly qualifies the dictionary name
562  return dictionary(*this, dictionary(fileName(keyword)));
563 }
564 
565 
567 (
568  const word& keyword,
569  enum keyType::option matchOpt
570 ) const
571 {
572  const const_searcher finder(csearch(keyword, matchOpt));
573 
574  const dictionary* dictPtr = finder.dictPtr();
575 
576  if (dictPtr)
577  {
578  // Found and a sub-dictionary
579  return *dictPtr;
580  }
581 
582  if (finder.good())
583  {
584  IOWarningInFunction(*this)
585  << "Entry '" << keyword
586  << "' found but not a sub-dictionary in dictionary "
587  << relativeName() << endl;
588  }
589 
590  return *this;
591 }
592 
593 
595 {
596  wordList list(size());
597 
598  label n = 0;
599  for (const entry& e : *this)
600  {
601  list[n++] = e.keyword();
602  }
603 
604  return list;
605 }
606 
609 {
610  return hashedEntries_.sortedToc();
611 }
612 
613 
615 {
616  List<keyType> list(size());
617 
618  label n = 0;
619  for (const entry& e : *this)
620  {
621  if (e.keyword().isPattern() ? patterns : !patterns)
622  {
623  list[n++] = e.keyword();
624  }
625  }
626  list.resize(n);
627 
628  return list;
629 }
630 
631 
632 Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
633 {
634  if (!entryPtr)
635  {
636  return nullptr;
637  }
638 
639  auto iter = hashedEntries_.find(entryPtr->keyword());
640 
641  if (mergeEntry && iter.good())
642  {
643  // Merge dictionary with dictionary
644  if (iter()->isDict() && entryPtr->isDict())
645  {
646  iter()->dict().merge(entryPtr->dict());
647 
648  delete entryPtr;
649  return iter(); // pointer to existing dictionary
650  }
651 
652 
653  // Replace existing dictionary with entry or vice versa
654  parent_type::replace(iter(), entryPtr);
655  delete iter();
656  hashedEntries_.erase(iter);
657 
658  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
659  {
660  entryPtr->name() =
661  fileName::concat(name(), entryPtr->keyword(), '/');
662 
663  if (entryPtr->keyword().isPattern())
664  {
665  patterns_.push_front(entryPtr);
666  regexps_.push_front(autoPtr<regExp>::New(entryPtr->keyword()));
667  }
668 
669  return entryPtr; // now an entry in the dictionary
670  }
671 
672 
673  IOWarningInFunction(*this)
674  << "Problem replacing entry "<< entryPtr->keyword()
675  << " in dictionary " << relativeName() << endl;
676 
677  parent_type::remove(entryPtr);
678 
679  delete entryPtr;
680  return nullptr;
681  }
682 
683 
684  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
685  {
686  entryPtr->name() =
687  fileName::concat(name(), entryPtr->keyword(), '/');
688 
689  parent_type::push_back(entryPtr);
690 
691  if (entryPtr->keyword().isPattern())
692  {
693  patterns_.push_front(entryPtr);
694  regexps_.push_front(autoPtr<regExp>::New(entryPtr->keyword()));
695  }
696 
697  return entryPtr; // now an entry in the dictionary
698  }
699 
700 
701  IOWarningInFunction(*this)
702  << "Attempt to add entry " << entryPtr->keyword()
703  << " which already exists in dictionary "
704  << relativeName() << endl;
705 
706  delete entryPtr;
707  return nullptr;
708 }
709 
710 
711 Foam::entry* Foam::dictionary::add(const entry& e, bool mergeEntry)
712 {
713  return add(e.clone(*this).ptr(), mergeEntry);
714 }
715 
716 
718 (
719  const keyType& k,
720  const word& v,
721  bool overwrite
722 )
723 {
724  return add(new primitiveEntry(k, token(v)), overwrite);
725 }
726 
727 
729 (
730  const keyType& k,
731  const Foam::string& v,
732  bool overwrite
733 )
734 {
735  return add(new primitiveEntry(k, token(v)), overwrite);
736 }
737 
738 
740 (
741  const keyType& k,
742  const label v,
743  bool overwrite
744 )
745 {
746  return add(new primitiveEntry(k, token(v)), overwrite);
747 }
748 
749 
751 (
752  const keyType& k,
753  const scalar v,
754  bool overwrite
755 )
756 {
757  return add(new primitiveEntry(k, token(v)), overwrite);
758 }
759 
760 
762 (
763  const keyType& k,
764  const dictionary& v,
765  bool mergeEntry
766 )
767 {
768  return add(new dictionaryEntry(k, *this, v), mergeEntry);
769 }
770 
771 
773 {
774  if (!entryPtr)
775  {
776  return nullptr;
777  }
778 
779  // Find non-recursive with patterns
780  searcher finder(search(entryPtr->keyword(), keyType::REGEX));
781 
782  dictionary* dictPtr = finder.dictPtr();
783 
784  // Clear dictionary so merge acts like overwrite
785  if (dictPtr)
786  {
787  dictPtr->clear();
788  }
789 
790  return add(entryPtr, true);
791 }
792 
795 {
796  return set(e.clone(*this).ptr());
797 }
798 
801 {
802  return set(new dictionaryEntry(k, *this, v));
803 }
804 
805 
807 {
808  if (this == &dict)
809  {
811  << "Attempted merge to self, for dictionary "
812  << relativeName() << nl
813  << abort(FatalIOError);
814  }
815 
816  bool changed = false;
817 
818  for (const entry& e : dict)
819  {
820  auto fnd = hashedEntries_.find(e.keyword());
821 
822  if (fnd.good())
823  {
824  // Recursively merge sub-dictionaries
825  // TODO: merge without copying
826  if (fnd()->isDict() && e.isDict())
827  {
828  if (fnd()->dict().merge(e.dict()))
829  {
830  changed = true;
831  }
832  }
833  else
834  {
835  add(e.clone(*this).ptr(), true);
836  changed = true;
837  }
838  }
839  else
840  {
841  // Not found - just add
842  add(e.clone(*this).ptr());
843  changed = true;
844  }
845  }
846 
847  return changed;
848 }
849 
850 
852 {
854  hashedEntries_.clear();
855  patterns_.clear();
856  regexps_.clear();
857 }
858 
859 
861 {
862  // Changing parents probably doesn't make much sense,
863  // but what about the names?
864  name() = dict.name();
865 
866  parent_type::transfer(dict);
867  hashedEntries_.transfer(dict.hashedEntries_);
868  patterns_.transfer(dict.patterns_);
869  regexps_.transfer(dict.regexps_);
870 }
871 
872 
873 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
874 
876 {
877  if (this == &rhs)
878  {
879  return; // Self-assignment is a no-op
880  }
881 
882  name() = rhs.name();
883  clear();
884 
885  // Create clones of the entries in the given dictionary
886  // resetting the parentDict to this dictionary
887 
888  for (const entry& e : rhs)
889  {
890  add(e.clone(*this).ptr());
891  }
892 }
893 
894 
895 void Foam::dictionary::operator+=(const dictionary& rhs)
896 {
897  if (this == &rhs)
898  {
900  << "Attempted addition to self, for dictionary "
901  << relativeName() << nl
902  << abort(FatalIOError);
903  }
904 
905  for (const entry& e : rhs)
906  {
907  add(e.clone(*this).ptr());
908  }
909 }
910 
911 
912 void Foam::dictionary::operator|=(const dictionary& rhs)
913 {
914  if (this == &rhs)
915  {
917  << "Attempted |= merging to self, for dictionary "
918  << relativeName() << nl
919  << abort(FatalIOError);
920  }
921 
922  for (const entry& e : rhs)
923  {
924  if (!found(e.keyword()))
925  {
926  add(e.clone(*this).ptr());
927  }
928  }
929 }
930 
931 
932 void Foam::dictionary::operator<<=(const dictionary& rhs)
933 {
934  if (this == &rhs)
935  {
937  << "Attempted addition to self, for dictionary "
938  << relativeName() << nl
939  << abort(FatalIOError);
940  }
941 
942  for (const entry& e : rhs)
943  {
944  set(e.clone(*this).ptr());
945  }
946 }
947 
948 
949 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
950 
951 Foam::dictionary Foam::operator+
952 (
953  const dictionary& dict1,
954  const dictionary& dict2
955 )
956 {
957  dictionary result(dict1);
958  result += dict2;
959  return result;
960 }
961 
962 
963 Foam::dictionary Foam::operator|
964 (
965  const dictionary& dict1,
966  const dictionary& dict2
967 )
968 {
969  dictionary result(dict1);
970  result |= dict2;
971  return result;
972 }
973 
974 
975 // ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:45
registerInfoSwitch("writeOptionalEntries", int, Foam::dictionary::writeOptionalEntries)
A class for handling keywords in dictionaries.
Definition: keyType.H:66
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
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void operator<<=(const dictionary &rhs)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:925
A class for handling file names.
Definition: fileName.H:72
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:209
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:234
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:220
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void transfer(dictionary &dict)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:853
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
void operator|=(const dictionary &rhs)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:905
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A token holds an item read from Istream.
Definition: token.H:65
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by &#39;$&#39;)
Definition: dictionary.C:409
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
The SHA1 message digest.
Definition: SHA1Digest.H:56
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
const entry * findEntry(const dictionary &dict, const label val)
Linear search for labelled entry, nullptr if not found.
label k
Boltzmann constant.
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:176
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
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:228
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:41
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
label nRemainingTokens() const noexcept
Number of tokens remaining.
Definition: ITstream.H:371
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:165
wordList toc() const
Return the table of contents.
Definition: dictionary.C:587
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition: dictionary.C:481
static tokenList parse(const UList< char > &input, IOstreamOption streamOpt=IOstreamOption())
Create token list by parsing the input character sequence until no good tokens remain.
Definition: ITstream.C:88
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read...
dictionary()
Default construct, a top-level empty dictionary.
Definition: dictionary.C:68
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
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:799
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:76
static refPtr< OSstream > reportingOutput
Output location when reporting default values.
Definition: dictionary.H:479
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
const keyType & keyword() const noexcept
Return keyword.
Definition: entry.H:231
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:868
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:185
bool substituteKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given keyword (which is prefixed by &#39;$&#39;)
Definition: dictionary.C:377
patchWriters clear()
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
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
static fileName envRelativePath(const fileName &input, const bool caseTag=false)
Return the input relative to the globalPath by stripping off a leading value of the envGlobalPath...
Definition: argList.C:658
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:469
static fileName concat(const std::string &s1, const std::string &s2, const char delim='/')
Join two strings with a path separator (&#39;/&#39; by default).
Definition: fileName.C:211
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:179
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:607
label lineNumber() const noexcept
Const access to the current stream line number.
Definition: IOstream.H:390
static word envExecutable()
Name of the executable from environment variable.
Definition: argList.C:645
List< word > wordList
List of word.
Definition: fileName.H:59
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
virtual ~dictionary()
Destructor.
Definition: dictionary.C:173
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
label n
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:642
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
friend class entry
Declare friendship with the entry class for IO.
Definition: dictionary.H:325
volScalarField & p
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
void clear()
Clear the dictionary.
Definition: dictionary.C:844
A class for handling character strings derived from std::string.
Definition: string.H:72
void operator+=(const dictionary &rhs)
Include entries from the given dictionary.
Definition: dictionary.C:888
bool found
Regular expression.
Definition: keyType.H:83
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:198
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:601
An input stream of tokens.
Definition: ITstream.H:52
static bool constructed
Global value for constructed job info.
Definition: JobInfo.H:115
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...