dynamicCode Class Reference

Tools for handling dynamic code compilation. More...

Collaboration diagram for dynamicCode:
[legend]

Public Types

typedef Tuple2< fileName, stringfileAndContent
 

Public Member Functions

 dynamicCode (const word &codeName, const word &codeDirName="")
 Construct for a specified code name and code directory name. More...
 
const wordcodeName () const
 Return the code-name. More...
 
const wordcodeDirName () const
 Return the code-dirname. More...
 
const fileNamecodeRoot () const
 Root for dynamic code compilation. More...
 
fileName libSubDir () const
 Subdirectory name for loading libraries. More...
 
fileName codePath () const
 Path for specified code name. More...
 
fileName codeRelPath () const
 Path for specified code name relative to <case> More...
 
fileName libPath () const
 Library path for specified code name. More...
 
fileName libRelPath () const
 Library path for specified code name relative to <case> More...
 
fileName digestFile () const
 Path for SHA1Digest. More...
 
void clear ()
 Clear files and variables. More...
 
void reset (const dynamicCodeContext &)
 Clear files and reset variables to specified context. More...
 
void addCompileFile (const fileName &name)
 Add a file template name, which will be found and filtered. More...
 
void addCopyFile (const fileName &name)
 Add a file template name, which will be found and filtered. More...
 
void addCreateFile (const fileName &name, const string &contents)
 Add a file to create with its contents. Will not be filtered. More...
 
void setFilterContext (const dynamicCodeContext &)
 Define filter variables for code, codeInclude, SHA1sum. More...
 
void setFilterVariable (const word &key, const std::string &value)
 Define a filter variable. More...
 
void setMakeOptions (const std::string &content)
 Define contents for Make/options. More...
 
bool upToDate (const dynamicCodeContext &context) const
 Verify if the copied code is up-to-date, based on Make/SHA1Digest. More...
 
bool upToDate (const SHA1Digest &sha1) const
 Verify if the copied code is up-to-date, based on Make/SHA1Digest. More...
 
bool copyOrCreateFiles (const bool verbose=false) const
 Copy/create files prior to compilation. More...
 
bool wmakeLibso () const
 Compile a libso. More...
 
template<class Type >
void setFieldTemplates ()
 Define a filter variables TemplateType and FieldType. More...
 

Static Public Member Functions

static void checkSecurity (const char *title, const dictionary &)
 Check security for creating dynamic code. More...
 

Static Public Attributes

static const word codeTemplateEnvName = "FOAM_CODE_TEMPLATES"
 Name of the code template environment variable. More...
 
static const fileName codeTemplateDirName = "codeTemplates/dynamicCode"
 Name of the code template sub-directory. More...
 
static int allowSystemOperations
 Flag if system operations are allowed. More...
 

Protected Member Functions

bool writeCommentSHA1 (Ostream &) const
 Write SHA1 value as C-comment. More...
 
bool createMakeFiles () const
 Copy/create Make/files prior to compilation. More...
 
bool createMakeOptions () const
 Copy/create Make/options prior to compilation. More...
 
bool writeDigest (const SHA1Digest &) const
 Write digest to Make/SHA1Digest. More...
 
bool writeDigest (const std::string &) const
 Write digest to Make/SHA1Digest. More...
 

Static Protected Member Functions

static void copyAndFilter (ISstream &, OSstream &, const HashTable< string > &mapping)
 Copy lines while expanding variables. More...
 
static bool resolveTemplates (const UList< fileName > &templateNames, DynamicList< fileName > &resolvedFiles, DynamicList< fileName > &badFiles)
 Resolve code-templates via the codeTemplateEnvName. More...
 

Static Protected Attributes

static const char *const targetLibDir = "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib"
 Directory for library targets for Make/files. More...
 
static const char *const topDirName = "dynamicCode"
 Top-level directory name for copy/compiling. More...
 

Detailed Description

Tools for handling dynamic code compilation.

Source files

Definition at line 59 of file dynamicCode.H.

Member Typedef Documentation

◆ fileAndContent

Definition at line 63 of file dynamicCode.H.

Constructor & Destructor Documentation

◆ dynamicCode()

dynamicCode ( const word codeName,
const word codeDirName = "" 
)
explicit

Construct for a specified code name and code directory name.

Defaults to using the code name for the code directory name

Definition at line 291 of file dynamicCode.C.

References dynamicCode::clear().

Here is the call graph for this function:

Member Function Documentation

◆ copyAndFilter()

void copyAndFilter ( ISstream is,
OSstream os,
const HashTable< string > &  mapping 
)
staticprotected

Copy lines while expanding variables.

Definition at line 101 of file dynamicCode.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, ISstream::getLine(), IOstream::good(), Foam::stringOps::inplaceExpand(), OFstream::name(), ISstream::name(), Foam::nl, os(), and OBJstream::writeQuoted().

Here is the call graph for this function:

◆ resolveTemplates()

