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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "dictionary.H"
27 #include "primitiveEntry.H"
28 #include "dictionaryEntry.H"
29 #include "regExp.H"
30 #include "OSHA1stream.H"
31 #include "DynamicList.H"
32 
33 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(dictionary, 0);
38  const dictionary dictionary::null;
39 
40  bool dictionary::writeOptionalEntries
41  (
42  debug::infoSwitch("writeOptionalEntries", 0)
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 bool Foam::dictionary::findInPatterns
50 (
51  const bool patternMatch,
52  const word& Keyword,
54  DLList<autoPtr<regExp> >::const_iterator& reLink
55 ) const
56 {
57  if (patternEntries_.size())
58  {
59  while (wcLink != patternEntries_.end())
60  {
61  if
62  (
63  patternMatch
64  ? reLink()->match(Keyword)
65  : wcLink()->keyword() == Keyword
66  )
67  {
68  return true;
69  }
70 
71  ++reLink;
72  ++wcLink;
73  }
74  }
75 
76  return false;
77 }
78 
79 
80 bool Foam::dictionary::findInPatterns
81 (
82  const bool patternMatch,
83  const word& Keyword,
85  DLList<autoPtr<regExp> >::iterator& reLink
86 )
87 {
88  if (patternEntries_.size())
89  {
90  while (wcLink != patternEntries_.end())
91  {
92  if
93  (
94  patternMatch
95  ? reLink()->match(Keyword)
96  : wcLink()->keyword() == Keyword
97  )
98  {
99  return true;
100  }
101 
102  ++reLink;
103  ++wcLink;
104  }
105  }
106 
107  return false;
108 }
109 
110 
111 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
112 
114 :
115  parent_(dictionary::null)
116 {}
117 
118 
120 :
121  dictionaryName(name),
122  parent_(dictionary::null)
123 {}
124 
125 
127 (
128  const dictionary& parentDict,
129  const dictionary& dict
130 )
131 :
132  dictionaryName(dict.name()),
133  IDLList<entry>(dict, *this),
134  parent_(parentDict)
135 {
136  forAllIter(IDLList<entry>, *this, iter)
137  {
138  hashedEntries_.insert(iter().keyword(), &iter());
139 
140  if (iter().keyword().isPattern())
141  {
142  patternEntries_.insert(&iter());
143  patternRegexps_.insert
144  (
145  autoPtr<regExp>(new regExp(iter().keyword()))
146  );
147  }
148  }
149 }
150 
151 
153 (
154  const dictionary& dict
155 )
156 :
157  dictionaryName(dict.name()),
158  IDLList<entry>(dict, *this),
159  parent_(dictionary::null)
160 {
161  forAllIter(IDLList<entry>, *this, iter)
162  {
163  hashedEntries_.insert(iter().keyword(), &iter());
164 
165  if (iter().keyword().isPattern())
166  {
167  patternEntries_.insert(&iter());
168  patternRegexps_.insert
169  (
170  autoPtr<regExp>(new regExp(iter().keyword()))
171  );
172  }
173  }
174 }
175 
176 
178 (
179  const dictionary* dictPtr
180 )
181 :
182  parent_(dictionary::null)
183 {
184  if (dictPtr)
185  {
186  operator=(*dictPtr);
187  }
188 }
189 
190 
192 (
193  const dictionary& parentDict,
194  const Xfer<dictionary>& dict
195 )
196 :
197  parent_(parentDict)
198 {
199  transfer(dict());
200  name() = parentDict.name() + '.' + name();
201 }
202 
203 
205 (
206  const Xfer<dictionary>& dict
207 )
208 :
209  parent_(dictionary::null)
210 {
211  transfer(dict());
212 }
213 
214 
216 {
217  return autoPtr<dictionary>(new dictionary(*this));
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
222 
224 {
225  // cerr<< "~dictionary() " << name() << " " << long(this) << std::endl;
226 }
227 
228 
229 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
230 
232 {
233  const dictionary& p = parent();
234 
235  if (&p != this && !p.name().empty())
236  {
237  return p.topDict();
238  }
239  else
240  {
241  return p;
242  }
243 }
244 
245 
247 {
248  if (size())
249  {
250  return first()->startLineNumber();
251  }
252  else
253  {
254  return -1;
255  }
256 }
257 
258 
260 {
261  if (size())
262  {
263  return last()->endLineNumber();
264  }
265  else
266  {
267  return -1;
268  }
269 }
270 
271 
273 {
274  OSHA1stream os;
275 
276  // process entries
277  forAllConstIter(IDLList<entry>, *this, iter)
278  {
279  os << *iter;
280  }
281 
282  return os.digest();
283 }
284 
285 
287 {
288  // linearise dictionary into a string
289  OStringStream os;
290  write(os, false);
291  IStringStream is(os.str());
292 
293  // parse string as tokens
295  token t;
296  while (is.read(t))
297  {
298  tokens.append(t);
299  }
300 
301  return tokenList(tokens.xfer());
302 }
303 
304 
306 (
307  const word& keyword,
308  bool recursive,
309  bool patternMatch
310 ) const
311 {
312  if (hashedEntries_.found(keyword))
313  {
314  return true;
315  }
316  else
317  {
318  if (patternMatch && patternEntries_.size())
319  {
321  patternEntries_.begin();
323  patternRegexps_.begin();
324 
325  // Find in patterns using regular expressions only
326  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
327  {
328  return true;
329  }
330  }
331 
332  if (recursive && &parent_ != &dictionary::null)
333  {
334  return parent_.found(keyword, recursive, patternMatch);
335  }
336  else
337  {
338  return false;
339  }
340  }
341 }
342 
343 
345 (
346  const word& keyword,
347  bool recursive,
348  bool patternMatch
349 ) const
350 {
351  HashTable<entry*>::const_iterator iter = hashedEntries_.find(keyword);
352 
353  if (iter == hashedEntries_.end())
354  {
355  if (patternMatch && patternEntries_.size())
356  {
358  patternEntries_.begin();
360  patternRegexps_.begin();
361 
362  // Find in patterns using regular expressions only
363  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
364  {
365  return wcLink();
366  }
367  }
368 
369  if (recursive && &parent_ != &dictionary::null)
370  {
371  return parent_.lookupEntryPtr(keyword, recursive, patternMatch);
372  }
373  else
374  {
375  return NULL;
376  }
377  }
378 
379  return iter();
380 }
381 
382 
384 (
385  const word& keyword,
386  bool recursive,
387  bool patternMatch
388 )
389 {
390  HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);
391 
392  if (iter == hashedEntries_.end())
393  {
394  if (patternMatch && patternEntries_.size())
395  {
396  DLList<entry*>::iterator wcLink =
397  patternEntries_.begin();
399  patternRegexps_.begin();
400 
401  // Find in patterns using regular expressions only
402  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
403  {
404  return wcLink();
405  }
406  }
407 
408  if (recursive && &parent_ != &dictionary::null)
409  {
410  return const_cast<dictionary&>(parent_).lookupEntryPtr
411  (
412  keyword,
413  recursive,
414  patternMatch
415  );
416  }
417  else
418  {
419  return NULL;
420  }
421  }
422 
423  return iter();
424 }
425 
426 
428 (
429  const word& keyword,
430  bool recursive,
431  bool patternMatch
432 ) const
433 {
434  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
435 
436  if (entryPtr == NULL)
437  {
439  (
440  "dictionary::lookupEntry(const word&, bool, bool) const",
441  *this
442  ) << "keyword " << keyword << " is undefined in dictionary "
443  << name()
444  << exit(FatalIOError);
445  }
446 
447  return *entryPtr;
448 }
449 
450 
452 (
453  const word& keyword,
454  bool recursive,
455  bool patternMatch
456 ) const
457 {
458  return lookupEntry(keyword, recursive, patternMatch).stream();
459 }
460 
461 
463 (
464  const word& keyword,
465  bool recursive,
466  bool patternMatch
467 ) const
468 {
469  if (keyword[0] == ':')
470  {
471  // Go up to top level
472  const dictionary* dictPtr = this;
473  while (&dictPtr->parent_ != &dictionary::null)
474  {
475  dictPtr = &dictPtr->parent_;
476  }
477 
478  // At top. Recurse to find entries
479  return dictPtr->lookupScopedEntryPtr
480  (
481  keyword.substr(1, keyword.size()-1),
482  false,
483  patternMatch
484  );
485  }
486  else
487  {
488  string::size_type dotPos = keyword.find('.');
489 
490  if (dotPos == string::npos)
491  {
492  // Non-scoped lookup
493  return lookupEntryPtr(keyword, recursive, patternMatch);
494  }
495  else
496  {
497  if (dotPos == 0)
498  {
499  // Starting with a '.'. Go up for every 2nd '.' found
500 
501  const dictionary* dictPtr = this;
502 
503  string::size_type begVar = dotPos + 1;
504  string::const_iterator iter = keyword.begin() + begVar;
505  string::size_type endVar = begVar;
506  while
507  (
508  iter != keyword.end()
509  && *iter == '.'
510  )
511  {
512  ++iter;
513  ++endVar;
514 
515  // Go to parent
516  if (&dictPtr->parent_ == &dictionary::null)
517  {
519  (
520  "dictionary::lookupScopedEntryPtr"
521  "(const word&, bool, bool)",
522  *this
523  ) << "No parent of current dictionary"
524  << " when searching for "
525  << keyword.substr(begVar, keyword.size()-begVar)
526  << exit(FatalIOError);
527  }
528  dictPtr = &dictPtr->parent_;
529  }
530 
531  return dictPtr->lookupScopedEntryPtr
532  (
533  keyword.substr(endVar),
534  false,
535  patternMatch
536  );
537  }
538  else
539  {
540  // Extract the first word
541  word firstWord = keyword.substr(0, dotPos);
542 
543  const entry* entPtr = lookupScopedEntryPtr
544  (
545  firstWord,
546  false, //recursive
547  patternMatch
548  );
549 
550  if (!entPtr)
551  {
553  (
554  "dictionary::lookupScopedEntryPtr"
555  "(const word&, bool, bool)",
556  *this
557  ) << "keyword " << firstWord
558  << " is undefined in dictionary "
559  << name() << endl
560  << "Valid keywords are " << keys()
561  << exit(FatalIOError);
562  }
563 
564  if (entPtr->isDict())
565  {
566  return entPtr->dict().lookupScopedEntryPtr
567  (
568  keyword.substr(dotPos, keyword.size()-dotPos),
569  false,
570  patternMatch
571  );
572  }
573  else
574  {
575  return NULL;
576  }
577  }
578  }
579  }
580 }
581 
582 
584 {
585  word varName = keyword(1, keyword.size()-1);
586 
587  // lookup the variable name in the given dictionary
588  const entry* ePtr = lookupScopedEntryPtr(varName, true, true);
589 
590  // if defined insert its entries into this dictionary
591  if (ePtr != NULL)
592  {
593  const dictionary& addDict = ePtr->dict();
594 
595  forAllConstIter(IDLList<entry>, addDict, iter)
596  {
597  add(iter());
598  }
599 
600  return true;
601  }
602 
603  return false;
604 }
605 
606 
607 bool Foam::dictionary::isDict(const word& keyword) const
608 {
609  // Find non-recursive with patterns
610  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
611 
612  if (entryPtr)
613  {
614  return entryPtr->isDict();
615  }
616  else
617  {
618  return false;
619  }
620 }
621 
622 
624 {
625  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
626 
627  if (entryPtr)
628  {
629  return &entryPtr->dict();
630  }
631  else
632  {
633  return NULL;
634  }
635 }
636 
637 
638 const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
639 {
640  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
641 
642  if (entryPtr == NULL)
643  {
645  (
646  "dictionary::subDict(const word& keyword) const",
647  *this
648  ) << "keyword " << keyword << " is undefined in dictionary "
649  << name()
650  << exit(FatalIOError);
651  }
652  return entryPtr->dict();
653 }
654 
655 
657 {
658  entry* entryPtr = lookupEntryPtr(keyword, false, true);
659 
660  if (entryPtr == NULL)
661  {
663  (
664  "dictionary::subDict(const word& keyword)",
665  *this
666  ) << "keyword " << keyword << " is undefined in dictionary "
667  << name()
668  << exit(FatalIOError);
669  }
670  return entryPtr->dict();
671 }
672 
673 
675 (
676  const word& keyword,
677  const bool mustRead
678 ) const
679 {
680  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
681 
682  if (entryPtr == NULL)
683  {
684  if (mustRead)
685  {
687  (
688  "dictionary::subOrEmptyDict(const word& keyword, const bool)",
689  *this
690  ) << "keyword " << keyword << " is undefined in dictionary "
691  << name()
692  << exit(FatalIOError);
693  return entryPtr->dict();
694  }
695  else
696  {
697  return dictionary(*this, dictionary(name() + '.' + keyword));
698  }
699  }
700  else
701  {
702  return entryPtr->dict();
703  }
704 }
705 
706 
708 {
709  wordList keys(size());
710 
711  label nKeys = 0;
712  forAllConstIter(IDLList<entry>, *this, iter)
713  {
714  keys[nKeys++] = iter().keyword();
715  }
716 
717  return keys;
718 }
719 
720 
722 {
724 
725  label nKeys = 0;
726  forAllConstIter(IDLList<entry>, *this, iter)
727  {
728  if (iter().keyword().isPattern() ? patterns : !patterns)
729  {
730  keys[nKeys++] = iter().keyword();
731  }
732  }
733  keys.setSize(nKeys);
734 
735  return keys;
736 }
737 
738 
739 bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
740 {
741  HashTable<entry*>::iterator iter = hashedEntries_.find
742  (
743  entryPtr->keyword()
744  );
745 
746  if (mergeEntry && iter != hashedEntries_.end())
747  {
748  // merge dictionary with dictionary
749  if (iter()->isDict() && entryPtr->isDict())
750  {
751  iter()->dict().merge(entryPtr->dict());
752  delete entryPtr;
753 
754  return true;
755  }
756  else
757  {
758  // replace existing dictionary with entry or vice versa
759  IDLList<entry>::replace(iter(), entryPtr);
760  delete iter();
761  hashedEntries_.erase(iter);
762 
763  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
764  {
765  entryPtr->name() = name() + '.' + entryPtr->keyword();
766 
767  if (entryPtr->keyword().isPattern())
768  {
769  patternEntries_.insert(entryPtr);
770  patternRegexps_.insert
771  (
772  autoPtr<regExp>(new regExp(entryPtr->keyword()))
773  );
774  }
775 
776  return true;
777  }
778  else
779  {
780  IOWarningIn("dictionary::add(entry*, bool)", (*this))
781  << "problem replacing entry "<< entryPtr->keyword()
782  << " in dictionary " << name() << endl;
783 
784  IDLList<entry>::remove(entryPtr);
785  delete entryPtr;
786  return false;
787  }
788  }
789  }
790 
791  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
792  {
793  entryPtr->name() = name() + '.' + entryPtr->keyword();
794  IDLList<entry>::append(entryPtr);
795 
796  if (entryPtr->keyword().isPattern())
797  {
798  patternEntries_.insert(entryPtr);
799  patternRegexps_.insert
800  (
801  autoPtr<regExp>(new regExp(entryPtr->keyword()))
802  );
803  }
804 
805  return true;
806  }
807  else
808  {
809  IOWarningIn("dictionary::add(entry*, bool)", (*this))
810  << "attempt to add entry "<< entryPtr->keyword()
811  << " which already exists in dictionary " << name()
812  << endl;
813 
814  delete entryPtr;
815  return false;
816  }
817 }
818 
819 
820 void Foam::dictionary::add(const entry& e, bool mergeEntry)
821 {
822  add(e.clone(*this).ptr(), mergeEntry);
823 }
824 
825 
826 void Foam::dictionary::add(const keyType& k, const word& w, bool overwrite)
827 {
828  add(new primitiveEntry(k, token(w)), overwrite);
829 }
830 
831 
833 (
834  const keyType& k,
835  const Foam::string& s,
836  bool overwrite
837 )
838 {
839  add(new primitiveEntry(k, token(s)), overwrite);
840 }
841 
842 
843 void Foam::dictionary::add(const keyType& k, const label l, bool overwrite)
844 {
845  add(new primitiveEntry(k, token(l)), overwrite);
846 }
847 
848 
849 void Foam::dictionary::add(const keyType& k, const scalar s, bool overwrite)
850 {
851  add(new primitiveEntry(k, token(s)), overwrite);
852 }
853 
854 
856 (
857  const keyType& k,
858  const dictionary& d,
859  bool mergeEntry
860 )
861 {
862  add(new dictionaryEntry(k, *this, d), mergeEntry);
863 }
864 
865 
867 {
868  entry* existingPtr = lookupEntryPtr(entryPtr->keyword(), false, true);
869 
870  // clear dictionary so merge acts like overwrite
871  if (existingPtr && existingPtr->isDict())
872  {
873  existingPtr->dict().clear();
874  }
875  add(entryPtr, true);
876 }
877 
878 
880 {
881  set(e.clone(*this).ptr());
882 }
883 
884 
885 void Foam::dictionary::set(const keyType& k, const dictionary& d)
886 {
887  set(new dictionaryEntry(k, *this, d));
888 }
889 
890 
891 bool Foam::dictionary::remove(const word& Keyword)
892 {
893  HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword);
894 
895  if (iter != hashedEntries_.end())
896  {
897  // Delete from patterns first
898  DLList<entry*>::iterator wcLink =
899  patternEntries_.begin();
901  patternRegexps_.begin();
902 
903  // Find in pattern using exact match only
904  if (findInPatterns(false, Keyword, wcLink, reLink))
905  {
906  patternEntries_.remove(wcLink);
907  patternRegexps_.remove(reLink);
908  }
909 
910  IDLList<entry>::remove(iter());
911  delete iter();
912  hashedEntries_.erase(iter);
913 
914  return true;
915  }
916  else
917  {
918  return false;
919  }
920 }
921 
922 
924 (
925  const keyType& oldKeyword,
926  const keyType& newKeyword,
927  bool forceOverwrite
928 )
929 {
930  // no change
931  if (oldKeyword == newKeyword)
932  {
933  return false;
934  }
935 
936  HashTable<entry*>::iterator iter = hashedEntries_.find(oldKeyword);
937 
938  // oldKeyword not found - do nothing
939  if (iter == hashedEntries_.end())
940  {
941  return false;
942  }
943 
944  if (iter()->keyword().isPattern())
945  {
947  (
948  "dictionary::changeKeyword(const word&, const word&, bool)",
949  *this
950  ) << "Old keyword "<< oldKeyword
951  << " is a pattern."
952  << "Pattern replacement not yet implemented."
953  << exit(FatalIOError);
954  }
955 
956 
957  HashTable<entry*>::iterator iter2 = hashedEntries_.find(newKeyword);
958 
959  // newKeyword already exists
960  if (iter2 != hashedEntries_.end())
961  {
962  if (forceOverwrite)
963  {
964  if (iter2()->keyword().isPattern())
965  {
966  // Delete from patterns first
967  DLList<entry*>::iterator wcLink =
968  patternEntries_.begin();
970  patternRegexps_.begin();
971 
972  // Find in patterns using exact match only
973  if (findInPatterns(false, iter2()->keyword(), wcLink, reLink))
974  {
975  patternEntries_.remove(wcLink);
976  patternRegexps_.remove(reLink);
977  }
978  }
979 
980  IDLList<entry>::replace(iter2(), iter());
981  delete iter2();
982  hashedEntries_.erase(iter2);
983 
984  }
985  else
986  {
988  (
989  "dictionary::changeKeyword(const word&, const word&, bool)",
990  *this
991  ) << "cannot rename keyword "<< oldKeyword
992  << " to existing keyword " << newKeyword
993  << " in dictionary " << name() << endl;
994  return false;
995  }
996  }
997 
998  // change name and HashTable, but leave DL-List untouched
999  iter()->keyword() = newKeyword;
1000  iter()->name() = name() + '.' + newKeyword;
1001  hashedEntries_.erase(oldKeyword);
1002  hashedEntries_.insert(newKeyword, iter());
1003 
1004  if (newKeyword.isPattern())
1005  {
1006  patternEntries_.insert(iter());
1007  patternRegexps_.insert
1008  (
1009  autoPtr<regExp>(new regExp(newKeyword))
1010  );
1011  }
1012 
1013  return true;
1014 }
1015 
1016 
1018 {
1019  // Check for assignment to self
1020  if (this == &dict)
1021  {
1022  FatalIOErrorIn("dictionary::merge(const dictionary&)", *this)
1023  << "attempted merge to self for dictionary " << name()
1024  << abort(FatalIOError);
1025  }
1026 
1027  bool changed = false;
1028 
1029  forAllConstIter(IDLList<entry>, dict, iter)
1030  {
1031  HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword());
1032 
1033  if (fnd != hashedEntries_.end())
1034  {
1035  // Recursively merge sub-dictionaries
1036  // TODO: merge without copying
1037  if (fnd()->isDict() && iter().isDict())
1038  {
1039  if (fnd()->dict().merge(iter().dict()))
1040  {
1041  changed = true;
1042  }
1043  }
1044  else
1045  {
1046  add(iter().clone(*this).ptr(), true);
1047  changed = true;
1048  }
1049  }
1050  else
1051  {
1052  // not found - just add
1053  add(iter().clone(*this).ptr());
1054  changed = true;
1055  }
1056  }
1057 
1058  return changed;
1059 }
1060 
1061 
1063 {
1065  hashedEntries_.clear();
1066  patternEntries_.clear();
1067  patternRegexps_.clear();
1068 }
1069 
1070 
1072 {
1073  // changing parents probably doesn't make much sense,
1074  // but what about the names?
1075  name() = dict.name();
1076 
1078  hashedEntries_.transfer(dict.hashedEntries_);
1079  patternEntries_.transfer(dict.patternEntries_);
1080  patternRegexps_.transfer(dict.patternRegexps_);
1081 }
1082 
1083 
1085 {
1086  return xferMove(*this);
1087 }
1088 
1089 
1090 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
1091 
1093 {
1094  return lookup(keyword);
1095 }
1096 
1097 
1099 {
1100  // Check for assignment to self
1101  if (this == &rhs)
1102  {
1103  FatalIOErrorIn("dictionary::operator=(const dictionary&)", *this)
1104  << "attempted assignment to self for dictionary " << name()
1105  << abort(FatalIOError);
1106  }
1107 
1108  name() = rhs.name();
1109  clear();
1110 
1111  // Create clones of the entries in the given dictionary
1112  // resetting the parentDict to this dictionary
1113 
1114  forAllConstIter(IDLList<entry>, rhs, iter)
1115  {
1116  add(iter().clone(*this).ptr());
1117  }
1118 }
1119 
1120 
1122 {
1123  // Check for assignment to self
1124  if (this == &rhs)
1125  {
1126  FatalIOErrorIn("dictionary::operator+=(const dictionary&)", *this)
1127  << "attempted addition assignment to self for dictionary " << name()
1128  << abort(FatalIOError);
1129  }
1130 
1131  forAllConstIter(IDLList<entry>, rhs, iter)
1132  {
1133  add(iter().clone(*this).ptr());
1134  }
1135 }
1136 
1137 
1139 {
1140  // Check for assignment to self
1141  if (this == &rhs)
1142  {
1143  FatalIOErrorIn("dictionary::operator|=(const dictionary&)", *this)
1144  << "attempted assignment to self for dictionary " << name()
1145  << abort(FatalIOError);
1146  }
1147 
1148  forAllConstIter(IDLList<entry>, rhs, iter)
1149  {
1150  if (!found(iter().keyword()))
1151  {
1152  add(iter().clone(*this).ptr());
1153  }
1154  }
1155 }
1156 
1157 
1159 {
1160  // Check for assignment to self
1161  if (this == &rhs)
1162  {
1163  FatalIOErrorIn("dictionary::operator<<=(const dictionary&)", *this)
1164  << "attempted assignment to self for dictionary " << name()
1165  << abort(FatalIOError);
1166  }
1167 
1168  forAllConstIter(IDLList<entry>, rhs, iter)
1169  {
1170  set(iter().clone(*this).ptr());
1171  }
1172 }
1173 
1174 
1175 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
1176 
1177 Foam::dictionary Foam::operator+
1179  const dictionary& dict1,
1180  const dictionary& dict2
1181 )
1182 {
1183  dictionary sum(dict1);
1184  sum += dict2;
1185  return sum;
1186 }
1187 
1188 
1189 Foam::dictionary Foam::operator|
1191  const dictionary& dict1,
1192  const dictionary& dict2
1193 )
1194 {
1195  dictionary sum(dict1);
1196  sum |= dict2;
1197  return sum;
1198 }
1199 
1200 
1201 // ************************************************************************* //
Input from memory buffer stream.
Definition: IStringStream.H:49
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:286
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
entry * last()
Return the last entry.
Definition: UILList.H:118
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
Definition: debug.C:174
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:113
void clear()
Clear the contents of the list.
entry * first()
Return the first entry.
Definition: UILList.H:106
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:231
friend class iterator
Definition: LList.H:82
Input token stream.
Definition: ITstream.H:49
An STL-conforming const_iterator.
Definition: HashTable.H:470
Xfer< dictionary > xfer()
Transfer contents to the Xfer container.
Definition: dictionary.C:1084
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:272
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:133
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1158
An STL-conforming iterator.
Definition: HashTable.H:415
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:891
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
#define forAllIter(Container, container, iter)
Definition: UList.H:440
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:463
dictionaryName()
Construct dictionaryName null.
Definition: dictionary.H:90
string str() const
Return the string.
bool substituteScopedKeyword(const word &keyword)
Substitute the given scoped keyword prepended by &#39;$&#39; with the.
Definition: dictionary.C:583
A class for handling words, derived from string.
Definition: word.H:59
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:59
A class for handling character strings derived from std::string.
Definition: string.H:74
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
virtual const fileName & name() const =0
Return the dictionary name.
void append(link *)
Add at tail of list.
Definition: DLListBase.C:73
T * remove(T *p)
Remove and return element.
Definition: UILList.H:139
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
Xfer< T > xferMove(T &)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1017
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:623
Namespace for OpenFOAM.
#define IOWarningIn(functionName, ios)
Report an IO warning using Foam::Warning.
A class for handling keywords in dictionaries.
Definition: keyType.H:56
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:345
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
void transfer(ILList< DLListBase, T > &)
Transfer the contents of the argument into this List.
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:246
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dictionary dict
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
const double e
Elementary charge.
Definition: doubleFloat.H:78
ITstream & operator[](const word &) const
Find and return entry.
Definition: dictionary.C:1092
void setSize(const label)
Reset size of List.
Definition: List.C:318
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
volScalarField & p
Definition: createFields.H:51
wordList toc() const
Return the table of contents.
Definition: dictionary.C:707
An STL-conforming const_iterator.
Definition: DLListBase.H:228
Output to memory buffer stream.
Definition: OStringStream.H:49
A token holds items read from Istream.
Definition: token.H:67
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:739
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Non-intrusive doubly-linked list.
Definition: DLList.H:47
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:1138
link * replace(link *oldLink, link *newLink)
Replace oldLink with newLink and return element.
Definition: DLListBase.C:232
Foam::SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:185
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:866
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:607
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:215
Wrapper around POSIX extended regular expressions.
Definition: regExp.H:61
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
A class for handling file names.
Definition: fileName.H:69
A keyword and a list of tokens is a &#39;primitiveEntry&#39;. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
List< token > tokenList
List of tokens, used for a IOdictionary entry.
Definition: tokenList.H:43
friend class const_iterator
Definition: LList.H:85
An STL-conforming iterator.
Definition: DLListBase.H:181
void clear()
Clear the dictionary.
Definition: dictionary.C:1062
virtual label endLineNumber() const =0
Return line number of last token in dictionary.
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:251
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:173
void operator=(const dictionary &)
Definition: dictionary.C:1098
virtual ~dictionary()
Destructor.
Definition: dictionary.C:223
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:259
void operator+=(const dictionary &)
Include entries from the given dictionary.
Definition: dictionary.C:1121
The SHA1 message digest.
Definition: SHA1Digest.H:62
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:428
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:721
defineTypeNameAndDebug(combustionModel, 0)
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
Definition: dictionary.C:924
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:675
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1071
virtual label startLineNumber() const =0
Return line number of first token in dictionary.