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 | Copyright (C) 2015 OpenCFD Ltd.
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 
41  (
42  debug::infoSwitch("writeOptionalEntries", 0)
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
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 
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 :
122  parent_(dictionary::null)
123 {}
124 
125 
127 (
128  const dictionary& parentDict,
129  const dictionary& dict
130 )
131 :
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 :
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 
226 
227 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
228 
230 {
231  const dictionary& p = parent();
232 
233  if (&p != this && !p.name().empty())
234  {
235  return p.topDict();
236  }
237  else
238  {
239  return *this;
240  }
241 }
242 
243 
245 {
246  if (size())
247  {
248  return first()->startLineNumber();
249  }
250  else
251  {
252  return -1;
253  }
254 }
255 
256 
258 {
259  if (size())
260  {
261  return last()->endLineNumber();
262  }
263  else
264  {
265  return -1;
266  }
267 }
268 
269 
271 {
272  OSHA1stream os;
273 
274  // process entries
275  forAllConstIter(IDLList<entry>, *this, iter)
276  {
277  os << *iter;
278  }
279 
280  return os.digest();
281 }
282 
283 
285 {
286  // linearise dictionary into a string
287  OStringStream os;
288  write(os, false);
289  IStringStream is(os.str());
290 
291  // parse string as tokens
292  DynamicList<token> tokens;
293  token t;
294  while (is.read(t))
295  {
296  tokens.append(t);
297  }
298 
299  return tokenList(tokens.xfer());
300 }
301 
302 
304 (
305  const word& keyword,
306  bool recursive,
307  bool patternMatch
308 ) const
309 {
310  if (hashedEntries_.found(keyword))
311  {
312  return true;
313  }
314  else
315  {
316  if (patternMatch && patternEntries_.size())
317  {
319  patternEntries_.begin();
320  DLList<autoPtr<regExp> >::const_iterator reLink =
321  patternRegexps_.begin();
322 
323  // Find in patterns using regular expressions only
324  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
325  {
326  return true;
327  }
328  }
329 
330  if (recursive && &parent_ != &dictionary::null)
331  {
332  return parent_.found(keyword, recursive, patternMatch);
333  }
334  else
335  {
336  return false;
337  }
338  }
339 }
340 
341 
343 (
344  const word& keyword,
345  bool recursive,
346  bool patternMatch
347 ) const
348 {
349  HashTable<entry*>::const_iterator iter = hashedEntries_.find(keyword);
350 
351  if (iter == hashedEntries_.end())
352  {
353  if (patternMatch && patternEntries_.size())
354  {
356  patternEntries_.begin();
357  DLList<autoPtr<regExp> >::const_iterator reLink =
358  patternRegexps_.begin();
359 
360  // Find in patterns using regular expressions only
361  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
362  {
363  return wcLink();
364  }
365  }
366 
367  if (recursive && &parent_ != &dictionary::null)
368  {
369  return parent_.lookupEntryPtr(keyword, recursive, patternMatch);
370  }
371  else
372  {
373  return NULL;
374  }
375  }
376 
377  return iter();
378 }
379 
380 
382 (
383  const word& keyword,
384  bool recursive,
385  bool patternMatch
386 )
387 {
388  HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);
389 
390  if (iter == hashedEntries_.end())
391  {
392  if (patternMatch && patternEntries_.size())
393  {
394  DLList<entry*>::iterator wcLink =
395  patternEntries_.begin();
396  DLList<autoPtr<regExp> >::iterator reLink =
397  patternRegexps_.begin();
398 
399  // Find in patterns using regular expressions only
400  if (findInPatterns(patternMatch, keyword, wcLink, reLink))
401  {
402  return wcLink();
403  }
404  }
405 
406  if (recursive && &parent_ != &dictionary::null)
407  {
408  return const_cast<dictionary&>(parent_).lookupEntryPtr
409  (
410  keyword,
411  recursive,
412  patternMatch
413  );
414  }
415  else
416  {
417  return NULL;
418  }
419  }
420 
421  return iter();
422 }
423 
424 
426 (
427  const word& keyword,
428  bool recursive,
429  bool patternMatch
430 ) const
431 {
432  const entry* entryPtr = lookupEntryPtr(keyword, recursive, patternMatch);
433 
434  if (entryPtr == NULL)
435  {
437  (
438  *this
439  ) << "keyword " << keyword << " is undefined in dictionary "
440  << name()
441  << exit(FatalIOError);
442  }
443 
444  return *entryPtr;
445 }
446 
447 
449 (
450  const word& keyword,
451  bool recursive,
452  bool patternMatch
453 ) const
454 {
455  return lookupEntry(keyword, recursive, patternMatch).stream();
456 }
457 
458 
460 (
461  const word& keyword,
462  bool recursive,
463  bool patternMatch
464 ) const
465 {
466  if (keyword[0] == ':')
467  {
468  // Go up to top level
469  const dictionary* dictPtr = this;
470  while (&dictPtr->parent_ != &dictionary::null)
471  {
472  dictPtr = &dictPtr->parent_;
473  }
474 
475  // At top. Recurse to find entries
476  return dictPtr->lookupScopedEntryPtr
477  (
478  keyword.substr(1, keyword.size()-1),
479  false,
480  patternMatch
481  );
482  }
483  else
484  {
485  string::size_type dotPos = keyword.find('.');
486 
487  if (dotPos == string::npos)
488  {
489  // Non-scoped lookup
490  return lookupEntryPtr(keyword, recursive, patternMatch);
491  }
492  else
493  {
494  if (dotPos == 0)
495  {
496  // Starting with a '.'. Go up for every 2nd '.' found
497 
498  const dictionary* dictPtr = this;
499 
500  string::size_type begVar = dotPos + 1;
501  string::const_iterator iter = keyword.begin() + begVar;
502  string::size_type endVar = begVar;
503  while
504  (
505  iter != keyword.end()
506  && *iter == '.'
507  )
508  {
509  ++iter;
510  ++endVar;
511 
512  // Go to parent
513  if (&dictPtr->parent_ == &dictionary::null)
514  {
516  (
517  *this
518  ) << "No parent of current dictionary"
519  << " when searching for "
520  << keyword.substr(begVar, keyword.size()-begVar)
521  << exit(FatalIOError);
522  }
523  dictPtr = &dictPtr->parent_;
524  }
525 
526  return dictPtr->lookupScopedEntryPtr
527  (
528  keyword.substr(endVar),
529  false,
530  patternMatch
531  );
532  }
533  else
534  {
535  // Extract the first word
536  word firstWord = keyword.substr(0, dotPos);
537 
538  const entry* entPtr = lookupScopedEntryPtr
539  (
540  firstWord,
541  false, //recursive
542  patternMatch
543  );
544 
545  if (!entPtr)
546  {
548  (
549  *this
550  ) << "keyword " << firstWord
551  << " is undefined in dictionary "
552  << name() << endl
553  << "Valid keywords are " << keys()
554  << exit(FatalIOError);
555  }
556 
557  if (entPtr->isDict())
558  {
559  return entPtr->dict().lookupScopedEntryPtr
560  (
561  keyword.substr(dotPos, keyword.size()-dotPos),
562  false,
563  patternMatch
564  );
565  }
566  else
567  {
568  return NULL;
569  }
570  }
571  }
572  }
573 }
574 
575 
577 {
578  word varName = keyword(1, keyword.size()-1);
579 
580  // lookup the variable name in the given dictionary
581  const entry* ePtr = lookupScopedEntryPtr(varName, true, true);
582 
583  // if defined insert its entries into this dictionary
584  if (ePtr != NULL)
585  {
586  const dictionary& addDict = ePtr->dict();
587 
588  forAllConstIter(IDLList<entry>, addDict, iter)
589  {
590  add(iter());
591  }
592 
593  return true;
594  }
595 
596  return false;
597 }
598 
599 
600 bool Foam::dictionary::isDict(const word& keyword) const
601 {
602  // Find non-recursive with patterns
603  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
604 
605  if (entryPtr)
606  {
607  return entryPtr->isDict();
608  }
609  else
610  {
611  return false;
612  }
613 }
614 
615 
617 {
618  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
619 
620  if (entryPtr)
621  {
622  return &entryPtr->dict();
623  }
624  else
625  {
626  return NULL;
627  }
628 }
629 
630 
631 const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const
632 {
633  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
634 
635  if (entryPtr == NULL)
636  {
638  (
639  *this
640  ) << "keyword " << keyword << " is undefined in dictionary "
641  << name()
642  << exit(FatalIOError);
643  }
644  return entryPtr->dict();
645 }
646 
647 
649 {
650  entry* entryPtr = lookupEntryPtr(keyword, false, true);
651 
652  if (entryPtr == NULL)
653  {
655  (
656  *this
657  ) << "keyword " << keyword << " is undefined in dictionary "
658  << name()
659  << exit(FatalIOError);
660  }
661  return entryPtr->dict();
662 }
663 
664 
666 (
667  const word& keyword,
668  const bool mustRead
669 ) const
670 {
671  const entry* entryPtr = lookupEntryPtr(keyword, false, true);
672 
673  if (entryPtr == NULL)
674  {
675  if (mustRead)
676  {
678  (
679  *this
680  ) << "keyword " << keyword << " is undefined in dictionary "
681  << name()
682  << exit(FatalIOError);
683  return entryPtr->dict();
684  }
685  else
686  {
687  return dictionary(*this, dictionary(name() + '.' + keyword));
688  }
689  }
690  else
691  {
692  return entryPtr->dict();
693  }
694 }
695 
696 
698 {
699  wordList keys(size());
700 
701  label nKeys = 0;
702  forAllConstIter(IDLList<entry>, *this, iter)
703  {
704  keys[nKeys++] = iter().keyword();
705  }
706 
707  return keys;
708 }
709 
710 
712 {
713  List<keyType> keys(size());
714 
715  label nKeys = 0;
716  forAllConstIter(IDLList<entry>, *this, iter)
717  {
718  if (iter().keyword().isPattern() ? patterns : !patterns)
719  {
720  keys[nKeys++] = iter().keyword();
721  }
722  }
723  keys.setSize(nKeys);
724 
725  return keys;
726 }
727 
728 
729 bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry)
730 {
731  HashTable<entry*>::iterator iter = hashedEntries_.find
732  (
733  entryPtr->keyword()
734  );
735 
736  if (mergeEntry && iter != hashedEntries_.end())
737  {
738  // merge dictionary with dictionary
739  if (iter()->isDict() && entryPtr->isDict())
740  {
741  iter()->dict().merge(entryPtr->dict());
742  delete entryPtr;
743 
744  return true;
745  }
746  else
747  {
748  // replace existing dictionary with entry or vice versa
749  IDLList<entry>::replace(iter(), entryPtr);
750  delete iter();
751  hashedEntries_.erase(iter);
752 
753  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
754  {
755  entryPtr->name() = name() + '.' + entryPtr->keyword();
756 
757  if (entryPtr->keyword().isPattern())
758  {
759  patternEntries_.insert(entryPtr);
760  patternRegexps_.insert
761  (
762  autoPtr<regExp>(new regExp(entryPtr->keyword()))
763  );
764  }
765 
766  return true;
767  }
768  else
769  {
770  IOWarningInFunction((*this))
771  << "problem replacing entry "<< entryPtr->keyword()
772  << " in dictionary " << name() << endl;
773 
774  IDLList<entry>::remove(entryPtr);
775  delete entryPtr;
776  return false;
777  }
778  }
779  }
780 
781  if (hashedEntries_.insert(entryPtr->keyword(), entryPtr))
782  {
783  entryPtr->name() = name() + '.' + entryPtr->keyword();
784  IDLList<entry>::append(entryPtr);
785 
786  if (entryPtr->keyword().isPattern())
787  {
788  patternEntries_.insert(entryPtr);
789  patternRegexps_.insert
790  (
791  autoPtr<regExp>(new regExp(entryPtr->keyword()))
792  );
793  }
794 
795  return true;
796  }
797  else
798  {
799  IOWarningInFunction((*this))
800  << "attempt to add entry "<< entryPtr->keyword()
801  << " which already exists in dictionary " << name()
802  << endl;
803 
804  delete entryPtr;
805  return false;
806  }
807 }
808 
809 
810 void Foam::dictionary::add(const entry& e, bool mergeEntry)
811 {
812  add(e.clone(*this).ptr(), mergeEntry);
813 }
814 
815 
816 void Foam::dictionary::add(const keyType& k, const word& w, bool overwrite)
817 {
818  add(new primitiveEntry(k, token(w)), overwrite);
819 }
820 
821 
823 (
824  const keyType& k,
825  const Foam::string& s,
826  bool overwrite
827 )
828 {
829  add(new primitiveEntry(k, token(s)), overwrite);
830 }
831 
832 
833 void Foam::dictionary::add(const keyType& k, const label l, bool overwrite)
834 {
835  add(new primitiveEntry(k, token(l)), overwrite);
836 }
837 
838 
839 void Foam::dictionary::add(const keyType& k, const scalar s, bool overwrite)
840 {
841  add(new primitiveEntry(k, token(s)), overwrite);
842 }
843 
844 
846 (
847  const keyType& k,
848  const dictionary& d,
849  bool mergeEntry
850 )
851 {
852  add(new dictionaryEntry(k, *this, d), mergeEntry);
853 }
854 
855 
857 {
858  entry* existingPtr = lookupEntryPtr(entryPtr->keyword(), false, true);
859 
860  // clear dictionary so merge acts like overwrite
861  if (existingPtr && existingPtr->isDict())
862  {
863  existingPtr->dict().clear();
864  }
865  add(entryPtr, true);
866 }
867 
868 
870 {
871  set(e.clone(*this).ptr());
872 }
873 
874 
876 {
877  set(new dictionaryEntry(k, *this, d));
878 }
879 
880 
881 bool Foam::dictionary::remove(const word& Keyword)
882 {
883  HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword);
884 
885  if (iter != hashedEntries_.end())
886  {
887  // Delete from patterns first
888  DLList<entry*>::iterator wcLink =
889  patternEntries_.begin();
890  DLList<autoPtr<regExp> >::iterator reLink =
891  patternRegexps_.begin();
892 
893  // Find in pattern using exact match only
894  if (findInPatterns(false, Keyword, wcLink, reLink))
895  {
896  patternEntries_.remove(wcLink);
897  patternRegexps_.remove(reLink);
898  }
899 
900  IDLList<entry>::remove(iter());
901  delete iter();
902  hashedEntries_.erase(iter);
903 
904  return true;
905  }
906  else
907  {
908  return false;
909  }
910 }
911 
912 
914 (
915  const keyType& oldKeyword,
916  const keyType& newKeyword,
917  bool forceOverwrite
918 )
919 {
920  // no change
921  if (oldKeyword == newKeyword)
922  {
923  return false;
924  }
925 
926  HashTable<entry*>::iterator iter = hashedEntries_.find(oldKeyword);
927 
928  // oldKeyword not found - do nothing
929  if (iter == hashedEntries_.end())
930  {
931  return false;
932  }
933 
934  if (iter()->keyword().isPattern())
935  {
937  (
938  *this
939  ) << "Old keyword "<< oldKeyword
940  << " is a pattern."
941  << "Pattern replacement not yet implemented."
942  << exit(FatalIOError);
943  }
944 
945 
946  HashTable<entry*>::iterator iter2 = hashedEntries_.find(newKeyword);
947 
948  // newKeyword already exists
949  if (iter2 != hashedEntries_.end())
950  {
951  if (forceOverwrite)
952  {
953  if (iter2()->keyword().isPattern())
954  {
955  // Delete from patterns first
956  DLList<entry*>::iterator wcLink =
957  patternEntries_.begin();
958  DLList<autoPtr<regExp> >::iterator reLink =
959  patternRegexps_.begin();
960 
961  // Find in patterns using exact match only
962  if (findInPatterns(false, iter2()->keyword(), wcLink, reLink))
963  {
964  patternEntries_.remove(wcLink);
965  patternRegexps_.remove(reLink);
966  }
967  }
968 
969  IDLList<entry>::replace(iter2(), iter());
970  delete iter2();
971  hashedEntries_.erase(iter2);
972 
973  }
974  else
975  {
977  (
978  *this
979  ) << "cannot rename keyword "<< oldKeyword
980  << " to existing keyword " << newKeyword
981  << " in dictionary " << name() << endl;
982  return false;
983  }
984  }
985 
986  // change name and HashTable, but leave DL-List untouched
987  iter()->keyword() = newKeyword;
988  iter()->name() = name() + '.' + newKeyword;
989  hashedEntries_.erase(oldKeyword);
990  hashedEntries_.insert(newKeyword, iter());
991 
992  if (newKeyword.isPattern())
993  {
994  patternEntries_.insert(iter());
995  patternRegexps_.insert
996  (
997  autoPtr<regExp>(new regExp(newKeyword))
998  );
999  }
1000 
1001  return true;
1002 }
1003 
1004 
1006 {
1007  // Check for assignment to self
1008  if (this == &dict)
1009  {
1010  FatalIOErrorInFunction(*this)
1011  << "attempted merge to self for dictionary " << name()
1012  << abort(FatalIOError);
1013  }
1014 
1015  bool changed = false;
1016 
1018  {
1019  HashTable<entry*>::iterator fnd = hashedEntries_.find(iter().keyword());
1020 
1021  if (fnd != hashedEntries_.end())
1022  {
1023  // Recursively merge sub-dictionaries
1024  // TODO: merge without copying
1025  if (fnd()->isDict() && iter().isDict())
1026  {
1027  if (fnd()->dict().merge(iter().dict()))
1028  {
1029  changed = true;
1030  }
1031  }
1032  else
1033  {
1034  add(iter().clone(*this).ptr(), true);
1035  changed = true;
1036  }
1037  }
1038  else
1039  {
1040  // not found - just add
1041  add(iter().clone(*this).ptr());
1042  changed = true;
1043  }
1044  }
1045 
1046  return changed;
1047 }
1048 
1049 
1051 {
1053  hashedEntries_.clear();
1054  patternEntries_.clear();
1055  patternRegexps_.clear();
1056 }
1057 
1058 
1060 {
1061  // changing parents probably doesn't make much sense,
1062  // but what about the names?
1063  name() = dict.name();
1064 
1066  hashedEntries_.transfer(dict.hashedEntries_);
1067  patternEntries_.transfer(dict.patternEntries_);
1068  patternRegexps_.transfer(dict.patternRegexps_);
1069 }
1070 
1071 
1073 {
1074  return xferMove(*this);
1075 }
1076 
1077 
1078 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
1079 
1081 {
1082  return lookup(keyword);
1083 }
1084 
1085 
1087 {
1088  // Check for assignment to self
1089  if (this == &rhs)
1090  {
1091  FatalIOErrorInFunction(*this)
1092  << "attempted assignment to self for dictionary " << name()
1093  << abort(FatalIOError);
1094  }
1095 
1096  name() = rhs.name();
1097  clear();
1098 
1099  // Create clones of the entries in the given dictionary
1100  // resetting the parentDict to this dictionary
1101 
1102  forAllConstIter(IDLList<entry>, rhs, iter)
1103  {
1104  add(iter().clone(*this).ptr());
1105  }
1106 }
1107 
1108 
1110 {
1111  // Check for assignment to self
1112  if (this == &rhs)
1113  {
1114  FatalIOErrorInFunction(*this)
1115  << "attempted addition assignment to self for dictionary " << name()
1116  << abort(FatalIOError);
1117  }
1118 
1119  forAllConstIter(IDLList<entry>, rhs, iter)
1120  {
1121  add(iter().clone(*this).ptr());
1122  }
1123 }
1124 
1125 
1127 {
1128  // Check for assignment to self
1129  if (this == &rhs)
1130  {
1131  FatalIOErrorInFunction(*this)
1132  << "attempted assignment to self for dictionary " << name()
1133  << abort(FatalIOError);
1134  }
1135 
1136  forAllConstIter(IDLList<entry>, rhs, iter)
1137  {
1138  if (!found(iter().keyword()))
1139  {
1140  add(iter().clone(*this).ptr());
1141  }
1142  }
1143 }
1144 
1145 
1147 {
1148  // Check for assignment to self
1149  if (this == &rhs)
1150  {
1151  FatalIOErrorInFunction(*this)
1152  << "attempted assignment to self for dictionary " << name()
1153  << abort(FatalIOError);
1154  }
1155 
1156  forAllConstIter(IDLList<entry>, rhs, iter)
1157  {
1158  set(iter().clone(*this).ptr());
1159  }
1160 }
1161 
1162 
1163 /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
1164 
1165 Foam::dictionary Foam::operator+
1167  const dictionary& dict1,
1168  const dictionary& dict2
1169 )
1170 {
1171  dictionary sum(dict1);
1172  sum += dict2;
1173  return sum;
1174 }
1175 
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::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::dictionary::parent_
const dictionary & parent_
Parent dictionary.
Definition: dictionary.H:152
Foam::dictionaryEntry
A keyword and a list of tokens is a 'dictionaryEntry'.
Definition: dictionaryEntry.H:57
Foam::dictionary::lookupEntry
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
Definition: dictionary.C:426
Foam::DynamicList::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container as a plain List.
Definition: DynamicListI.H:301
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::primitiveEntry
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
Definition: primitiveEntry.H:62
p
p
Definition: pEqn.H:62
primitiveEntry.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::HashTable::iterator
An STL-conforming iterator.
Definition: HashTable.H:415
Foam::entry::keyword
const keyType & keyword() const
Return keyword.
Definition: entry.H:120
Foam::DLList
Non-intrusive doubly-linked list.
Definition: DLList.H:47
clear
UEqn clear()
Foam::dictionary::operator[]
ITstream & operator[](const word &) const
Find and return entry.
Definition: dictionary.C:1080
Foam::dictionaryName::name
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:103
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::keyType::isPattern
bool isPattern() const
Should be treated as a match rather than a literal string.
Definition: keyTypeI.H:76
Foam::dictionary::dictionary
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:113
Foam::debug::infoSwitch
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
Definition: debug.C:173
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition: HashTable.H:470
Foam::dictionary::operator<<=
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
Definition: dictionary.C:1146
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::dictionary::remove
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:881
Foam::FatalIOError
IOerror FatalIOError
Foam::dictionary::operator=
void operator=(const dictionary &)
Definition: dictionary.C:1086
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::token
A token holds items read from Istream.
Definition: token.H:67
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::dictionary::isDict
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:600
Foam::OStringStream::str
string str() const
Return the string.
Definition: OStringStream.H:107
Foam::regExp
Wrapper around POSIX extended regular expressions.
Definition: regExp.H:61
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::LList< DLListBase, T >::end
const iterator & end()
Definition: LList.H:273
Foam::ILList< DLListBase, T >::transfer
void transfer(ILList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: ILList.C:125
Foam::dictionary::keys
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
Definition: dictionary.C:711
Foam::dictionary::changeKeyword
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
Definition: dictionary.C:914
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
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:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::IDLList< entry >
Foam::entry::isDict
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
Foam::ITstream
Input token stream.
Definition: ITstream.H:49
Foam::dictionary::hashedEntries_
HashTable< entry * > hashedEntries_
HashTable of the entries held on the DL-list for quick lookup.
Definition: dictionary.H:149
Foam::LList< DLListBase, T >::begin
iterator begin()
Definition: LList.H:268
Foam::dictionary::~dictionary
virtual ~dictionary()
Destructor.
Definition: dictionary.C:223
Foam::dictionary::startLineNumber
label startLineNumber() const
Return line number of first token in dictionary.
Definition: dictionary.C:244
Foam::dictionary::endLineNumber
label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:257
Foam::dictionary::merge
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1005
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Foam::ILList< DLListBase, T >::clear
void clear()
Clear the contents of the list.
Definition: ILList.C:112
Foam::dictionary::topDict
const dictionary & topDict() const
Return the top of the tree.
Definition: dictionary.C:229
Foam::OSHA1stream
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:133
Foam::dictionary::lookupScopedEntryPtr
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:460
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::dictionary::patternRegexps_
DLList< autoPtr< regExp > > patternRegexps_
Patterns as precompiled regular expressions.
Definition: dictionary.H:158
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:870
Foam::dictionary::patternEntries_
DLList< entry * > patternEntries_
Entries of matching patterns.
Definition: dictionary.H:155
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
dictionaryEntry.H
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:62
Foam::entry::name
virtual const fileName & name() const =0
Return the dictionary name.
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::dictionary::substituteScopedKeyword
bool substituteScopedKeyword(const word &keyword)
Substitute the given scoped keyword prepended by '$' with the.
Definition: dictionary.C:576
Foam::tokenList
List< token > tokenList
List of tokens, used for a IOdictionary entry.
Definition: tokenList.H:43
Foam::dictionary::writeOptionalEntries
static bool writeOptionalEntries
If true write optional keywords and values.
Definition: dictionary.H:146
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::dictionary::operator+=
void operator+=(const dictionary &)
Include entries from the given dictionary.
Definition: dictionary.C:1109
Foam::dictionary::operator|=
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
Definition: dictionary.C:1126
Foam::dictionary::lookupEntryPtr
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:343
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::ISstream::read
virtual Istream & read(token &)
Return next token from stream.
Definition: ISstream.C:132
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:59
Foam::OStringStream
Output to memory buffer stream.
Definition: OStringStream.H:49
Foam::dictionary::transfer
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
Definition: dictionary.C:1059
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::dictionary::clone
autoPtr< dictionary > clone() const
Construct and return clone.
Definition: dictionary.C:215
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:666
dictionary.H
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
OSHA1stream.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
DynamicList.H
Foam::dictionary::tokens
tokenList tokens() const
Return the dictionary as a list of tokens.
Definition: dictionary.C:284
regExp.H
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:697
Foam::dictionary::digest
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:270
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:271
Foam::OSHA1stream::digest
Foam::SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:185
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dictionary::clear
void clear()
Clear the dictionary.
Definition: dictionary.C:1050
Foam::dictionaryName
Definition: dictionary.H:78
write
Tcoeff write()
merge
bool merge(dictionary &, const dictionary &, const bool, const HashTable< wordList, word > &)
Definition: changeDictionary.C:222
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::dictionary::xfer
Xfer< dictionary > xfer()
Transfer contents to the Xfer container.
Definition: dictionary.C:1072
Foam::dictionary::findInPatterns
bool findInPatterns(const bool patternMatch, const word &Keyword, DLList< entry * >::const_iterator &wcLink, DLList< autoPtr< regExp > >::const_iterator &reLink) const
Search patterns table for exact match or regular expression match.
Definition: dictionary.C:50
Foam::dictionary::null
static const dictionary null
Null dictionary.
Definition: dictionary.H:193
Foam::dictionary::subDictPtr
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:616
Foam::dictionary::add
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:729
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress
Foam::dictionary::set
void set(entry *)
Assign a new entry, overwrite any existing entry.
Definition: dictionary.C:856