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-2016 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 *this;
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  // Serialize 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  *this
441  ) << "keyword " << keyword << " is undefined in dictionary "
442  << name()
443  << exit(FatalIOError);
444  }
445 
446  return *entryPtr;
447 }
448 
449 
451 (
452  const word& keyword,
453  bool recursive,
454  bool patternMatch
455 ) const
456 {
457  return lookupEntry(keyword, recursive, patternMatch).stream();
458 }
459 
460 
462 (
463  const word& keyword,
464  bool recursive,
465  bool patternMatch
466 ) const
467 {
468  if (keyword[0] == ':')
469  {
470  // Go up to top level
471  const dictionary* dictPtr = this;
472  while (&dictPtr->parent_ != &dictionary::null)
473  {
474  dictPtr = &dictPtr->parent_;
475  }
476 
477  // At top. Recurse to find entries
478  return dictPtr->lookupScopedEntryPtr
479  (
480  keyword.substr(1, keyword.size()-1),
481  false,
482  patternMatch
483  );
484  }
485  else
486  {
487  string::size_type dotPos = keyword.find('.');
488 
489  if (dotPos == string::npos)
490  {
491  // Non-scoped lookup
492  return lookupEntryPtr(keyword, recursive, patternMatch);
493  }
494  else
495  {
496  if (dotPos == 0)
497  {
498  // Starting with a '.'. Go up for every 2nd '.' found
499 
500  const dictionary* dictPtr = this;
501 
502  string::size_type begVar = dotPos + 1;
503  string::const_iterator iter = keyword.begin() + begVar;
504  string::size_type endVar = begVar;
505  while
506  (
507  iter != keyword.end()
508  && *iter == '.'
509  )
510  {
511  ++iter;
512  ++endVar;
513 
514  // Go to parent
515  if (&dictPtr->parent_ == &dictionary::null)
516  {
518  (
519  *this
520  ) << "No parent of current dictionary"
521  << " when searching for "
522  << keyword.substr(begVar, keyword.size()-begVar)
523  << exit(FatalIOError);
524  }
525  dictPtr = &dictPtr->parent_;
526  }
527 
528  return dictPtr->lookupScopedEntryPtr
529  (
530  keyword.substr(endVar),
531  false,
532  patternMatch
533  );
534  }
535  else
536  {
537  // Extract the first word
538  word firstWord = keyword.substr(0, dotPos);
539 
540  const entry* entPtr = lookupScopedEntryPtr
541  (
542  firstWord,
543  false, //recursive
544  patternMatch
545  );
546 
547  if (!entPtr)
548  {
550  (
551  *this
552  ) << "keyword " << firstWord
553  << " is undefined in dictionary "
554  << name() << endl
555  << "Valid keywords are " << keys()
556  << exit(FatalIOError);
557  }
558 
559  if (entPtr->isDict())
560  {
561  return entPtr->dict().lookupScopedEntryPtr
562  (
563  keyword.substr(dotPos, keyword.size()-dotPos),
564  false,
565  patternMatch
566  );
567  }
568  else
569  {
570  return NULL;
571  }
572  }
573  }
574  }
575 }
576 
577 
579 {
580  word varName = keyword(1, keyword.size()-1);
581 
582  // Lookup the variable name in the given dictionary
583  const entry* ePtr = lookupScopedEntryPtr(varName, true, true);
584 
585  // If defined insert its entries into this dictionary
586  if (ePtr != NULL)
587  {
588  const dictionary& addDict = ePtr->dict();
589 
590  forAllConstIter(IDLList<entry>, addDict, iter)
591  {
592  add(iter());
593  }
594 
595  return true;
596  }
597 
598  return false;
599 }
600 
601 
602 bool Foam::dictionary::isDict(const word& keyword) const
603 {
604  // Find non-recursive with patterns
605  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
606 
607  if (entryPtr)
608  {
609  return entryPtr->isDict();
610  }
611  else
612  {
613  return false;
614  }
615 }
616 
617 
619 {
620  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
621 
622  if (entryPtr)
623  {
624  return &entryPtr->dict();
625  }
626  else
627  {
628  return NULL;
629  }
630 }
631 
632 
633 const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
634 {
635  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
636 
637  if (entryPtr == NULL)
638  {
640  (
641  *this
642  ) << "keyword " << keyword << " is undefined in dictionary "
643  << name()
644  << exit(FatalIOError);
645  }
646  return entryPtr->dict();
647 }
648 
649 
651 {
652  entry* entryPtr = lookupEntryPtr(keyword, false, true);
653 
654  if (entryPtr == NULL)
655  {
657  (
658  *this
659  ) << "keyword " << keyword << " is undefined in dictionary "
660  << name()
661  << exit(FatalIOError);
662  }
663  return entryPtr->dict();
664 }
665 
666 
668 (
669  const word& keyword,
670  const bool mustRead
671 ) const
672 {
673  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
674 
675  if (entryPtr == NULL)
676  {
677  if (mustRead)
678  {
680  (
681  *this
682  ) << "keyword " << keyword << " is undefined in dictionary "
683  << name()
684  << exit(FatalIOError);
685  return entryPtr->dict();
686  }
687  else
688  {
689  return dictionary(*this, dictionary(name() + '.' + keyword));
690  }
691  }
692  else
693  {
694  return entryPtr->dict();
695  }
696 }
697 
698 
700 {
701  wordList keys(size());
702 
703  label nKeys = 0;
704  forAllConstIter(IDLList<entry>, *this, iter)
705  {
706  keys[nKeys++] = iter().keyword();
707  }
708 
709  return keys;
710 }
711 
712 
714 {
715  return hashedEntries_.sortedToc();
716 }
717 
718 
720 {
722 
723  label nKeys = 0;
724  forAllConstIter(IDLList<entry>, *this, iter)
725  {
726  if (iter().keyword().isPattern() ? patterns : !patterns)
727  {
728  keys[nKeys++] = iter().keyword();
729  }
730  }
731  keys.setSize(nKeys);
732 
733  return keys;
734 }
735 
736 
737 bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
738 {
739  HashTable<entry*>::iterator iter = hashedEntries_.find
740  (
741  entryPtr->keyword()
742  );
743 
744  if (mergeEntry && iter != hashedEntries_.end())
745  {
746  // Merge dictionary with dictionary
747  if (iter()->isDict() && entryPtr->isDict())
748  {
749  iter()->dict().merge(entryPtr->dict());
750  delete entryPtr;
751 
752  return true;
753  }
754  else
755  {
756  // Replace existing dictionary with entry or vice versa
757  IDLList<entry>::replace(iter(), entryPtr);
758  delete iter();
759  hashedEntries_.erase(iter);
760 
761  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
762  {
763  entryPtr->name() = name() + '.' + entryPtr->keyword();
764 
765  if (entryPtr->keyword().isPattern())
766  {
767  patternEntries_.insert(entryPtr);
768  patternRegexps_.insert
769  (
770  autoPtr<regExp>(new regExp(entryPtr->keyword()))
771  );
772  }
773 
774  return true;
775  }
776  else
777  {
778  IOWarningInFunction((*this))
779  << "problem replacing entry "<< entryPtr->keyword()
780  << " in dictionary " << name() << endl;
781 
782  IDLList<entry>::remove(entryPtr);
783  delete entryPtr;
784  return false;
785  }
786  }
787  }
788 
789  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
790  {
791  entryPtr->name() = name() + '.' + entryPtr->keyword();
792  IDLList<entry>::append(entryPtr);
793 
794  if (entryPtr->keyword().isPattern())
795  {
796  patternEntries_.insert(entryPtr);
797  patternRegexps_.insert
798  (
799  autoPtr<regExp>(new regExp(entryPtr->keyword()))
800  );
801  }
802 
803  return true;
804  }
805  else
806  {
807  IOWarningInFunction((*this))
808  << "attempt to add entry "<< entryPtr->keyword()
809  << " which already exists in dictionary " << name()
810  << endl;
811 
812  delete entryPtr;
813  return false;
814  }
815 }
816 
817 
818 void Foam::dictionary::add(const entry& e, bool mergeEntry)
819 {
820  add(e.clone(*this).ptr(), mergeEntry);
821 }
822 
823 
824 void Foam::dictionary::add(const keyType& k, const word& w, bool overwrite)
825 {
826  add(new primitiveEntry(k, token(w)), overwrite);
827 }
828 
829 
831 (
832  const keyType& k,
833  const Foam::string& s,
834  bool overwrite
835 )
836 {
837  add(new primitiveEntry(k, token(s)), overwrite);
838 }
839 
840 
841 void Foam::dictionary::add(const keyType& k, const label l, bool overwrite)
842 {
843  add(new primitiveEntry(k, token(l)), overwrite);
844 }
845 
846 
847 void Foam::dictionary::add(const keyType& k, const scalar s, bool overwrite)
848 {
849  add(new primitiveEntry(k, token(s)), overwrite);
850 }
851 
852 
854 (
855  const keyType& k,
856  const dictionary& d,
857  bool mergeEntry
858 )
859 {
860  add(new dictionaryEntry(k, *this, d), mergeEntry);
861 }
862 
863 
865 {
866  entry* existingPtr = lookupEntryPtr(entryPtr->keyword(), false, true);
867 
868  // Clear dictionary so merge acts like overwrite
869  if (existingPtr && existingPtr->isDict())
870  {
871  existingPtr->dict().clear();
872  }
873  add(entryPtr, true);
874 }
875 
876 
878 {
879  set(e.clone(*this).ptr());
880 }
881 
882 
883 void Foam::dictionary::set(const keyType& k, const dictionary& d)
884 {
885  set(new dictionaryEntry(k, *this, d));
886 }
887 
888 
889 bool Foam::dictionary::remove(const word& Keyword)
890 {
891  HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword);
892 
893  if (iter != hashedEntries_.end())
894  {
895  // Delete from patterns first
896  DLList<entry*>::iterator wcLink =
897  patternEntries_.begin();
899  patternRegexps_.begin();
900 
901  // Find in pattern using exact match only
902  if (findInPatterns(false, Keyword, wcLink, reLink))
903  {
904  patternEntries_.remove(wcLink);
905  patternRegexps_.remove(reLink);
906  }
907 
908  IDLList<entry>::remove(iter());
909  delete iter();
910  hashedEntries_.erase(iter);
911 
912  return true;
913  }
914  else
915  {
916  return false;
917  }
918 }
919 
920 
922 (
923  const keyType& oldKeyword,
924  const keyType& newKeyword,
925  bool forceOverwrite
926 )
927 {
928  // No change
929  if (oldKeyword == newKeyword)
930  {
931  return false;
932  }
933 
934  HashTable<entry*>::iterator iter = hashedEntries_.find(oldKeyword);
935 
936  // oldKeyword not found - do nothing
937  if (iter == hashedEntries_.end())
938  {
939  return false;
940  }
941 
942  if (iter()->keyword().isPattern())
943  {
945  (
946  *this
947  ) << "Old keyword "<< oldKeyword
948  << " is a pattern."
949  << "Pattern replacement not yet implemented."
950  << exit(FatalIOError);
951  }
952 
953 
954  HashTable<entry*>::iterator iter2 = hashedEntries_.find(newKeyword);
955 
956  // newKeyword already exists
957  if (iter2 != hashedEntries_.end())
958  {
959  if (forceOverwrite)
960  {
961  if (iter2()->keyword().isPattern())
962  {
963  // Delete from patterns first
964  DLList<entry*>::iterator wcLink =
965  patternEntries_.begin();
967  patternRegexps_.begin();
968 
969  // Find in patterns using exact match only
970  if (findInPatterns(false, iter2()->keyword(), wcLink, reLink))
971  {
972  patternEntries_.remove(wcLink);
973  patternRegexps_.remove(reLink);
974  }
975  }
976 
977  IDLList<entry>::replace(iter2(), iter());
978  delete iter2();
979  hashedEntries_.erase(iter2);
980 
981  }
982  else
983  {
985  (
986  *this
987  ) << "cannot rename keyword "<< oldKeyword
988  << " to existing keyword " << newKeyword
989  << " in dictionary " << name() << endl;
990  return false;
991  }
992  }
993 
994  // Change name and HashTable, but leave DL-List untouched
995  iter()->keyword() = newKeyword;
996  iter()->name() = name() + '.' + newKeyword;
997  hashedEntries_.erase(oldKeyword);
998  hashedEntries_.insert(newKeyword, iter());
999 
1000  if (newKeyword.isPattern())
1001  {
1002  patternEntries_.insert(iter());
1003  patternRegexps_.insert
1004  (
1005  autoPtr<regExp>(new regExp(newKeyword))
1006  );
1007  }
1008 
1009  return true;
1010 }
1011 
1012 
1014 {
1015  // Check for assignment to self
1016  if (this == &dict)
1017  {
1018  FatalIOErrorInFunction(*this)
1019  << "attempted merge to self for dictionary " << name()
1020  << abort(FatalIOError);
1021  }
1022 
1023  bool changed = false;
1024 
1025  forAllConstIter(IDLList<entry>, dict, iter)
1026  {
1027  HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword());
1028 
1029  if (fnd != hashedEntries_.end())
1030  {
1031  // Recursively merge sub-dictionaries
1032  // TODO: merge without copying
1033  if (fnd()->isDict() && iter().isDict())
1034  {
1035  if (fnd()->dict().merge(iter().dict()))
1036  {
1037  changed = true;
1038  }
1039  }
1040  else
1041  {
1042  add(iter().clone(*this).ptr(), true);
1043  changed = true;
1044  }
1045  }
1046  else
1047  {
1048  // Not found - just add
1049  add(iter().clone(*this).ptr());
1050  changed = true;
1051  }
1052  }
1053 
1054  return changed;
1055 }
1056 
1057 
1059 {
1061  hashedEntries_.clear();
1062  patternEntries_.clear();
1063  patternRegexps_.clear();
1064 }
1065 
1066 
1068 {
1069  // Changing parents probably doesn't make much sense,
1070  // but what about the names?
1071  name() = dict.name();
1072 
1074  hashedEntries_.transfer(dict.hashedEntries_);
1075  patternEntries_.transfer(dict.patternEntries_);
1076  patternRegexps_.transfer(dict.patternRegexps_);
1077 }
1078 
1079 
1081 {
1082  return xferMove(*this);
1083 }
1084 
1085 
1086 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
1087 
1089 {
1090  return lookup(keyword);
1091 }
1092 
1093 
1095 {
1096  // Check for assignment to self
1097  if (this == &rhs)
1098  {
1099  FatalIOErrorInFunction(*this)
1100  << "attempted assignment to self for dictionary " << name()
1101  << abort(FatalIOError);
1102  }
1103 
1104  name() = rhs.name();
1105  clear();
1106 
1107  // Create clones of the entries in the given dictionary
1108  // resetting the parentDict to this dictionary
1109 
1110  forAllConstIter(IDLList<entry>, rhs, iter)
1111  {
1112  add(iter().clone(*this).ptr());
1113  }
1114 }
1115 
1116 
1118 {
1119  // Check for assignment to self
1120  if (this == &rhs)
1121  {
1122  FatalIOErrorInFunction(*this)
1123  << "attempted addition assignment to self for dictionary " << name()
1124  << abort(FatalIOError);
1125  }
1126 
1127  forAllConstIter(IDLList<entry>, rhs, iter)
1128  {
1129  add(iter().clone(*this).ptr());
1130  }
1131 }
1132 
1133 
1135 {
1136  // Check for assignment to self
1137  if (this == &rhs)
1138  {
1139  FatalIOErrorInFunction(*this)
1140  << "attempted assignment to self for dictionary " << name()
1141  << abort(FatalIOError);
1142  }
1143 
1144  forAllConstIter(IDLList<entry>, rhs, iter)
1145  {
1146  if (!found(iter().keyword()))
1147  {
1148  add(iter().clone(*this).ptr());
1149  }
1150  }
1151 }
1152 
1153 
1155 {
1156  // Check for assignment to self
1157  if (this == &rhs)
1158  {
1159  FatalIOErrorInFunction(*this)
1160  << "attempted assignment to self for dictionary " << name()
1161  << abort(FatalIOError);
1162  }
1163 
1164  forAllConstIter(IDLList<entry>, rhs, iter)
1165  {
1166  set(iter().clone(*this).ptr());
1167  }
1168 }
1169 
1170 
1171 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
1172 
1173 Foam::dictionary Foam::operator+
1175  const dictionary& dict1,
1176  const dictionary& dict2
1177 )
1178 {
1179  dictionary sum(dict1);
1180  sum += dict2;
1181  return sum;
1182 }
1183 
1184 
1185 Foam::dictionary Foam::operator|
1187  const dictionary& dict1,
1188  const dictionary& dict2
1189 )
1190 {
1191  dictionary sum(dict1);
1192  sum |= dict2;
1193  return sum;
1194 }
1195 
1196 
1197 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:64
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
string str() const
Return the string.
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
dictionary dict
wordList toc() const
Return the table of contents.
Definition: dictionary.C:699
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:889
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 file names.
Definition: fileName.H:69
void operator=(const dictionary &)
Definition: dictionary.C:1094
An STL-conforming const_iterator.
Definition: HashTable.H:470
Wrapper around POSIX extended regular expressions.
Definition: regExp.H:61
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void operator+=(const dictionary &)
Include entries from the given dictionary.
Definition: dictionary.C:1117
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:719
const double e
Elementary charge.
Definition: doubleFloat.H:78
List< token > tokenList
List of tokens, used for a IOdictionary entry.
Definition: tokenList.H:42
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void transfer(ILList< DLListBase, T > &)
Transfer the contents of the argument into this 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:59
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:668
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
dictionaryName()
Construct dictionaryName null.
Definition: dictionary.H:90
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
virtual label startLineNumber() const =0
Return line number of first token in dictionary.
A token holds items read from Istream.
Definition: token.H:69
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:602
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
The SHA1 message digest.
Definition: SHA1Digest.H:62
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:345
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
friend class iterator
Definition: LList.H:82
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
link * replace(link *oldLink, link *newLink)
Replace oldLink with newLink and return element.
Definition: DLListBase.C:232
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:133
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
entry * last()
Return the last entry.
Definition: UILList.H:118
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:259
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1067
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:286
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
Definition: debug.C:175
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:737
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:215
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.
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:113
An STL-conforming iterator.
Definition: HashTable.H:415
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
Definition: dictionary.C:922
ITstream & operator[](const word &) const
Find and return entry.
Definition: dictionary.C:1088
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:713
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1154
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:462
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
A class for handling words, derived from string.
Definition: word.H:59
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
void clear()
Clear the contents of the list.
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:246
An STL-conforming const_iterator.
Definition: DLListBase.H:228
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
An STL-conforming iterator.
Definition: DLListBase.H:181
Non-intrusive doubly-linked list.
Definition: DLList.H:47
T * remove(T *p)
Remove and return element.
Definition: UILList.H:139
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Xfer< dictionary > xfer()
Transfer contents to the Xfer container.
Definition: dictionary.C:1080
void append(link *)
Add at tail of list.
Definition: DLListBase.C:73
defineTypeNameAndDebug(combustionModel, 0)
virtual label endLineNumber() const =0
Return line number of last token in dictionary.
friend class const_iterator
Definition: LList.H:85
void setSize(const label)
Reset size of List.
Definition: List.C:295
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:1134
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:618
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:173
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Input from memory buffer stream.
Definition: IStringStream.H:49
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:272
virtual const fileName & name() const =0
Return the dictionary name.
virtual ~dictionary()
Destructor.
Definition: dictionary.C:223
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:864
bool substituteScopedKeyword(const word &keyword)
Substitute the given scoped keyword prepended by &#39;$&#39; with the.
Definition: dictionary.C:578
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1013
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:251
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
volScalarField & p
entry * first()
Return the first entry.
Definition: UILList.H:106
void clear()
Clear the dictionary.
Definition: dictionary.C:1058
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
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:231
A class for handling character strings derived from std::string.
Definition: string.H:74
Output to memory buffer stream.
Definition: OStringStream.H:49
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
Input token stream.
Definition: ITstream.H:49
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
Foam::SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:185
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451
IOerror FatalIOError