139 using namespace Foam;
145 bool upgradeScope(
word& entryName)
155 if (entryName.size()) entryName.append(
".");
157 entryName.append(
name);
176 dictAndKeyword(
const word& scopedName)
178 auto i = scopedName.rfind(
'/');
179 if (i == string::npos)
181 i = scopedName.rfind(
'.');
184 if (i != string::npos)
186 dict_ = scopedName.substr(0, i);
187 key_ = scopedName.substr(i+1);
210 const word& subDictName
213 if (subDictName.empty())
220 if (!eptr || !eptr->
isDict())
223 <<
"'" << subDictName <<
"' not found in dictionary " 224 <<
dict.
name() <<
" or is not a dictionary" <<
nl 225 <<
"Known entries are " <<
dict.
keys()
235 for (
const entry& refEntry : dictToRemove)
243 if (refEntry.isDict())
245 removeDict(finder.dict(), refEntry.dict());
248 purge = finder.
dict().empty();
251 else if (finder.found() && !refEntry.isDict())
254 purge = (finder.ref() == refEntry);
265 int main(
int argc,
char *argv[])
269 "Interrogate and manipulate dictionaries" 286 "Set entry value or add new entry" 303 "Write differences with respect to the specified dictionary" 309 "As per -diff, but locate the file as per foamEtcFile" 316 "Set default write precision for IOstreams" 322 "List the #include/#sinclude files to standard output" 327 "Read the specified dictionary file, expand the macros etc. and write " 328 "the resulting dictionary to standard output" 332 "disableFunctionEntries",
333 "Disable expansion of dictionary directives - #include, #codeStream etc" 339 const bool listIncludes =
args.
found(
"includes");
346 const bool disableEntries =
args.
found(
"disableFunctionEntries");
352 Serr<<
"Not expanding variables or dictionary directives" <<
endl;
375 if (!dictFile().good())
378 <<
"Cannot open file " << dictFileName
383 bool changed =
false;
395 <<
"//\n// " << dictFileName <<
"\n//\n";
404 bool optDiff =
false;
413 if (!diffFile.good())
416 <<
"Cannot open file " << diffFileName
421 diffDict.
read(diffFile,
true);
427 if (foundName.empty())
430 <<
"Cannot find etcFile " << diffFileName
435 if (!diffFile.good())
438 <<
"Cannot open file " << foundName
443 diffDict.
read(diffFile,
true);
451 upgradeScope(scopedName);
460 const bool overwrite =
args.
found(
"set");
463 const dictAndKeyword dAk(scopedName);
493 const dictAndKeyword dAk(scopedName);
507 const dictAndKeyword dAk(scopedName);
510 const dictionary& d2(lookupScopedDict(diffDict, dAk.dict()));
517 if (*e1Ptr == *e2Ptr)
519 const_cast<dictionary&
>(d1).
remove(dAk.key());
525 const_cast<dictionary&>(e1Ptr->
dict()),
537 <<
"Cannot find entry " << scopedName
542 for (
const entry&
e : finder.dict())
551 Info<< finder.dict();
553 else if (finder.ref().isStream())
555 const tokenList& tokens = finder.ref().stream();
559 if (i < tokens.size() - 1)
582 removeDict(
dict, diffDict);
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
dict_reference dict() const
Reference the found entry as a dictionary.
static void addNote(const string ¬e)
Add extra notes for the usage information.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
A class for handling file names.
bool contains(char c) const noexcept
True if string contains given character (cf. C++23)
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual int precision() const
Get precision of output field.
bool read(Istream &is)
Read dictionary from Istream. Discards the header.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
virtual const dictionary & dict() const =0
Return dictionary, if entry is a dictionary.
static unsigned int defaultPrecision() noexcept
Return the default precision.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
const fileName & name() const noexcept
The dictionary name.
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
static void disable()
Disallow profiling by forcing the InfoSwitch off.
#define forAll(list, i)
Loop across all elements in list.
bool remove(const word &keyword)
Remove an entry specified by keyword.
const_searcher search(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
const dimensionedScalar e
Elementary charge.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
A class for handling words, derived from Foam::string.
Functions to search 'etc' directories for configuration files etc.
Extract command arguments and options from the supplied argc and argv parameters. ...
OSstream Sout
OSstream wrapped stdout (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.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
const_searcher csearchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using scoping.
Input from file stream, using an ISstream.
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
T get(const label index) const
Get a value from the argument at index.
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
static bool master(const label communicator=worldComm)
Am I the master rank.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
OSstream Serr
OSstream wrapped stderr (std::cerr)
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void noBanner()
Disable emitting the banner information.
virtual bool isDict() const noexcept
Return true if this entry is a dictionary.
static Ostream & writeBanner(Ostream &os, const bool noSyntaxHint=false)
Write the standard OpenFOAM file/dictionary banner.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
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.
static bool log
Report to stdout which file is included.
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
A keyword and a list of tokens is an 'entry'.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...