bool resolveTemplates ( const UList< fileName > &  templateNames,
DynamicList< fileName > &  resolvedFiles,
DynamicList< fileName > &  badFiles 
)
staticprotected

Resolve code-templates via the codeTemplateEnvName.

alternatively in the codeTemplateDirName via Foam::findEtcFile

Definition at line 138 of file dynamicCode.C.

References DynamicList< T, SizeMin >::append(), Foam::findEtcFile(), Foam::getEnv(), Foam::isDir(), and Foam::isFile().

Here is the call graph for this function:

◆ writeCommentSHA1()

bool writeCommentSHA1 ( Ostream os) const
protected

Write SHA1 value as C-comment.

Definition at line 182 of file dynamicCode.C.

References os(), and OBJstream::writeQuoted().

Here is the call graph for this function:

◆ createMakeFiles()

bool createMakeFiles ( ) const
protected

Copy/create Make/files prior to compilation.

Definition at line 197 of file dynamicCode.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, IOstream::good(), Foam::mkDir(), Foam::nl, os(), fileName::path(), and OBJstream::writeQuoted().

Here is the call graph for this function:

◆ createMakeOptions()

bool createMakeOptions ( ) const
protected

Copy/create Make/options prior to compilation.

Definition at line 235 of file dynamicCode.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, IOstream::good(), Foam::mkDir(), Foam::nl, os(), fileName::path(), and OBJstream::writeQuoted().

Here is the call graph for this function:

◆ writeDigest() [1/2]

bool writeDigest ( const SHA1Digest sha1) const
protected

Write digest to Make/SHA1Digest.

Definition at line 264 of file dynamicCode.C.

References IOstream::good(), Foam::mkDir(), Foam::nl, os(), fileName::path(), and SHA1Digest::write().

Here is the call graph for this function:

◆ writeDigest() [2/2]

bool writeDigest ( const std::string &  sha1) const
protected

Write digest to Make/SHA1Digest.

Definition at line 276 of file dynamicCode.C.

References IOstream::good(), Foam::mkDir(), Foam::nl, os(), fileName::path(), and OBJstream::writeQuoted().

Here is the call graph for this function:

◆ checkSecurity()

void checkSecurity ( const char *  title,
const dictionary dict 
)
static

Check security for creating dynamic code.

Definition at line 64 of file dynamicCode.C.

References dynamicCode::allowSystemOperations, Foam::foamVersion::api, dict, Foam::endl(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::isAdministrator(), and Foam::nl.

Referenced by codeStream::evaluate(), and codedBase::updateLibrary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ codeName()

const word & codeName ( ) const
inline

Return the code-name.

Definition at line 189 of file dynamicCode.H.

Referenced by codeStream::getFunction(), and codedBase::updateLibrary().

Here is the caller graph for this function:

◆ codeDirName()

const word & codeDirName ( ) const
inline

Return the code-dirname.

Definition at line 195 of file dynamicCode.H.

◆ codeRoot()

const fileName & codeRoot ( ) const
inline

Root for dynamic code compilation.

Expanded from <case>/dynamicCode

Definition at line 202 of file dynamicCode.H.

◆ libSubDir()

fileName libSubDir ( ) const
inline

Subdirectory name for loading libraries.

Expanded from platforms/$WM_OPTIONS/lib

Definition at line 209 of file dynamicCode.H.

◆ codePath()

fileName codePath ( ) const
inline

Path for specified code name.

Corresponds to codeRoot()/codeDirName()

Definition at line 216 of file dynamicCode.H.

◆ codeRelPath()

Foam::fileName codeRelPath ( ) const

Path for specified code name relative to <case>

Corresponds to topDirName/codeDirName()

Definition at line 309 of file dynamicCode.C.

◆ libPath()

Foam::fileName libPath ( ) const

Library path for specified code name.

Corresponds to codeRoot()/libSubDir()/lib<codeName>.so

Definition at line 315 of file dynamicCode.C.

References dlLibraryTable::fullname().

Referenced by codeStream::getFunction(), and codedBase::updateLibrary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ libRelPath()

Foam::fileName libRelPath ( ) const

Library path for specified code name relative to <case>

Corresponds to dynamicCode/codeDirName()/libSubDir()/lib<codeName>.so

Definition at line 321 of file dynamicCode.C.

References dlLibraryTable::fullname().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ digestFile()

fileName digestFile ( ) const
inline

Path for SHA1Digest.

Corresponds to codePath()/Make/SHA1Digest

Definition at line 237 of file dynamicCode.H.

◆ clear()

void clear ( )

Clear files and variables.

Definition at line 327 of file dynamicCode.C.

Referenced by dynamicCode::dynamicCode().

Here is the caller graph for this function:

◆ reset()

void reset ( const dynamicCodeContext context)

Clear files and reset variables to specified context.

Definition at line 343 of file dynamicCode.C.

References clear().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCompileFile()

void addCompileFile ( const fileName name)

Add a file template name, which will be found and filtered.

Definition at line 353 of file dynamicCode.C.

References Foam::name().

Referenced by codeStream::getFunction(), codedPoints0MotionSolver::prepare(), codedMixedFvPatchField< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), CodedField< Type >::prepare(), and CodedFunction1< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCopyFile()

