mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
rename Foam::dotFoam() -> Foam::findEtcFile() with an optional 'mandatory' argument
- if mandatory is true, findEtcFile() will abort with a message (via cerr). This allows a non-existent file to be caught at the lowest level and avoid error handling in IFstream, which might not be initialized at that stage.
This commit is contained in:
@ -32,6 +32,7 @@ Description
|
||||
|
||||
#include "fileName.H"
|
||||
#include "IOstreams.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -57,7 +58,16 @@ int main()
|
||||
Info<< "pathName.components() = " << pathName.components() << endl;
|
||||
Info<< "pathName.component(2) = " << pathName.component(2) << endl;
|
||||
|
||||
Info<< "end" << endl;
|
||||
|
||||
// test findEtcFile
|
||||
Info<< "\n\nfindEtcFile tests:" << nl
|
||||
<< " controlDict => " << findEtcFile("controlDict") << nl
|
||||
<< " badName => " << findEtcFile("badName") << endl;
|
||||
Info<< "This should emit a fatal error:" << endl;
|
||||
Info<< " badName(die) => " << findEtcFile("badName", true) << nl
|
||||
<< endl;
|
||||
|
||||
Info<< "\nEnd" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Reading Burcat data dictionary" << endl;
|
||||
|
||||
fileName BurcatCpDataFileName(dotFoam("thermoData/BurcatCpData"));
|
||||
fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
|
||||
|
||||
// Construct control dictionary
|
||||
IFstream BurcatCpDataFile(BurcatCpDataFileName);
|
||||
|
||||
@ -79,7 +79,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Reading Burcat data dictionary" << endl;
|
||||
|
||||
fileName BurcatCpDataFileName(dotFoam("thermoData/BurcatCpData"));
|
||||
fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
|
||||
|
||||
// Construct control dictionary
|
||||
IFstream BurcatCpDataFile(BurcatCpDataFileName);
|
||||
|
||||
@ -77,7 +77,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Reading Burcat data dictionary" << endl;
|
||||
|
||||
fileName BurcatCpDataFileName(dotFoam("thermoData/BurcatCpData"));
|
||||
fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
|
||||
|
||||
// Construct control dictionary
|
||||
IFstream BurcatCpDataFile(BurcatCpDataFileName);
|
||||
|
||||
@ -211,7 +211,7 @@ bool Foam::chDir(const fileName& dir)
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::dotFoam(const fileName& name)
|
||||
Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
{
|
||||
// Search user files:
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
@ -268,6 +268,15 @@ Foam::fileName Foam::dotFoam(const fileName& name)
|
||||
}
|
||||
|
||||
// Not found
|
||||
// abort if the file is mandatory, otherwise return null
|
||||
if (mandatory)
|
||||
{
|
||||
cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
|
||||
" could not find mandatory file\n '"
|
||||
<< name.c_str() << "'\n\n" << std::endl;
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
return fileName::null;
|
||||
}
|
||||
|
||||
|
||||
@ -102,7 +102,8 @@ bool chDir(const fileName& dir);
|
||||
// - $WM_PROJECT_DIR/etc/
|
||||
//
|
||||
// @return the full path name or fileName::null if the name cannot be found
|
||||
fileName dotFoam(const fileName& name);
|
||||
// Optionally abort if the file cannot be found
|
||||
fileName findEtcFile(const fileName& name, bool mandatory=false);
|
||||
|
||||
//- Make a directory and return an error if it could not be created
|
||||
// and does not already exist
|
||||
|
||||
@ -40,7 +40,7 @@ namespace Foam
|
||||
// PtrList of models
|
||||
PtrList<cellModel> cellModeller::models_
|
||||
(
|
||||
(IFstream(dotFoam("cellModels"))())
|
||||
IFstream(findEtcFile("cellModels", true))()
|
||||
);
|
||||
|
||||
// List of model pointers
|
||||
|
||||
@ -202,7 +202,7 @@ Foam::string& Foam::string::expand()
|
||||
// otherwise add extra test
|
||||
if (user == "OpenFOAM")
|
||||
{
|
||||
*this = dotFoam(file);
|
||||
*this = findEtcFile(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -34,7 +34,7 @@ Description
|
||||
Used as a base class for word and fileName.
|
||||
|
||||
See Also
|
||||
Foam::dotFoam() for information about the site/user OpenFOAM
|
||||
Foam::findEtcFile() for information about the site/user OpenFOAM
|
||||
configuration directory
|
||||
|
||||
SourceFiles
|
||||
@ -176,7 +176,7 @@ public:
|
||||
// - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
|
||||
//
|
||||
// @sa
|
||||
// Foam::dotFoam
|
||||
// Foam::findEtcFile
|
||||
string& expand();
|
||||
|
||||
//- Remove repeated characters returning true if string changed
|
||||
|
||||
Reference in New Issue
Block a user