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-2019 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 "argList.H"
37 #include "registerSwitch.H"
38 
39 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
40 
41 namespace Foam
42 {
43  defineTypeNameAndDebug(dictionary, 0);
44 }
45 
47 
49 (
50  Foam::debug::infoSwitch("writeOptionalEntries", 0)
51 );
52 
53 
55 (
56  "writeOptionalEntries",
57  int,
59 );
60 
61 
62 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 
64 Foam::fileName Foam::dictionary::relativeName(const bool caseTag) const
65 {
66  const fileName caseDir(argList::envGlobalPath());
67 
68  if (!caseDir.empty() && name().isAbsolute())
69  {
70  return name().relative(caseDir, caseTag);
71  }
72  else
73  {
74  return name();
75  }
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 
82 :
83  name_(),
84  parent_(dictionary::null)
85 {}
86 
87 
89 :
90  name_(name),
91  parent_(dictionary::null)
92 {}
93 
94 
96 (
97  const dictionary& parentDict,
98  const dictionary& dict
99 )
100 :
101  parent_type(dict, *this),
102  name_(dict.name()),
103  parent_(parentDict)
104 {
105  for (entry& e : *this)
106  {
107  hashedEntries_.insert(e.keyword(), &e);
108 
109  if (e.keyword().isPattern())
110  {
111  patterns_.insert(&e);
112  regexps_.insert(autoPtr<regExp>::New(e.keyword()));
113  }
114  }
115 }
116 
117 
119 (
120  const dictionary& dict
121 )
122 :
123  parent_type(dict, *this),
124  name_(dict.name()),
125  parent_(dictionary::null)
126 {
127  for (entry& e : *this)
128  {
129  hashedEntries_.insert(e.keyword(), &e);
130 
131  if (e.keyword().isPattern())
132  {
133  patterns_.insert(&e);
134  regexps_.insert(autoPtr<regExp>::New(e.keyword()));
135  }
136  }
137 }
138 
139 
141 :
142  name_(),
143  parent_(dictionary::null)
144 {
145  if (dict)
146  {
147  operator=(*dict);
148  }
149 }
150 
151 
153 (
154  const dictionary& parentDict,
155  dictionary&& dict
156 )
157 :
158  name_(),
159  parent_(parentDict)
160 {
161  transfer(dict);
162  name() = fileName::concat(parentDict.name(), name(), '.');
163 }
164 
165 
167 (
168  dictionary&& dict
169 )
170 :
171  name_(),
172  parent_(dictionary::null)
173 {
174  transfer(dict);
175 }
176 
177 
179 {
180  return autoPtr<dictionary>::New(*this);
181 }
182 
183 
184 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
185 
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
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 
206 {
207  if (size())
208  {
209  return first()->startLineNumber();
210  }
211 
212  return -1;
213 }
214 
215 
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  }
251 
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  this->name(), // ioFileName
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  << "file: " << this->name()
299  << " at line " << is.lineNumber() << '.' << nl
300  << std::endl;
301 
302  std::exit(1);
303  }
304  }
305  else if (!is.size())
306  {
307  // Similar to SafeFatalIOError
309  {
311  (
312  "", // functionName
313  "", // sourceFileName
314  0, // sourceFileLineNumber
315  this->name(), // ioFileName
316  is.lineNumber() // ioStartLineNumber
317  )
318  << "Entry '" << keyword
319  << "' had no tokens in stream" << nl << nl
320  << exit(FatalIOError);
321  }
322  else
323  {
324  std::cerr
325  << nl
326  << "--> FOAM FATAL IO ERROR:" << nl
327  << "Entry '" << keyword
328  << "' had no tokens in stream" << nl << nl;
329 
330  std::cerr
331  << "file: " << this->name()
332  << " at line " << is.lineNumber() << '.' << nl
333  << std::endl;
334 
335  std::exit(1);
336  }
337  }
338 }
339 
340 
341 void Foam::dictionary::raiseBadInput(const word& keyword) const
342 {
343  // Can use FatalIOError instead of SafeFatalIOError
344  // since predicate checks are not used at the earliest stages
346  (
347  "", // functionName
348  "", // sourceFileName
349  0, // sourceFileLineNumber
350  *this // ios
351  )
352  << "Entry '" << keyword << "' with invalid input in dictionary "
353  << name() << nl << nl
354  << exit(FatalIOError);
355 }
356 
357 
359 (
360  const word& keyword,
361  enum keyType::option matchOpt
362 ) const
363 {
364  return csearch(keyword, matchOpt).good();
365 }
366 
367 
369 (
370  const word& keyword,
371  enum keyType::option matchOpt
372 )
373 {
374  return search(keyword, matchOpt).ptr();
375 }
376 
377 
379 (
380  const word& keyword,
381  enum keyType::option matchOpt
382 ) const
383 {
384  return csearch(keyword, matchOpt).ptr();
385 }
386 
387 
389 (
390  const word& keyword,
391  enum keyType::option matchOpt
392 ) const
393 {
394  return csearchScoped(keyword, matchOpt).ptr();
395 }
396 
397 
399 (
400  const word& keyword,
401  enum keyType::option matchOpt
402 ) const
403 {
404  const const_searcher finder(csearch(keyword, matchOpt));
405 
406  if (!finder.good())
407  {
409  << "Entry '" << keyword << "' not found in dictionary "
410  << name() << nl
411  << exit(FatalIOError);
412  }
413 
414  return finder.ref();
415 }
416 
417 
419 (
420  const word& keyword,
421  enum keyType::option matchOpt
422 ) const
423 {
424  return lookupEntry(keyword, matchOpt).stream();
425 }
426 
427 
429 (
430  const word& keyword,
431  bool mergeEntry
432 )
433 {
434  if (keyword.size() < 2)
435  {
436  return false;
437  }
438 
439  // Drop leading '$' to get the var-name, already validated as word.
440  const word varName(keyword.substr(1), false);
441 
442  // Lookup the variable name in the given dictionary
443  const const_searcher finder(csearch(varName, keyType::REGEX_RECURSIVE));
444 
445  // If defined insert its entries into this dictionary
446  if (finder.good())
447  {
448  for (const entry& e : finder.dict())
449  {
450  add(e, mergeEntry);
451  }
452 
453  return true;
454  }
455 
456  return false;
457 }
458 
459 
461 (
462  const word& keyword,
463  bool mergeEntry
464 )
465 {
466  if (keyword.size() < 2)
467  {
468  return false;
469  }
470 
471  // Drop leading '$' to get the var-name, already validated as word.
472  const word varName(keyword.substr(1), false);
473 
474  // Lookup the variable name in the given dictionary
475  const auto finder(csearchScoped(varName, keyType::REGEX_RECURSIVE));
476 
477  // If defined insert its entries into this dictionary
478  if (finder.good())
479  {
480  for (const entry& e : finder.dict())
481  {
482  add(e, mergeEntry);
483  }
484 
485  return true;
486  }
487 
488  return false;
489 }
490 
491 
493 (
494  const word& keyword,
495  enum keyType::option matchOpt
496 ) const
497 {
498  return csearch(keyword, matchOpt).isDict();
499 }
500 
501 
503 (
504  const word& keyword,
505  enum keyType::option matchOpt
506 )
507 {
508  return search(keyword, matchOpt).dictPtr();
509 }
510 
511 
513 (
514  const word& keyword,
515  enum keyType::option matchOpt
516 ) const
517 {
518  return csearch(keyword, matchOpt).dictPtr();
519 }
520 
521 
523 (
524  const word& keyword,
525  enum keyType::option matchOpt
526 ) const
527 {
528  const const_searcher finder(csearch(keyword, matchOpt));
529 
530  if (!finder.good())
531  {
533  << "Entry '" << keyword << "' not found in dictionary "
534  << name() << nl
535  << exit(FatalIOError);
536  }
537 
538  return finder.dict();
539 }
540 
541 
543 (
544  const word& keyword,
545  enum keyType::option matchOpt
546 )
547 {
548  searcher finder(search(keyword, matchOpt));
549 
550  if (!finder.good())
551  {
553  << "Entry '" << keyword << "' not found in dictionary "
554  << name() << nl
555  << exit(FatalIOError);
556  }
557 
558  return finder.dict();
559 }
560 
561 
563 (
564  const word& keyword,
565  enum keyType::option matchOpt
566 )
567 {
568  searcher finder(search(keyword, matchOpt));
569 
570  dictionary* ptr = finder.dictPtr();
571 
572  if (ptr)
573  {
574  // Found and a sub-dictionary
575  return *ptr;
576  }
577 
578  if (finder.good())
579  {
581  << "Entry '" << keyword
582  << "' is not a sub-dictionary in dictionary "
583  << name() << nl
584  << exit(FatalIOError);
585  }
586 
587  ptr = this->set(keyword, dictionary())->dictPtr();
588 
589  if (!ptr)
590  {
592  << "Failed to insert sub-dictionary '" << keyword
593  << "' in dictionary "
594  << name() << nl
595  << exit(FatalIOError);
596  }
597 
598  return *ptr;
599 }
600 
601 
603 (
604  const word& keyword,
605  enum keyType::option matchOpt,
606  const bool mandatory
607 ) const
608 {
609  const const_searcher finder(csearch(keyword, matchOpt));
610 
611  if (finder.isDict())
612  {
613  // Found and a sub-dictionary
614  return finder.dict();
615  }
616 
617  if (mandatory)
618  {
620  << "Entry '" << keyword
621  << "' is not a sub-dictionary in dictionary "
622  << name() << nl
623  << exit(FatalIOError);
624  }
625 
626  if (finder.good())
627  {
628  IOWarningInFunction(*this)
629  << "Entry '" << keyword
630  << "' found but not a sub-dictionary in dictionary "
631  << name() << endl;
632  }
633 
634  // The move constructor properly qualifies the dictionary name
635  return dictionary(*this, dictionary(fileName(keyword)));
636 }
637 
638 
640 (
641  const word& keyword,
642  enum keyType::option matchOpt
643 ) const
644 {
645  const const_searcher finder(csearch(keyword, matchOpt));
646 
647  if (finder.isDict())
648  {
649  // Found and a sub-dictionary
650  return finder.dict();
651  }
652 
653  if (finder.good())
654  {
655  IOWarningInFunction(*this)
656  << "Entry '" << keyword
657  << "' found but not a sub-dictionary in dictionary "
658  << name() << endl;
659  }
660 
661  return *this;
662 }
663 
664 
666 {
667  wordList list(size());
668 
669  label n = 0;
670  for (const entry& e : *this)
671  {
672  list[n++] = e.keyword();
673  }
674 
675  return list;
676 }
677 
678 
680 {
681  return hashedEntries_.sortedToc();
682 }
683 
684 
686 {
687  List<keyType> list(size());
688 
689  label n = 0;
690  for (const entry& e : *this)
691  {
692  if (e.keyword().isPattern() ? patterns : !patterns)
693  {
694  list[n++] = e.keyword();
695  }
696  }
697  list.resize(n);
698 
699  return list;
700 }
701 
702 
703 Foam::entry* Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
704 {
705  if (!entryPtr)
706  {
707  return nullptr;
708  }
709 
710  auto iter = hashedEntries_.find(entryPtr->keyword());
711 
712  if (mergeEntry && iter.good())
713  {
714  // Merge dictionary with dictionary
715  if (iter()->isDict() && entryPtr->isDict())
716  {
717  iter()->dict().merge(entryPtr->dict());
718 
719  delete entryPtr;
720  return iter(); // pointer to existing dictionary
721  }
722 
723 
724  // Replace existing dictionary with entry or vice versa
725  parent_type::replace(iter(), entryPtr);
726  delete iter();
727  hashedEntries_.erase(iter);
728 
729  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
730  {
731  entryPtr->name() =
732  fileName::concat(name(), entryPtr->keyword(), '.');
733 
734  if (entryPtr->keyword().isPattern())
735  {
736  patterns_.insert(entryPtr);
737  regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword()));
738  }
739 
740  return entryPtr; // now an entry in the dictionary
741  }
742 
743 
744  IOWarningInFunction(*this)
745  << "Problem replacing entry "<< entryPtr->keyword()
746  << " in dictionary " << name() << endl;
747 
748  parent_type::remove(entryPtr);
749 
750  delete entryPtr;
751  return nullptr;
752  }
753 
754 
755  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
756  {
757  entryPtr->name() =
758  fileName::concat(name(), entryPtr->keyword(), '.');
759 
760  parent_type::append(entryPtr);
761 
762  if (entryPtr->keyword().isPattern())
763  {
764  patterns_.insert(entryPtr);
765  regexps_.insert(autoPtr<regExp>::New(entryPtr->keyword()));
766  }
767 
768  return entryPtr; // now an entry in the dictionary
769  }
770 
771 
772  IOWarningInFunction(*this)
773  << "Attempt to add entry " << entryPtr->keyword()
774  << " which already exists in dictionary " << name() << endl;
775 
776  delete entryPtr;
777  return nullptr;
778 }
779 
780 
781 Foam::entry* Foam::dictionary::add(const entry& e, bool mergeEntry)
782 {
783  return add(e.clone(*this).ptr(), mergeEntry);
784 }
785 
786 
788 (
789  const keyType& k,
790  const word& v,
791  bool overwrite
792 )
793 {
794  return add(new primitiveEntry(k, token(v)), overwrite);
795 }
796 
797 
799 (
800  const keyType& k,
801  const Foam::string& v,
802  bool overwrite
803 )
804 {
805  return add(new primitiveEntry(k, token(v)), overwrite);
806 }
807 
808 
810 (
811  const keyType& k,
812  const label v,
813  bool overwrite
814 )
815 {
816  return add(new primitiveEntry(k, token(v)), overwrite);
817 }
818 
819 
821 (
822  const keyType& k,
823  const scalar v,
824  bool overwrite
825 )
826 {
827  return add(new primitiveEntry(k, token(v)), overwrite);
828 }
829 
830 
832 (
833  const keyType& k,
834  const dictionary& v,
835  bool mergeEntry
836 )
837 {
838  return add(new dictionaryEntry(k, *this, v), mergeEntry);
839 }
840 
841 
843 {
844  if (!entryPtr)
845  {
846  return nullptr;
847  }
848 
849  // Find non-recursive with patterns
850  searcher finder(search(entryPtr->keyword(), keyType::REGEX));
851 
852  // Clear dictionary so merge acts like overwrite
853  if (finder.isDict())
854  {
855  finder.dict().clear();
856  }
857 
858  return add(entryPtr, true);
859 }
860 
861 
863 {
864  return set(e.clone(*this).ptr());
865 }
866 
867 
869 {
870  return set(new dictionaryEntry(k, *this, v));
871 }
872 
873 
875 {
876  if (this == &dict)
877  {
879  << "Attempted merge to self, for dictionary "
880  << name() << nl
881  << abort(FatalIOError);
882  }
883 
884  bool changed = false;
885 
886  for (const entry& e : dict)
887  {
888  auto fnd = hashedEntries_.find(e.keyword());
889 
890  if (fnd.good())
891  {
892  // Recursively merge sub-dictionaries
893  // TODO: merge without copying
894  if (fnd()->isDict() && e.isDict())
895  {
896  if (fnd()->dict().merge(e.dict()))
897  {
898  changed = true;
899  }
900  }
901  else
902  {
903  add(e.clone(*this).ptr(), true);
904  changed = true;
905  }
906  }
907  else
908  {
909  // Not found - just add
910  add(e.clone(*this).ptr());
911  changed = true;
912  }
913  }
914 
915  return changed;
916 }
917 
918 
920 {
922  hashedEntries_.clear();
923  patterns_.clear();
924  regexps_.clear();
925 }
926 
927 
929 {
930  // Changing parents probably doesn't make much sense,
931  // but what about the names?
932  name() = dict.name();
933 
934  parent_type::transfer(dict);
935  hashedEntries_.transfer(dict.hashedEntries_);
936  patterns_.transfer(dict.patterns_);
937  regexps_.transfer(dict.regexps_);
938 }
939 
940 
941 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
942 
944 {
945  if (this == &rhs)
946  {
947  return; // Self-assignment is a no-op
948  }
949 
950  name() = rhs.name();
951  clear();
952 
953  // Create clones of the entries in the given dictionary
954  // resetting the parentDict to this dictionary
955 
956  for (const entry& e : rhs)
957  {
958  add(e.clone(*this).ptr());
959  }
960 }
961 
962 
964 {
965  if (this == &rhs)
966  {
968  << "Attempted addition to self, for dictionary "
969  << name() << nl
970  << abort(FatalIOError);
971  }
972 
973  for (const entry& e : rhs)
974  {
975  add(e.clone(*this).ptr());
976  }
977 }
978 
979 
981 {
982  if (this == &rhs)
983  {
985  << "Attempted |= merging to self, for dictionary "
986  << name() << nl
987  << abort(FatalIOError);
988  }
989 
990  for (const entry& e : rhs)
991  {
992  if (!found(e.keyword()))
993  {
994  add(e.clone(*this).ptr());
995  }
996  }
997 }
998 
999 
1001 {
1002  if (this == &rhs)
1003  {
1004  FatalIOErrorInFunction(*this)
1005  << "Attempted addition to self, for dictionary "
1006  << name() << nl
1007  << abort(FatalIOError);
1008  }
1009 
1010  for (const entry& e : rhs)
1011  {
1012  set(e.clone(*this).ptr());
1013  }
1014 }
1015 
1016 
1017 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
1018 
1019 Foam::dictionary Foam::operator+
1021  const dictionary& dict1,
1022  const dictionary& dict2
1023 )
1024 {
1025  dictionary sum(dict1);
1026  sum += dict2;
1027  return sum;
1028 }
1029 
1030 
1031 Foam::dictionary Foam::operator|
1033  const dictionary& dict1,
1034  const dictionary& dict2
1035 )
1036 {
1037  dictionary sum(dict1);
1038  sum |= dict2;
1039  return sum;
1040 }
1041 
1042 
1043 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::dictionary::findDict
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:503
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::dictionaryEntry
A keyword and a list of tokens is a 'dictionaryEntry'.
Definition: dictionaryEntry.H:65
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::primitiveEntry
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Definition: primitiveEntry.H:62
primitiveEntry.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dictionary::Searcher::dictPtr
dict_pointer dictPtr() const
Pointer to the found entry as a dictionary or nullptr otherwise.
Definition: dictionary.H:234
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::entry::keyword
const keyType & keyword() const
Return keyword.
Definition: entry.H:187
Foam::argList::envGlobalPath
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition: argList.C:513
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:359
Foam::keyType::isPattern
bool isPattern() const
The keyType is treated as a pattern, not as literal string.
Definition: keyTypeI.H:128
Foam::dictionary::checkITstream
void checkITstream(const ITstream &is, const word &keyword) const
Definition: dictionary.C:258
Foam::dictionary::dictionary
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:81
Foam::ITstream::nRemainingTokens
label nRemainingTokens() const
Return the number of remaining tokens.
Definition: ITstream.H:233
Foam::dictionary::operator|=
void operator|=(const dictionary &rhs)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:980
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::dictionary::set
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:842
Foam::dictionary::lookupEntry
const entry & lookupEntry(const word &keyword, enum keyType::option matchOpt) const
Search for an entry (const access) with the given keyword.
Definition: dictionary.C:399
Foam::fileName::relative
fileName relative(const fileName &parent, const bool caseTag=false) const
Definition: fileName.C:431
Foam::dictionary::operator+=
void operator+=(const dictionary &rhs)
Include entries from the given dictionary.
Definition: dictionary.C:963
Foam::dictionary::subDictOrAdd
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition: dictionary.C:563
Foam::dictionary::substituteKeyword
bool substituteKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given keyword (which is prefixed by '$')
Definition: dictionary.C:429
Foam::dictionary::transfer
void transfer(dictionary &dict)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:928
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:385
Foam::debug::infoSwitch
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:231
Foam::dictionary::keys
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:685
Foam::dictionary::Searcher
Generic const/non-const dictionary entry searcher.
Definition: dictionary.H:138
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::dictionary::operator<<=
void operator<<=(const dictionary &rhs)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1000
Foam::dictionary::merge
bool merge(const dictionary &dict)
Merge entries from the given dictionary.
Definition: dictionary.C:874
Foam::dictionary::name
const fileName & name() const
The dictionary name.
Definition: dictionary.H:446
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
error.H
Foam::entry::isDict
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:222
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
argList.H
Foam::dictionary::~dictionary
virtual ~dictionary()
Destructor.
Definition: dictionary.C:186
Foam::dictionary::startLineNumber
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:205
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:523
Foam::dictionary::endLineNumber
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:216
Foam::dictionary::Searcher::good
bool good() const
True if entry was found.
Definition: dictionary.H:198
Foam::OSstream
Generic output stream.
Definition: OSstream.H:54
Foam::dictionary::Searcher::dict
dict_reference dict() const
Reference the found entry as a dictionary.
Definition: dictionary.H:241
Foam::dictionary::topDict
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:192
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::OSHA1stream
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:183
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:419
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::ILList
Template class for intrusive linked lists.
Definition: ILList.H:52
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
Foam::ITstream::parse
static tokenList parse(const UList< char > &input, streamFormat format=ASCII)
Definition: ITstream.C:56
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
Foam::dictionary::writeOptionalEntries
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:382
dictionaryEntry.H
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:60
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:603
Foam::entry::name
virtual const fileName & name() const =0
Return the dictionary name.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::dictionary::isDict
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check if entry is found and is a sub-dictionary.
Definition: dictionary.C:493
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:92
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::dictionary::findScoped
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: dictionary.C:389
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::JobInfo::constructed
static bool constructed
Global value for constructed job info.
Definition: JobInfo.H:80
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:189
Foam::dictionary::operator=
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:943
Foam::dictionary::findEntry
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
Definition: dictionary.C:369
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::dictionary::clone
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:178
Foam::keyType::REGEX
Regular expression.
Definition: keyType.H:74
dictionary.H
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:576
Foam::dictionary::Searcher::isDict
bool isDict() const
True if found entry is a dictionary.
Definition: dictionary.H:228
Foam::fileName::concat
static fileName concat(const std::string &s1, const std::string &s2, const char delim='/')
Join two strings with a path separator ('/' by default).
Definition: fileName.C:126
Foam::dictionary::substituteScopedKeyword
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by '$')
Definition: dictionary.C:461
Foam::dictionary::optionalSubDict
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:640
OSHA1stream.H
JobInfo.H
Foam::IOstream::lineNumber
label lineNumber() const
Const access to the current stream line number.
Definition: IOstream.H:301
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:703
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
registerSwitch.H
Foam::dictionary::tokens
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:241
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:665
Foam::dictionary::digest
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:227
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:306
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dictionary::clear
void clear()
Clear the dictionary.
Definition: dictionary.C:919
Foam::dictionary::sortedToc
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:679
Foam::dictionary::Searcher::ref
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:222
Foam::fileName::isAbsolute
static bool isAbsolute(const std::string &str)
Return true if string starts with a '/'.
Definition: fileNameI.H:136
registerInfoSwitch
registerInfoSwitch("writeOptionalEntries", int, Foam::dictionary::writeOptionalEntries)
Foam::keyType::option
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:70
Foam::Detail::OSHA1streamAllocator::digest
SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:161
Foam::keyType::REGEX_RECURSIVE
Definition: keyType.H:79