156 using namespace Foam;
169 if (!dictFile().good())
172 <<
"Cannot open file " << dictFileName
179 dictFile.read(firstToken);
182 dictFile.putBack(firstToken);
197 firstEntry->dict().lookup(
"format")
203 IFstream dictFile(dictFileName, dictFormat);
207 dict.
read(dictFile(),
true);
219 && entryName.find(
'/') != string::npos
225 for (
label i = 1; i < entryNames.size(); i++)
242 entry* entPtr = dict.lookupEntryPtr
255 remove(entPtr->
dict(), iter().dict());
258 if (!entPtr->
dict().size())
260 dict.remove(iter().keyword());
264 else if (!iter().isDict())
266 if (*entPtr == iter())
268 dict.remove(iter().keyword());
276 void substitute(
dictionary& dict,
string substitutions)
288 dAk.second() +
' ' + namedArgs[i].second() +
';' 295 int main(
int argc,
char *argv[])
315 "Set entry value, add new entry or apply list of substitutions" 332 "Set, add or merge entry from a dictionary." 343 "Write differences with respect to the specified dictionary" 348 "List the #include/#includeIfPresent files to standard output" 353 "Read the specified dictionary file, expand the macros etc. and write " 354 "the resulting dictionary to standard output" 360 "Write with the specified precision" 365 const bool listIncludes = args.optionFound(
"includes");
374 if (!args.optionFound(
"expand"))
380 if (args.optionFound(
"writePrecision"))
382 const label writePrecision = args.optionRead<
label>(
"writePrecision");
390 Time* runTimePtr =
nullptr;
400 if (!args.checkRootCase())
407 const wordList dictPathComponents(dictPath.components());
409 if (dictPathComponents.size() == 1)
412 <<
"File name " << dictPath
413 <<
" does not contain an instance path needed in parallel" 417 const word instance = dictPathComponents[0];
420 SubList<word>(dictPathComponents, dictPathComponents.size() - 1, 1)
445 dictFormat = readDict(*dictPtr, dictPath);
448 dictionary& dict = localDictPtr ? *localDictPtr : *dictPtr;
450 bool changed =
false;
456 else if (args.optionFound(
"expand") && !args.optionFound(
"entry"))
459 <<
"//\n// " << dictPath <<
"\n//\n";
462 if (dict.
found(IOobject::foamFile))
472 dict.dictionary::write(
Info,
false);
483 if (args.optionReadIfPresent(
"diff", diffFileName))
485 readDict(diffDict, diffFileName);
489 if (args.optionReadIfPresent(
"entry", entryName))
491 const word scopedName(dotToSlash(entryName));
496 args.optionReadIfPresent(
"set", newValue)
497 || args.optionReadIfPresent(
"add", newValue)
498 || args.optionReadIfPresent(
"merge", newValue)
501 const bool overwrite = args.optionFound(
"set");
502 const bool merge = args.optionFound(
"merge");
507 entry* ePtr =
nullptr;
509 if (args.optionFound(
"dict"))
511 const fileName fromDictFileName(newValue);
513 readDict(fromDict, fromDictFileName);
528 <<
"Cannot find entry " << entryName
529 <<
" in file " << fromDictFileName
533 ePtr = fePtr->
clone().ptr();
537 IStringStream str(
string(dAk.second()) +
' ' + newValue +
';');
543 Info <<
"New entry " << *ePtr <<
endl;
548 subDict.add(ePtr, merge);
552 else if (args.optionFound(
"remove"))
558 subDict.remove(dAk.second());
564 if (args.optionFound(
"diff"))
572 subDict.lookupEntryPtr(dAk.second(),
false,
true);
574 subDict2.lookupEntryPtr(dAk.second(),
false,
true);
580 subDict.remove(dAk.second());
584 remove(ePtr->
dict(), e2Ptr->
dict());
599 if (args.optionFound(
"keywords"))
609 if (args.optionFound(
"value"))
617 if (i < tokens.size() - 1)
624 else if (entPtr->
isDict())
638 <<
"Cannot find entry " << entryName
643 else if (args.optionFound(
"set"))
645 const string substitutions(args.optionRead<
string>(
"set"));
646 substitute(dict, substitutions);
649 else if (args.optionFound(
"keywords"))
656 else if (args.optionFound(
"diff"))
658 remove(
dict, diffDict);
659 dict.dictionary::write(
Info,
false);
663 dict.dictionary::write(
Info,
false);
670 localDictPtr->regIOobject::write();
676 if (dictPtr->
found(IOobject::foamFile))
680 dictPtr->
remove(IOobject::foamFile);
683 dictPtr->
write(os,
false);
virtual bool isStream() const
Return true if this entry is a stream.
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
labelList first(const UList< labelPair > &p)
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
#define forAll(list, i)
Loop across all elements in list.
static streamFormat formatEnum(const word &)
Return stream format of given format name.
bool remove(const word &)
Remove an entry specified by keyword.
static void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
A class for handling file names.
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
const dictionary & scopedDict(const word &) const
Find and return a sub-dictionary by scoped lookup.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual int precision() const
Get precision of output field.
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
const word & wordToken() const
static unsigned int defaultPrecision()
Return the default precision.
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
A token holds items read from Istream.
static bool New(dictionary &parentDict, Istream &)
Construct from Istream and insert into dictionary.
static bool dot()
Return true if the inputSyntax is dot.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
bool read(Istream &, const bool keepHeader=false)
Read dictionary from Istream, optionally keeping the header.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
wordList components(const char delimiter='/') const
Return path components as wordList.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
localIOdictionary derived from IOdictionary with global set false to disable parallel master reading...
Pair< word > dictAndKeyword(const word &scopedName)
Extracts dict name and keyword.
A List obtained as a section of another List.
static int disableFunctionEntries
A class for handling words, derived from string.
Extract command arguments and options from the supplied argc and argv parameters. ...
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
streamFormat
Enumeration for the format of data in the stream.
virtual void setTime(const Time &)
Reset the time and time-index to those of the given time.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
OSstream Sout(cout, "Sout")
static word controlDictName
The default control dictionary name (normally "controlDict")
virtual bool isDict() const
Return true if this entry is a dictionary.
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
static bool & parRun()
Is this a parallel run?
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Input from memory buffer stream.
prefixOSstream Pout(cout, "Pout")
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
static void addNote(const string &)
Add extra notes for the usage information.
static bool log
Report which file is included to stdout.
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void dictArgList(const string &funcArgs, word &funcName, wordReList &args, List< Tuple2< word, string >> &namedArgs)
Parse dictionary substitution argument list.
A keyword and a list of tokens is an 'entry'.