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-2022 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_.prepend(&e);
106  regexps_.prepend(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_.prepend(&e);
128  regexps_.prepend(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  if (size())
208  {
209  return first()->startLineNumber();
210  }
211 
212  return -1;
213 }
214 
215 
216 Foam::label Foam::dictionary::endLineNumber() const
217 {
218  if (size())
219  {
220  return last()->endLineNumber();
221  }
222 
223  return -1;
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  if (is.nRemainingTokens())
264  {
265  const label remaining = is.nRemainingTokens();
266 
267  // Similar to SafeFatalIOError
269  {
270  OSstream& err =
272  (
273  "", // functionName
274  "", // sourceFileName
275  0, // sourceFileLineNumber
276  relativeName(), // ioFileName == dictionary name
277  is.lineNumber() // ioStartLineNumber
278  );
279 
280  err << "Entry '" << keyword << "' has "
281  << remaining << " excess tokens in stream" << nl << nl
282  << " ";
283  is.writeList(err, 0);
284 
285  err << exit(FatalIOError);
286  }
287  else
288  {
289  std::cerr
290  << nl
291  << "--> FOAM FATAL IO ERROR:" << nl;
292 
293  std::cerr
294  << "Entry '" << keyword << "' has "
295  << remaining << " excess tokens in stream" << nl << nl;
296 
297  std::cerr
298  // ioFileName == dictionary name
299  << "file: " << relativeName()
300  << " at line " << is.lineNumber() << '.' << nl
301  << std::endl;
302 
303  std::exit(1);
304  }
305  }
306  else if (!is.size())
307  {
308  // Similar to SafeFatalIOError
310  {
312  (
313  "", // functionName
314  "", // sourceFileName
315  0, // sourceFileLineNumber
316  relativeName(), // ioFileName == dictionary name
317  is.lineNumber() // ioStartLineNumber
318  )
319  << "Entry '" << keyword
320  << "' had no tokens in stream" << nl << nl
321  << exit(FatalIOError);
322  }
323  else
324  {
325  std::cerr
326  << nl
327  << "--> FOAM FATAL IO ERROR:" << nl
328  << "Entry '" << keyword
329  << "' had no tokens in stream" << nl << nl;
330 
331  std::cerr
332  // ioFileName == dictionary name
333  << "file: " << relativeName()
334  << " at line " << is.lineNumber() << '.' << nl
335  << std::endl;
336 
337  std::exit(1);
338  }
339  }
340 }
341 
342 
343 void Foam::dictionary::raiseBadInput
344 (
345  const ITstream& is,
346  const word& keyword
347 ) const
348 {
349  // Can use FatalIOError instead of SafeFatalIOError
350  // since predicate checks are not used at the earliest stages
352  (
353  "", // functionName
354  "", // sourceFileName
355  0, // sourceFileLineNumber
356  relativeName(), // ioFileName == dictionary name
357  is.lineNumber(), // ioStartLineNumber
358  -1 // ioEndLineNumber
359  )
360  << "Entry '" << keyword << "' with invalid input" << nl
361  << exit(FatalIOError);
362 }
363 
364 
366 (
367  const word& keyword,
368  enum keyType::option matchOpt
369 ) const
370 {
371  const entry* eptr = findEntry(keyword, matchOpt);
372 
373  if (!eptr)
374  {
376  << "Entry '" << keyword << "' not found in dictionary "
377  << relativeName() << nl
378  << exit(FatalIOError);
379  }
380 
381  return *eptr;
382 }
383 
384 
386 (
387  const word& keyword,
388  enum keyType::option matchOpt
389 ) const
390 {
391  return lookupEntry(keyword, matchOpt).stream();
392 }
393 
394 
396 (
397  const word& keyword,
398  bool mergeEntry
399 )
400 {
401  if (keyword.size() < 2)
402  {
403  return false;
404  }
405 
406  // Drop leading '$' to get the var-name, already validated as word.
407  const word varName(keyword.substr(1), false);
408 
409  // Lookup the variable name in the given dictionary
410  const const_searcher finder(csearch(varName, keyType::REGEX_RECURSIVE));
411 
412  // If defined insert its entries into this dictionary
413  if (finder.good())
414  {
415  for (const entry& e : finder.dict())
416  {
417  add(e, mergeEntry);
418  }
419 
420  return true;
421  }
422 
423  return false;
424 }
425 
426 
428 (
429  const word& keyword,
430  bool mergeEntry
431 )
432 {
433  if (keyword.size() < 2)
434  {
435  return false;
436  }
437 
438  // Drop leading '$' to get the var-name, already validated as word.
439  const word varName(keyword.substr(1), false);
440 
441  // Lookup the variable name in the given dictionary
442  const auto finder(csearchScoped(varName, keyType::REGEX_RECURSIVE));
443 
444  // If defined insert its entries into this dictionary
445  if (finder.good())
446  {
447  for (const entry& e : finder.dict())
448  {
449  add(e, mergeEntry);
450  }
451 
452  return true;
453  }
454 
455  return false;
456 }
457 
458 
460 (
461  const word& keyword,
462  enum keyType::option matchOpt
463 ) const
464 {
465  const const_searcher finder(csearch(keyword, matchOpt));
466 
467  if (!finder.good())
468  {
470  << "Entry '" << keyword << "' not found in dictionary "
471  << relativeName() << nl
472  << exit(FatalIOError);
473  }
474 
475  return finder.dict();
476 }
477 
478 
480 (
481  const word& keyword,
482  enum keyType::option matchOpt
483 )
484 {
485  searcher finder(search(keyword, matchOpt));
486 
487  if (!finder.good())
488  {
490  << "Entry '" << keyword << "' not found in dictionary "
491  << relativeName() << nl
492  << exit(FatalIOError);
493  }
494 
495  return finder.dict();
496 }
497 
498 
500 (
501  const word& keyword,
502  enum keyType::option matchOpt
503 )
504 {
505  searcher finder(search(keyword, matchOpt));
506 
507  dictionary* dictPtr = finder.dictPtr();
508 
509  if (dictPtr)
510  {
511  // Found and a sub-dictionary
512  return *dictPtr;
513  }
514 
515  if (finder.good())
516  {
518  << "Entry '" << keyword
519  << "' is not a sub-dictionary in dictionary "
520  << relativeName() << nl
521  << exit(FatalIOError);
522  }
523 
524  dictPtr = this->set(keyword, dictionary())->dictPtr();
525 
526  if (!dictPtr)
527  {
529  << "Failed to insert sub-dictionary '" << keyword
530  << "' in dictionary "
531  << relativeName() << nl
532  << exit(FatalIOError);
533  }
534 
535  return *dictPtr;
536 }
537 
538 
540 (
541  const word& keyword,
542  enum keyType::option matchOpt,
543  const bool mandatory
544 ) const
545 {
546  const const_searcher finder(csearch(keyword, matchOpt));
547 
548  const dictionary* dictPtr = finder.dictPtr();
549 
550  if (dictPtr)
551  {
552  // Found and a sub-dictionary
553  return *dictPtr;
554  }
555 
556  if (mandatory)
557  {
559  << "Entry '" << keyword
560  << "' is not a sub-dictionary in dictionary "
561  << relativeName() << nl
562  << exit(FatalIOError);
563  }
564 
565  if (finder.good())
566  {
567  IOWarningInFunction(*this)
568  << "Entry '" << keyword
569  << "' found but not a sub-dictionary in dictionary "
570  << relativeName() << endl;
571  }
573  // The move constructor properly qualifies the dictionary name
574  return dictionary(*this, dictionary(fileName(keyword)));
575 }
576 
577 
579 (
580  const word& keyword,
581  enum keyType::option matchOpt
582 ) const
583 {
584  const const_searcher finder(csearch(keyword, matchOpt));
585 
586  const dictionary* dictPtr = finder.dictPtr();
587 
588  if (dictPtr)
589  {
590  // Found and a sub-dictionary
591  return *dictPtr;
592  }
593 
594  if (finder.good())
595  {
596  IOWarningInFunction(*this)
597  << "Entry '" << keyword
598  << "' found but not a sub-dictionary in dictionary "
599  << relativeName() << endl;
600  }
601 
602  return *this;
603 }
604 
605 
607 {
608  wordList list(size());
609 
610  label n = 0;
611  for (const entry& e : *this)
612  {
613  list[n++] = e.keyword();
614  }
615 
616  return list;
617 }
618 
621 {
622  return hashedEntries_.sortedToc();
623 }
624 
625 
627 {
628  List<keyType> list(size());
629 
630  label n = 0;
631  for (const entry& e : *this)
632  {
633  if (e.keyword().isPattern() ? patterns : !patterns)
634  {
635  list[n++] = e.keyword();
636  }
637  }
638  list.resize(n);
639 
640  return list;
641 }
642 
643 
644 Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
645 {
646  if (!entryPtr)
647  {
648  return nullptr;
649  }
650 
651  auto iter = hashedEntries_.find(entryPtr->keyword());
652 
653  if (mergeEntry && iter.good())
654  {
655  // Merge dictionary with dictionary
656  if (iter()->isDict() && entryPtr->isDict())
657  {
658  iter()->dict().merge(entryPtr->dict());
659 
660  delete entryPtr;
661  return iter(); // pointer to existing dictionary
662  }
663 
664 
665  // Replace existing dictionary with entry or vice versa
666  parent_type::replace(iter(), entryPtr);
667  delete iter();
668  hashedEntries_.erase(iter);
669 
670  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
671  {
672  entryPtr->name() =
673  fileName::concat(name(), entryPtr->keyword(), '.');
674 
675  if (entryPtr->keyword().isPattern())
676  {
677  patterns_.prepend(entryPtr);
678  regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword()));
679  }
680 
681  return entryPtr; // now an entry in the dictionary
682  }
683 
684 
685  IOWarningInFunction(*this)
686  << "Problem replacing entry "<< entryPtr->keyword()
687  << " in dictionary " << relativeName() << endl;
688 
689  parent_type::remove(entryPtr);
690 
691  delete entryPtr;
692  return nullptr;
693  }
694 
695 
696  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
697  {
698  entryPtr->name() =
699  fileName::concat(name(), entryPtr->keyword(), '.');
700 
701  parent_type::append(entryPtr);
702 
703  if (entryPtr->keyword().isPattern())
704  {
705  patterns_.prepend(entryPtr);
706  regexps_.prepend(autoPtr<regExp>::New(entryPtr->keyword()));
707  }
708 
709  return entryPtr; // now an entry in the dictionary
710  }
711 
712 
713  IOWarningInFunction(*this)
714  << "Attempt to add entry " << entryPtr->keyword()
715  << " which already exists in dictionary "
716  << relativeName() << endl;
717 
718  delete entryPtr;
719  return nullptr;
720 }
721 
722 
723 Foam::entry* Foam::dictionary::add(const entry& e, bool mergeEntry)
724 {
725  return add(e.clone(*this).ptr(), mergeEntry);
726 }
727 
728 
730 (
731  const keyType& k,
732  const word& v,
733  bool overwrite
734 )
735 {
736  return add(new primitiveEntry(k, token(v)), overwrite);
737 }
738 
739 
741 (
742  const keyType& k,
743  const Foam::string& v,
744  bool overwrite
745 )
746 {
747  return add(new primitiveEntry(k, token(v)), overwrite);
748 }
749 
750 
752 (
753  const keyType& k,
754  const label v,
755  bool overwrite
756 )
757 {
758  return add(new primitiveEntry(k, token(v)), overwrite);
759 }
760 
761 
763 (
764  const keyType& k,
765  const scalar v,
766  bool overwrite
767 )
768 {
769  return add(new primitiveEntry(k, token(v)), overwrite);
770 }
771 
772 
774 (
775  const keyType& k,
776  const dictionary& v,
777  bool mergeEntry
778 )
779 {
780  return add(new dictionaryEntry(k, *this, v), mergeEntry);
781 }
782 
783 
785 {
786  if (!entryPtr)
787  {
788  return nullptr;
789  }
790 
791  // Find non-recursive with patterns
792  searcher finder(search(entryPtr->keyword(), keyType::REGEX));
793 
794  dictionary* dictPtr = finder.dictPtr();
795 
796  // Clear dictionary so merge acts like overwrite
797  if (dictPtr)
798  {
799  dictPtr->clear();
800  }
801 
802  return add(entryPtr, true);
803 }
804 
807 {
808  return set(e.clone(*this).ptr());
809 }
810 
813 {
814  return set(new dictionaryEntry(k, *this, v));
815 }
816 
817 
819 {
820  if (this == &dict)
821  {
823  << "Attempted merge to self, for dictionary "
824  << relativeName() << nl
825  << abort(FatalIOError);
826  }
827 
828  bool changed = false;
829 
830  for (const entry& e : dict)
831  {
832  auto fnd = hashedEntries_.find(e.keyword());
833 
834  if (fnd.good())
835  {
836  // Recursively merge sub-dictionaries
837  // TODO: merge without copying
838  if (fnd()->isDict() && e.isDict())
839  {
840  if (fnd()->dict().merge(e.dict()))
841  {
842  changed = true;
843  }
844  }
845  else
846  {
847  add(e.clone(*this).ptr(), true);
848  changed = true;
849  }
850  }
851  else
852  {
853  // Not found - just add
854  add(e.clone(*this).ptr());
855  changed = true;
856  }
857  }
858 
859  return changed;
860 }
861 
862 
864 {
866  hashedEntries_.clear();
867  patterns_.clear();
868  regexps_.clear();
869 }
870 
871 
873 {
874  // Changing parents probably doesn't make much sense,
875  // but what about the names?
876  name() = dict.name();
877 
878  parent_type::transfer(dict);
879  hashedEntries_.transfer(dict.hashedEntries_);
880  patterns_.transfer(dict.patterns_);
881  regexps_.transfer(dict.regexps_);
882 }
883 
884 
885 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
886 
888 {
889  if (this == &rhs)
890  {
891  return; // Self-assignment is a no-op
892  }
893 
894  name() = rhs.name();
895  clear();
896 
897  // Create clones of the entries in the given dictionary
898  // resetting the parentDict to this dictionary
899 
900  for (const entry& e : rhs)
901  {
902  add(e.clone(*this).ptr());
903  }
904 }
905 
906 
907 void Foam::dictionary::operator+=(const dictionary& rhs)
908 {
909  if (this == &rhs)
910  {
912  << "Attempted addition to self, for dictionary "
913  << relativeName() << nl
914  << abort(FatalIOError);
915  }
916 
917  for (const entry& e : rhs)
918  {
919  add(e.clone(*this).ptr());
920  }
921 }
922 
923 
924 void Foam::dictionary::operator|=(const dictionary& rhs)
925 {
926  if (this == &rhs)
927  {
929  << "Attempted |= merging to self, for dictionary "
930  << relativeName() << nl
931  << abort(FatalIOError);
932  }
933 
934  for (const entry& e : rhs)
935  {
936  if (!found(e.keyword()))
937  {
938  add(e.clone(*this).ptr());
939  }
940  }
941 }
942 
943 
944 void Foam::dictionary::operator<<=(const dictionary& rhs)
945 {
946  if (this == &rhs)
947  {
949  << "Attempted addition to self, for dictionary "
950  << relativeName() << nl
951  << abort(FatalIOError);
952  }
953 
954  for (const entry& e : rhs)
955  {
956  set(e.clone(*this).ptr());
957  }
958 }
959 
960 
961 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
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 Foam::dictionary Foam::operator|
976 (
977  const dictionary& dict1,
978  const dictionary& dict2
979 )
980 {
981  dictionary result(dict1);
982  result |= dict2;
983  return result;
984 }
985 
986 
987 // ************************************************************************* //
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:379
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:50
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
void operator<<=(const dictionary &rhs)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:937
A class for handling file names.
Definition: fileName.H:71
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:865
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
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:917
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
A token holds an item read from Istream.
Definition: token.H:64
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by &#39;$&#39;)
Definition: dictionary.C:421
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
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:637
const entry * findEntry(const dictionary &dict, const label val)
Linear search for labelled entry, nullptr if not found.
label k
Boltzmann constant.
const entry & lookupEntry(const word &keyword, enum keyType::option matchOpt) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:359
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:453
label nRemainingTokens() const noexcept
Number of tokens remaining.
Definition: ITstream.H:314
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:165
wordList toc() const
Return the table of contents.
Definition: dictionary.C:599
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition: dictionary.C:493
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:58
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:572
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:811
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:72
static refPtr< OSstream > reportingOutput
Output location when reporting default values.
Definition: dictionary.H:470
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 INVALID.
Definition: exprTraits.C:52
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:880
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:465
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:389
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:533
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:597
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:460
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:619
label lineNumber() const noexcept
Const access to the current stream line number.
Definition: IOstream.H:383
static word envExecutable()
Name of the executable from environment variable.
Definition: argList.C:584
List< word > wordList
A List of words.
Definition: fileName.H:58
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
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:640
#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:777
friend class entry
Declare friendship with the entry class for IO.
Definition: dictionary.H:316
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:856
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:900
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:613
An input stream of tokens.
Definition: ITstream.H:48
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 ...