void addCopyFile ( const fileName name)

Add a file template name, which will be found and filtered.

Definition at line 359 of file dynamicCode.C.

References Foam::name().

Referenced by codedPoints0MotionSolver::prepare(), codedMixedFvPatchField< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), CodedField< Type >::prepare(), and CodedFunction1< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCreateFile()

void addCreateFile ( const fileName name,
const string contents 
)

Add a file to create with its contents. Will not be filtered.

Definition at line 365 of file dynamicCode.C.

References Foam::name().

Here is the call graph for this function:

◆ setFilterContext()

void setFilterContext ( const dynamicCodeContext context)

Define filter variables for code, codeInclude, SHA1sum.

Definition at line 375 of file dynamicCode.C.

References dynamicCodeContext::code(), dynamicCodeContext::include(), dynamicCodeContext::localCode(), dynamicCodeContext::sha1(), and SHA1::str().

Here is the call graph for this function:

◆ setFilterVariable()

void setFilterVariable ( const word key,
const std::string &  value 
)

Define a filter variable.

Definition at line 387 of file dynamicCode.C.

Referenced by codedPoints0MotionSolver::prepare(), codedMixedFvPatchField< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), CodedField< Type >::prepare(), CodedFunction1< Type >::prepare(), and dynamicCode::setFieldTemplates().

Here is the caller graph for this function:

◆ setMakeOptions()

void setMakeOptions ( const std::string &  content)

Define contents for Make/options.

Definition at line 397 of file dynamicCode.C.

Referenced by codeStream::getFunction(), codedPoints0MotionSolver::prepare(), codedMixedFvPatchField< Type >::prepare(), codedFunctionObject::prepare(), CodedSource< Type >::prepare(), CodedField< Type >::prepare(), and CodedFunction1< Type >::prepare().

Here is the caller graph for this function:

◆ upToDate() [1/2]

bool upToDate ( const dynamicCodeContext context) const

Verify if the copied code is up-to-date, based on Make/SHA1Digest.

Definition at line 530 of file dynamicCode.C.

References dynamicCodeContext::sha1().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upToDate() [2/2]

bool upToDate ( const SHA1Digest sha1) const

Verify if the copied code is up-to-date, based on Make/SHA1Digest.

Definition at line 517 of file dynamicCode.C.

References Foam::exists().

Here is the call graph for this function:

◆ copyOrCreateFiles()

bool copyOrCreateFiles ( const bool  verbose = false) const

Copy/create files prior to compilation.

Definition at line 403 of file dynamicCode.C.

References DetailInfo, UList< T >::empty(), Foam::endl(), Foam::exit(), Foam::stringOps::expand(), Foam::FatalError, FatalErrorInFunction, IOstream::good(), Foam::mkDir(), fileName::name(), Foam::nl, os(), fileName::path(), and OBJstream::writeQuoted().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wmakeLibso()

bool wmakeLibso ( ) const

Compile a libso.

Definition at line 495 of file dynamicCode.C.

References Foam::endl(), Foam::Info, Foam::infoDetailLevel, os(), Foam::Serr, and Foam::system().

Referenced by codeStream::getFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFieldTemplates()

void setFieldTemplates ( )
inline

Define a filter variables TemplateType and FieldType.

Definition at line 286 of file dynamicCode.H.

References dynamicCode::setFilterVariable().

Referenced by codedMixedFvPatchField< Type >::prepare(), CodedField< Type >::prepare(), and CodedFunction1< Type >::prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ targetLibDir

const char *const targetLibDir = "LIB = $(PWD)/../platforms/$(WM_OPTIONS)/lib"
staticprotected

Directory for library targets for Make/files.

Definition at line 111 of file dynamicCode.H.

◆ topDirName

const char *const topDirName = "dynamicCode"
staticprotected

Top-level directory name for copy/compiling.

Definition at line 114 of file dynamicCode.H.

◆ codeTemplateEnvName

const Foam::word codeTemplateEnvName = "FOAM_CODE_TEMPLATES"
static

Name of the code template environment variable.

Used to located the codeTemplateName

Definition at line 159 of file dynamicCode.H.

◆ codeTemplateDirName

const Foam::fileName codeTemplateDirName = "codeTemplates/dynamicCode"
static

Name of the code template sub-directory.

Used when locating the codeTemplateName via Foam::findEtcFile

Definition at line 163 of file dynamicCode.H.

◆ allowSystemOperations

int allowSystemOperations
static

Flag if system operations are allowed.

Definition at line 166 of file dynamicCode.H.

Referenced by dynamicCode::checkSecurity(), argList::parse(), and systemCall::read().


The documentation for this class was generated from the following files: