ENH: refactor codeStreamTools, use for codedFixedValueFvPatchScalarField

This commit is contained in:
Mark Olesen
2011-02-22 15:01:20 +01:00
parent 4aa279d7bc
commit f0f2bfa632
9 changed files with 210 additions and 133 deletions

View File

@ -57,15 +57,9 @@ namespace functionEntries
}
const Foam::word Foam::functionEntries::codeStream::codeTemplateName
const Foam::word Foam::functionEntries::codeStream::codeTemplateC
= "codeStreamTemplate.C";
const Foam::word Foam::functionEntries::codeStream::codeTemplateEnvName
= "FOAM_CODESTREAM_TEMPLATES";
const Foam::fileName Foam::functionEntries::codeStream::codeTemplateDirName
= "codeTemplates/codeStream";
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -148,49 +142,30 @@ bool Foam::functionEntries::codeStream::execute
{
Info<< "Creating new library in " << libPath << endl;
fileName srcFile;
// try to get template from FOAM_CODESTREAM_TEMPLATES
fileName templateDir
const fileName fileCsrc
(
Foam::getEnv(codeTemplateEnvName)
codeStreamTools::findTemplate
(
codeTemplateC
)
);
if (!templateDir.empty())
{
srcFile = templateDir/codeTemplateName;
if (!isFile(srcFile, false))
{
srcFile.clear();
}
}
// not found - fallback to ~OpenFOAM expansion
if (srcFile.empty())
{
srcFile = findEtcFile
(
codeTemplateDirName/codeTemplateName
);
}
if (srcFile.empty())
// not found!
if (fileCsrc.empty())
{
FatalIOErrorIn
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Could not find the code template: "
<< codeTemplateName << nl
<< "Under the $FOAM_CODESTREAM_TEMPLATES directory"
<< " via via the ~OpenFOAM/" / codeTemplateDirName
<< " expansion"
<< codeTemplateC << nl
<< codeStreamTools::searchedLocations()
<< exit(FatalIOError);
}
List<codeStreamTools::fileAndVars> copyFiles(1);
copyFiles[0].file() = srcFile;
copyFiles[0].file() = fileCsrc;
copyFiles[0].set("codeInclude", codeInclude);
copyFiles[0].set("code", code);
@ -199,7 +174,7 @@ bool Foam::functionEntries::codeStream::execute
// Write Make/files
filesContents[0].first() = "Make/files";
filesContents[0].second() =
codeTemplateName + "\n"
codeTemplateC + "\n\n"
"LIB = $(FOAM_USER_LIBBIN)/lib" + name;
// Write Make/options
@ -214,7 +189,7 @@ bool Foam::functionEntries::codeStream::execute
(
"functionEntries::codeStream::execute(..)",
parentDict
) << "Failed writing " << endl
) << "Failed writing " <<nl
<< copyFiles << endl
<< filesContents
<< exit(FatalIOError);

View File

@ -114,16 +114,8 @@ public:
// Static data members
//- Name of the code template to be used
const static word codeTemplateName;
//- Name of the code template environment variable
// Used to located the codeTemplateName
const static word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
const static fileName codeTemplateDirName;
//- Name of the C code template to be used
const static word codeTemplateC;
//- Runtime type information

View File

@ -40,6 +40,53 @@ int Foam::codeStreamTools::allowSystemOperations
);
const Foam::word Foam::codeStreamTools::codeTemplateEnvName
= "FOAM_CODESTREAM_TEMPLATES";
const Foam::fileName Foam::codeStreamTools::codeTemplateDirName
= "codeTemplates/codeStream";
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::codeStreamTools::findTemplate(const word& templateFile)
{
// try to get template from FOAM_CODESTREAM_TEMPLATES
fileName templateDir(Foam::getEnv(codeTemplateEnvName));
fileName file;
if (!templateDir.empty() && isDir(templateDir))
{
file = templateDir/templateFile;
if (!isFile(file, false))
{
file.clear();
}
}
// not found - fallback to ~OpenFOAM expansion
if (file.empty())
{
file = findEtcFile(codeTemplateDirName/templateFile);
}
return file;
}
Foam::string Foam::codeStreamTools::searchedLocations()
{
return
(
"Under the $"
+ codeTemplateDirName
+ " directory or via via the ~OpenFOAM/"
+ codeTemplateDirName
+ " expansion"
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::codeStreamTools::copyAndExpand

View File

@ -109,7 +109,18 @@ protected:
public:
static int allowSystemOperations;
// Static data members
//- Name of the code template environment variable
// Used to located the codeTemplateName
const static word codeTemplateEnvName;
//- Name of the code template sub-directory
// Used when locating the codeTemplateName via Foam::findEtcFile
const static fileName codeTemplateDirName;
static int allowSystemOperations;
// Constructors
@ -150,6 +161,15 @@ public:
bool copyFilesContents(const fileName& dir) const;
//- Find a code-template via the codeTemplateEnvName
// alternatively in the codeTemplateDirName via Foam::findEtcFile
static fileName findTemplate(const word& templateName);
//- List searched locations in a format suitable for display an error
static string searchedLocations();
static void* findLibrary(const fileName& libPath);
static bool writeDigest(const fileName& dir, const SHA1Digest& sha1);