dictionaryIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 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 "IOobject.H"
28 #include "HashSet.H"
29 #include "inputModeEntry.H"
30 #include "calcIncludeEntry.H"
31 #include "stringOps.H"
32 #include "etcFiles.H"
33 #include "wordAndDictionary.H"
34 #include "OSspecific.H"
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const fileName& name,
41  const dictionary& parentDict,
42  Istream& is
43 )
44 :
46  (
47  parentDict.name().size()
48  ? parentDict.name()/name
49  : name
50  ),
51  parent_(parentDict),
52  filePtr_(nullptr)
53 {
54  read(is);
55 }
56 
57 
58 Foam::dictionary::dictionary(Istream& is, const bool keepHeader)
59 :
60  dictionaryName(is.name()),
61  parent_(dictionary::null),
62  filePtr_(nullptr)
63 {
64  // Reset input mode as this is a "top-level" dictionary
66 
67  // Clear the cache of #calc include files
69 
70  read(is, keepHeader);
71 }
72 
73 
75 (
76  const fileName& fName,
77  const dictionary& parentDict
78 )
79 :
80  dictionary(fName),
81  global_(parentDict.topDict().global())
82 {
83  autoPtr<ISstream> ifsPtr
84  (
85  fileHandler().NewIFstream(fName)
86  );
87  ISstream& ifs = ifsPtr();
88 
89  if (!ifs || !ifs.good())
90  {
91  FatalIOErrorInFunction(parentDict)
92  << "Included dictionary file " << fName
93  << " cannot be found for dictionary " << parentDict.name()
94  << exit(FatalIOError);
95  }
96 
97  read(ifs);
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
102 
104 {
105  return autoPtr<dictionary>(new dictionary(is));
106 }
107 
108 
109 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
110 
111 bool Foam::dictionary::read(Istream& is, const bool keepHeader)
112 {
113  // Check for empty dictionary
114  if (is.eof())
115  {
116  return true;
117  }
118 
119  if (!is.good())
120  {
122  << "Istream not OK for reading dictionary "
123  << exit(FatalIOError);
124 
125  return false;
126  }
127 
128  // Cache the current name and file/stream pointer
129  const fileName name0(name());
130  const Istream* filePtr0 = filePtr_;
131 
132  // Set the name and file/stream pointer to the given stream
133  name() = is.name();
134  filePtr_ = &is;
135 
136  token currToken(is);
137  if (currToken != token::BEGIN_BLOCK)
138  {
139  is.putBack(currToken);
140  }
141 
142  while (!is.eof() && entry::New(*this, is))
143  {}
144 
145  // normally remove the FoamFile header entry if it exists
146  if (!keepHeader)
147  {
149  }
150 
151  if (is.bad())
152  {
154  << "Istream not OK after reading dictionary " << name()
155  << endl;
156 
157  return false;
158  }
159 
160  // Reset the name and file/stream pointer to the original
161  name() = name0;
162  filePtr_ = filePtr0;
163 
164  return true;
165 }
166 
167 
169 {
170  if (&parent_ != &dictionary::null)
171  {
172  return parent_.global();
173  }
174  else
175  {
176  return false;
177  }
178 }
179 
180 
182 {
183  word varName = keyword(1, keyword.size()-1);
184 
185  // lookup the variable name in the given dictionary
186  const entry* ePtr = lookupEntryPtr(varName, true, true);
187 
188  // if defined insert its entries into this dictionary
189  if (ePtr != nullptr)
190  {
191  const dictionary& addDict = ePtr->dict();
192 
193  forAllConstIter(IDLList<entry>, addDict, iter)
194  {
195  add(iter());
196  }
197 
198  return true;
199  }
200 
201  return false;
202 }
203 
204 
205 
206 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
207 
209 {
210  // Reset input mode assuming this is a "top-level" dictionary
212 
213  // Clear the cache of #calc include files
215 
216  dict.clear();
217  dict.name() = is.name();
218  dict.read(is);
219 
220  return is;
221 }
222 
223 
224 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
225 
227 {
228  if (subDict)
229  {
230  os << nl << indent << token::BEGIN_BLOCK << incrIndent << nl;
231  }
232 
233  forAllConstIter(IDLList<entry>, *this, iter)
234  {
235  const entry& e = *iter;
236 
237  // Write entry
238  os << e;
239 
240  // Add extra new line between entries for "top-level" dictionaries
241  if (!subDict && parent() == dictionary::null && (&e != last()))
242  {
243  os << nl;
244  }
245 
246  // Check stream before going to next entry.
247  if (!os.good())
248  {
250  << "Can't write entry " << iter().keyword()
251  << " for dictionary " << name()
252  << endl;
253  }
254  }
255 
256  if (subDict)
257  {
258  os << decrIndent << indent << token::END_BLOCK << endl;
259  }
260 }
261 
262 
264 {
265  dict.write(os, true);
266  return os;
267 }
268 
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 namespace Foam
273 {
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
278 unsetConfigEntries(const dictionary& configDict)
279 {
280  const wordRe unsetPattern("<.*>");
281  unsetPattern.compile();
282 
283  List<Tuple2<word, string>> unsetArgs;
284 
285  forAllConstIter(IDLList<entry>, configDict, iter)
286  {
287  if (iter().isStream())
288  {
289  ITstream& its = iter().stream();
290  OStringStream oss;
291  bool isUnset = false;
292 
293  forAll(its, i)
294  {
295  oss << its[i];
296  if (its[i].isWord() && unsetPattern.match(its[i].wordToken()))
297  {
298  isUnset = true;
299  }
300  }
301 
302  if (isUnset)
303  {
304  unsetArgs.append
305  (
307  (
308  iter().keyword(),
309  oss.str()
310  )
311  );
312  }
313  }
314  else
315  {
316  List<Tuple2<word, string>> subUnsetArgs =
317  unsetConfigEntries(iter().dict());
318 
319  forAll(subUnsetArgs, i)
320  {
321  unsetArgs.append
322  (
324  (
325  iter().keyword() + '/' + subUnsetArgs[i].first(),
326  subUnsetArgs[i].second()
327  )
328  );
329  }
330  }
331  }
332 
333  return unsetArgs;
334 }
335 
336 
338 (
339  const fileName& dir,
340  HashSet<word>& foMap
341 )
342 {
343  // Search specified directory for configuration files
344  {
345  fileNameList foFiles(fileHandler().readDir(dir));
346  forAll(foFiles, f)
347  {
348  if (foFiles[f].ext().empty())
349  {
350  foMap.insert(foFiles[f]);
351  }
352  }
353  }
354 
355  // Recurse into sub-directories
356  {
358  forAll(foDirs, fd)
359  {
360  listConfigFiles(dir/foDirs[fd], foMap);
361  }
362  }
363 }
364 
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 } // End namespace Foam
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
373 (
374  const word& configName,
375  const fileName& configFilesPath,
376  const word& configFilesDir,
377  const word& region
378 )
379 {
380  // First check if there is a configuration file in the
381  // region configFilesDir directory
382  {
383  const fileName dictFile
384  (
385  stringOps::expandEnvVar("$FOAM_CASE")
386  /configFilesDir/region/configName
387  );
388 
389  if (isFile(dictFile))
390  {
391  return dictFile;
392  }
393  }
394 
395  // Next, if the region is specified, check if there is a configuration file
396  // in the global configFilesDir directory
397  if (region != word::null)
398  {
399  const fileName dictFile
400  (
401  stringOps::expandEnvVar("$FOAM_CASE")/configFilesDir/configName
402  );
403 
404  if (isFile(dictFile))
405  {
406  return dictFile;
407  }
408  }
409 
410  // Finally, check etc directories
411  {
412  const fileNameList etcDirs(findEtcDirs(configFilesPath));
413 
414  forAll(etcDirs, i)
415  {
416  const fileName dictFile(search(configName, etcDirs[i]));
417 
418  if (!dictFile.empty())
419  {
420  return dictFile;
421  }
422  }
423  }
424 
425  return fileName::null;
426 }
427 
428 
430 (
431  const fileName& configFilesPath
432 )
433 {
434  HashSet<word> foMap;
435 
436  fileNameList etcDirs(findEtcDirs(configFilesPath));
437 
438  forAll(etcDirs, ed)
439  {
440  listConfigFiles(etcDirs[ed], foMap);
441  }
442 
443  return foMap.sortedToc();
444 }
445 
446 
448 (
449  const string& arg,
450  dictionary& dict,
451  const label lineNumber
452 )
453 {
454  // Add a temporary dummy_ entry to set the arg lineNumber in dict
455  dict.set(primitiveEntry("dummy_", token(word("<dummy>"), lineNumber)));
456 
457  string expandedArg(arg);
458  stringOps::inplaceExpandEntry(expandedArg, dict, true, false);
459 
460  // Remove temporary dummy_ entry
461  dict.remove("dummy_");
462 
463  return expandedArg;
464 }
465 
466 
468 (
469  dictionary& dict,
470  const word& keyword,
471  const string& value,
472  const label lineNumber
473 )
474 {
475  IStringStream entryStream(dict.name(), keyword + ' ' + value + ';');
476  entryStream.lineNumber() = lineNumber;
477  autoPtr<entry> argEntry(entry::New(entryStream));
478  if (argEntry.valid())
479  {
480  dict.set(argEntry.ptr());
481  }
482  else
483  {
485  << "Cannot construct argument entry from string "
486  << entryStream.str() << nl
487  << " on line " << lineNumber << " of dictionary " << dict.name()
488  << exit(FatalIOError);
489  }
490 }
491 
492 
494 (
495  const word& configType,
496  const Tuple2<string, label>& argStringLine,
497  dictionary& parentDict,
498  const fileName& configFilesPath,
499  const word& configFilesDir,
500  const word& region
501 )
502 {
503  word funcType;
506 
507  dictArgList(argStringLine, funcType, args, namedArgs);
508 
509  // Search for the configuration file
510  fileName path = findConfigFile
511  (
512  funcType,
513  configFilesPath,
514  configFilesDir,
515  region
516  );
517 
518  if (path == fileName::null)
519  {
520  if (funcType == word::null)
521  {
522  FatalIOErrorInFunction(parentDict)
523  << "configuration file name not specified"
524  << nl << nl
525  << "Available configured objects:"
526  << listAllConfigFiles(configFilesPath)
527  << exit(FatalIOError);
528  }
529  else
530  {
531  FatalIOErrorInFunction(parentDict)
532  << "Cannot find configuration file "
533  << funcType << nl << nl
534  << "Available configured objects:"
535  << listAllConfigFiles(configFilesPath)
536  << exit(FatalIOError);
537  }
538 
539  return false;
540  }
541 
542  // Read the configuration file
543  autoPtr<ISstream> fileStreamPtr(fileHandler().NewIFstream(path));
544  ISstream& fileStream = fileStreamPtr();
545 
546  // Delay processing the functionEntries
547  // until after the argument entries have been added
549  dictionary funcDict(fileName(funcType), parentDict, fileStream);
551 
552  // Store the funcDict as read for error reporting context
553  const dictionary funcDict0(funcDict);
554 
555  // Insert the 'field' and/or 'fields' and 'objects' entries corresponding
556  // to both the arguments and the named arguments
558  forAll(args, i)
559  {
560  fieldArgs.append
561  (
563  (
564  expandArg(args[i].first(), funcDict, args[i].second()),
566  )
567  );
568  }
569  forAll(namedArgs, i)
570  {
571  if (namedArgs[i].first() == "field")
572  {
573  IStringStream iss(namedArgs[i].second());
574  fieldArgs.append(wordAndDictionary(iss));
575  }
576  if
577  (
578  namedArgs[i].first() == "fields"
579  || namedArgs[i].first() == "objects"
580  )
581  {
582  IStringStream iss(namedArgs[i].second());
583  fieldArgs.append(List<wordAndDictionary>(iss));
584  }
585  }
586  if (fieldArgs.size() == 1)
587  {
588  funcDict.set("field", fieldArgs[0].first());
589  funcDict.merge(fieldArgs[0].second());
590  }
591  if (fieldArgs.size() >= 1)
592  {
593  funcDict.set("fields", fieldArgs);
594  funcDict.set("objects", fieldArgs);
595  }
596 
597  // Insert non-field arguments
598  forAll(namedArgs, i)
599  {
600  if
601  (
602  namedArgs[i].first() != "field"
603  && namedArgs[i].first() != "fields"
604  && namedArgs[i].first() != "objects"
605  && namedArgs[i].first() != "funcName"
606  && namedArgs[i].first() != "name"
607  )
608  {
609  const Pair<word> dAk(dictAndKeyword(namedArgs[i].first()));
610  dictionary& subDict(funcDict.scopedDict(dAk.first()));
612  (
613  subDict,
614  dAk.second(),
615  expandArg
616  (
617  namedArgs[i].second(),
618  funcDict,
619  namedArgs[i].third()
620  ),
621  namedArgs[i].third()
622  );
623  }
624  }
625 
626  // Insert the region name if specified
627  if (region != word::null)
628  {
629  funcDict.set("region", region);
630  }
631 
632  // Set the name of the entry to that specified by the optional
633  // name argument otherwise automatically generate a unique name
634  // from the type and arguments
635  word entryName(funcType);
636  if (args.size() || namedArgs.size())
637  {
638  bool named = false;
639  forAll(namedArgs, i)
640  {
641  if
642  (
643  namedArgs[i].first() == "funcName"
644  || namedArgs[i].first() == "name"
645  )
646  {
647  entryName = expandArg
648  (
649  namedArgs[i].second(),
650  funcDict,
651  namedArgs[i].third()
652  );
653  entryName.strip(" \n");
654  named = true;
655  }
656  }
657 
658  if (!named)
659  {
660  entryName += '(';
661  forAll(args, i)
662  {
663  if (i > 0)
664  {
665  entryName += ',';
666  }
667  entryName += args[i].first();
668  }
669  forAll(namedArgs, i)
670  {
671  if (args.size() || i > 0)
672  {
673  entryName += ',';
674  }
675  entryName += namedArgs[i].first();
676  entryName += '=';
677  entryName += expandArg
678  (
679  namedArgs[i].second(),
680  funcDict,
681  namedArgs[i].third()
682  );
683  }
684  entryName += ')';
685  string::stripInvalid<word>(entryName);
686  }
687  }
688 
689  // Check for anything in the configuration that has not been set
690  List<Tuple2<word, string>> unsetArgs = unsetConfigEntries(funcDict);
691  bool hasUnsetError = false;
692  forAll(unsetArgs, i)
693  {
694  if
695  (
696  unsetArgs[i].first() != "fields"
697  && unsetArgs[i].first() != "objects"
698  )
699  {
700  hasUnsetError = true;
701  }
702  }
703  if (!hasUnsetError)
704  {
705  forAll(unsetArgs, i)
706  {
707  funcDict.set(unsetArgs[i].first(), wordList());
708  }
709  }
710  else
711  {
712  FatalIOErrorInFunction(funcDict0)
713  << nl;
714 
715  forAll(unsetArgs, i)
716  {
717  FatalIOErrorInFunction(funcDict0)
718  << "Essential value for keyword '" << unsetArgs[i].first()
719  << "' not set" << nl;
720  }
721 
722  FatalIOErrorInFunction(funcDict0)
723  << nl << "in " << configType << " entry:" << nl
724  << argStringLine.first().c_str() << nl
725  << nl << "in dictionary " << parentDict.name().c_str()
726  << " starting at line " << argStringLine.second() << nl;
727 
728  word funcType;
731  dictArgList(argStringLine, funcType, args, namedArgs);
732 
733  string argList;
734  forAll(args, i)
735  {
736  args[i].first().strip(" \n");
737  argList += (argList.size() ? ", " : "") + args[i].first();
738  }
739  forAll(namedArgs, i)
740  {
741  namedArgs[i].second().strip(" \n");
742  argList +=
743  (argList.size() ? ", " : "")
744  + namedArgs[i].first() + " = " + namedArgs[i].second();
745  }
746  forAll(unsetArgs, i)
747  {
748  unsetArgs[i].second().strip(" \n");
749  argList +=
750  (argList.size() ? ", " : "")
751  + unsetArgs[i].first() + " = " + unsetArgs[i].second();
752  }
753 
754  FatalIOErrorInFunction(funcDict0)
755  << nl << "The " << configType << " entry should be:" << nl
756  << " " << funcType << '(' << argList.c_str() << ')'
757  << exit(FatalIOError);
758  }
759 
760  // Re-parse the funcDict to execute the functionEntries
761  // now that the argument entries have been added
762  dictionary funcArgsDict;
763  funcArgsDict.add(entryName, funcDict);
764 
765  {
766  OStringStream os;
767  funcArgsDict.write(os);
768  funcArgsDict = dictionary
769  (
770  funcType,
771  funcDict,
772  IStringStream(os.str())()
773  );
774  }
775 
776  // Merge this configuration dictionary into parentDict
777  parentDict.merge(funcArgsDict);
778  parentDict.subDict(entryName).name() = funcDict.name();
779 
780  return true;
781 }
782 
783 
784 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
785 
786 void Foam::writeEntry(Ostream& os, const dictionary& value)
787 {
788  os << value;
789 }
790 
791 
792 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
A HashTable with keys but without contents.
Definition: HashSet.H:62
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:242
Template class for intrusive linked lists.
Definition: ILList.H:67
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
Definition: IOobject.H:104
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:450
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
bool bad() const
Return true if stream is corrupted.
Definition: IOstream.H:351
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
Generic input stream.
Definition: ISstream.H:55
Input from memory buffer stream.
Definition: IStringStream.H:52
string str() const
Return the string.
Input token stream.
Definition: ITstream.H:53
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void putBack(const token &)
Put back token.
Definition: Istream.C:30
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const Type & second() const
Return second.
Definition: PairI.H:121
const Type & first() const
Return first.
Definition: PairI.H:107
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
const Type2 & second() const
Return second.
Definition: Tuple2.H:131
const Type1 & first() const
Return first.
Definition: Tuple2.H:119
T * last()
Return the last entry.
Definition: UILList.H:121
T * first()
Return the first entry.
Definition: UILList.H:109
T & first()
Return the first element of the list.
Definition: UListI.H:114
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
label size() const
Return the number of arguments.
Definition: argListI.H:90
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
T * ptr()
Return object pointer for reuse.
Definition: autoPtrI.H:90
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
includedDictionary(const fileName &fName, const dictionary &parentDict)
Construct an included dictionary for the given parent.
Definition: dictionaryIO.C:75
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
dictionary()
Construct top-level dictionary null.
Definition: dictionary.C:327
virtual bool global() const
Return true if the dictionary global,.
Definition: dictionaryIO.C:168
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Definition: dictionaryIO.C:111
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:578
bool substituteKeyword(const word &keyword)
Substitute the given keyword prepended by '$' with the.
Definition: dictionaryIO.C:181
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:226
bool remove(const word &)
Remove an entry specified by keyword.
Definition: dictionary.C:1183
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:364
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:849
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1020
const dictionary & scopedDict(const word &) const
Find and return a sub-dictionary by scoped lookup.
Definition: dictionary.C:944
static const dictionary null
Null dictionary.
Definition: dictionary.H:273
static autoPtr< dictionary > New(Istream &)
Construct top-level dictionary on freestore from Istream.
Definition: dictionaryIO.C:103
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1314
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:68
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
Definition: entryIO.C:103
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
static int disableFunctionEntries
Definition: entry.H:102
A class for handling file names.
Definition: fileName.H:82
static const fileName null
An empty fileName.
Definition: fileName.H:97
static void clear()
Reset the cache of #calc include file names.
static void clear()
Reset the inputMode to default (ie, merge)
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling character strings derived from std::string.
Definition: string.H:79
void strip(const string &)
Strip characters from the start and end of the string.
Definition: string.C:265
A token holds items read from Istream.
Definition: token.H:73
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
Tuple of a word and dictionary, used to read in per-field options for function objects in the followi...
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
bool compile() const
Compile the regular expression.
Definition: wordReI.H:161
bool match(const std::string &, bool literalMatch=false) const
Smart match as regular expression or as a string.
Definition: wordReI.H:202
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
Functions to search 'etc' directories for configuration files etc.
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
string expandEnvVar(const string &, const bool allowEmpty=false)
Expand all occurrences of environment variables and paths.
Definition: stringOps.C:241
string & inplaceExpandEntry(string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
Inplace expand occurrences of variables according to the dictionary.
Definition: stringOps.C:760
Namespace for OpenFOAM.
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
Definition: POSIX.C:555
const fileOperation & fileHandler()
Get current file handler.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
const doubleScalar e
Definition: doubleScalar.H:106
fileName findConfigFile(const word &configName, const fileName &configFilesPath, const word &configFilesDir, const word &region=word::null)
Search for configuration file for given region.
Definition: dictionaryIO.C:373
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:242
void dictArgList(const Tuple2< string, label > &argString, word &configName, List< Tuple2< wordRe, label >> &args, List< Tuple3< word, string, label >> &namedArgs)
Parse dictionary substitution argument list.
Definition: dictionary.C:1495
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
void listConfigFiles(const fileName &dir, HashSet< word > &foMap)
Definition: dictionaryIO.C:338
wordList listAllConfigFiles(const fileName &configFilesPath)
Return the list of configuration files in.
Definition: dictionaryIO.C:430
labelList second(const UList< labelPair > &p)
Definition: patchToPatch.C:49
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:235
bool readConfigFile(const word &configType, const Tuple2< string, label > &argString, dictionary &parentDict, const fileName &configFilesPath, const word &configFilesDir, const word &region=word::null)
Read the specified configuration file.
Definition: dictionaryIO.C:494
Pair< word > dictAndKeyword(const word &scopedName)
Extracts dict name and keyword.
Definition: dictionary.C:1684
void addArgEntry(dictionary &dict, const word &keyword, const string &value, const label lineNumber)
Add the keyword value pair to dict.
Definition: dictionaryIO.C:468
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, pistonPointEdgeData &)
Foam::List< Foam::Tuple2< Foam::word, Foam::string > > unsetConfigEntries(const dictionary &configDict)
Definition: dictionaryIO.C:278
IOerror FatalIOError
fileNameList findEtcDirs(const fileName &local=fileName::null)
Search for directories from user/group/shipped directories.
Definition: etcFiles.C:32
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:228
static const char nl
Definition: Ostream.H:267
fileNameList readDir(const fileName &, const fileType=fileType::file, const bool filterVariants=true, const bool followLink=true)
Read a directory and return the entries as a string list.
Definition: POSIX.C:662
string expandArg(const string &arg, dictionary &dict, const label lineNumber)
Expand arg within the dict context and return.
Definition: dictionaryIO.C:448
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
labelList f(nPoints)
dictionary dict
Foam::argList args(argc, argv)