Go to the documentation of this file.
139 using namespace Foam;
145 bool upgradeScope(
word& entryName)
149 entryName.find(
'/') == string::npos
150 && entryName.find(
':') != string::npos
159 if (entryName.size()) entryName.append(
".");
161 entryName.append(
name);
180 dictAndKeyword(
const word& scopedName)
182 auto i = scopedName.rfind(
'/');
183 if (i == string::npos)
185 i = scopedName.rfind(
'.');
188 if (i != string::npos)
190 dict_ = scopedName.substr(0, i);
191 key_ = scopedName.substr(i+1);
204 inline const word& key()
const
214 const word& subDictName
217 if (subDictName.empty())
224 if (!eptr || !eptr->
isDict())
227 <<
"'" << subDictName <<
"' not found in dictionary "
228 <<
dict.
name() <<
" or is not a dictionary" <<
nl
229 <<
"Known entries are " <<
dict.
keys()
239 for (
const entry& refEntry : dictToRemove)
247 if (refEntry.isDict())
249 removeDict(finder.dict(), refEntry.dict());
252 purge = finder.
dict().empty();
255 else if (finder.found() && !refEntry.isDict())
258 purge = (finder.ref() == refEntry);
269 int main(
int argc,
char *argv[])
273 "Interrogate and manipulate dictionaries"
290 "Set entry value or add new entry"
307 "Write differences with respect to the specified dictionary"
313 "As per -diff, but locate the file as per foamEtcFile"
320 "Set default write precision for IOstreams"
326 "List the #include/#sinclude files to standard output"
331 "Read the specified dictionary file, expand the macros etc. and write "
332 "the resulting dictionary to standard output"
336 "disableFunctionEntries",
337 "Disable expansion of dictionary directives - #include, #codeStream etc"
343 const bool listIncludes =
args.
found(
"includes");
350 const bool disableEntries =
args.
found(
"disableFunctionEntries");
356 Serr<<
"Not expanding variables or dictionary directives" <<
endl;
379 if (!dictFile().good())
382 <<
"Cannot open file " << dictFileName
387 bool changed =
false;
399 <<
"//\n// " << dictFileName <<
"\n//\n";
408 bool optDiff =
false;
417 if (!diffFile.good())
420 <<
"Cannot open file " << diffFileName
425 diffDict.
read(diffFile,
true);
431 if (foundName.empty())
434 <<
"Cannot find etcFile " << diffFileName
439 if (!diffFile.good())
442 <<
"Cannot open file " << foundName
447 diffDict.
read(diffFile,
true);
455 upgradeScope(scopedName);
464 const bool overwrite =
args.
found(
"set");
467 const dictAndKeyword dAk(scopedName);
497 const dictAndKeyword dAk(scopedName);
511 const dictAndKeyword dAk(scopedName);
514 const dictionary& d2(lookupScopedDict(diffDict, dAk.dict()));
521 if (*e1Ptr == *e2Ptr)
523 const_cast<dictionary&
>(d1).remove(dAk.key());
541 <<
"Cannot find entry " << scopedName
546 for (
const entry&
e : finder.dict())
555 Info<< finder.dict();
557 else if (finder.ref().isStream())
559 const tokenList& tokens = finder.ref().stream();
563 if (i < tokens.size() - 1)
586 removeDict(
dict, diffDict);
static void noBanner()
Disable emitting the banner information.
A keyword and a list of tokens is an 'entry'.
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
A class for handling words, derived from Foam::string.
A class for handling file names.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Input from file stream, using an ISstream.
static Ostream & writeBanner(Ostream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
static void addNote(const string ¬e)
Add extra notes for the usage information.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Extract command arguments and options from the supplied argc and argv parameters.
Ostream & endl(Ostream &os)
Add newline and flush stream.
OSstream Serr
An Ostream wrapper for std::cerr.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
#define forAll(list, i)
Loop across all elements in list.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
const fileName & name() const
The dictionary name.
virtual bool isDict() const
Return true if this entry is a dictionary.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
messageStream Info
Information stream (uses stdout - output is on the master only)
const_searcher csearchScoped(const word &keyword, enum keyType::option) const
Search using scoping.
word name(const complex &c)
Return string representation of complex.
static bool log
Report to stdout which file is included.
dict_reference dict() const
Reference the found entry as a dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Input from string buffer, using a ISstream.
static void disable()
Disallow profiling by forcing the InfoSwitch off.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
bool read(Istream &is)
Read dictionary from Istream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
static bool master(const label communicator=0)
Am I the master process.
virtual int precision() const
Get precision of output field.
Functions to search 'etc' directories for configuration files etc.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
Input/output from file streams.
static unsigned int defaultPrecision()
Return the default precision.
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
bool remove(const word &keyword)
Remove an entry specified by keyword.
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
const dimensionedScalar e
Elementary charge.
const_searcher search(const word &keyword, enum keyType::option=keyType::REGEX) const
Search dictionary for given keyword.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OSstream Sout
An Ostream wrapper for std::cout.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.