CTL  0.6.1
Computed Tomography Library
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CTL::ClFileLoader Class Reference

The ClFileLoader class provides the ability to load files with OpenCL C source code. More...

#include <clfileloader.h>

Public Member Functions

 ClFileLoader (const char *fileName)
 
 ClFileLoader (std::string fileName)
 
 ClFileLoader (const QString &fileName)
 
void setFileName (const char *fileName)
 
void setFileName (std::string fileName)
 
void setFileName (const QString &fileName)
 
const std::string & fileName () const
 
bool isValid () const
 
std::string loadSourceCode () const
 

Static Public Member Functions

static std::string loadExternalSourceCode (const char *absoluteFilePath)
 
static std::string loadExternalSourceCode (const std::string &absoluteFilePath)
 
static std::string loadExternalSourceCode (const QString &absoluteFilePath)
 
static void setOpenCLSourceDir (const char *path)
 
static void setOpenCLSourceDir (const QString &path)
 
static void setOpenCLSourceDir (QString &&path)
 
static void setOpenCLSourceDir (const std::string &path)
 
static const QString & openCLSourceDir ()
 

Static Private Member Functions

static const QString & absoluteOpenCLSourceDir ()
 

Private Attributes

std::string _fn
 

Static Private Attributes

static QString _oclSourceDir
 

Detailed Description

The ClFileLoader class provides the ability to load files with OpenCL C source code.

OpenCL C source code needs to be available at runtime. Therefore, it will be collected in .cl files within the "cl_src" directory, which is located in the path of the executable (copied from the "ocl" folder of the repository by the qmake build system; see "ocl_config.pri"). The ClFileLoader provides the method loadSourceCode() that loads a file from the "cl_src" folder and return the content as a std::string. The file name of a .cl file is passed by the constructor or the setFileName() method as a relative path wrt the "cl_src" folder, e.g. "projectors/external_raycaster.cl". Moreover, the ClFileLoader allows to check beforehand if a certain .cl file is readable by using isValid().

NOTE: The internal determination of the absolute path of the "cl_src" folder can only work correctly if the main function of the program instantiate a QCoreApplication (or derived classes) as in the following snippet:

#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// your code...
}

If no QCoreApplication has been instantiated:
The ClFileLoader can only use the relative path to the OpenCL sources wrt to the executable. This requires that the current directory (from where the program was started) is equal to the directory of the executable. Should this not be the case, the ClFileLoader is not able to locate the .cl files, i.e. isValid() will return false and loadSourceCode() will return an empty string. Alternatively, the path to the "cl_src" folder can be set during run time using the static method setOpenCLSourceDir().

Constructor & Destructor Documentation

◆ ClFileLoader() [1/3]

CTL::ClFileLoader::ClFileLoader ( const char *  fileName)
explicit

Constructs a ClFileLoader object using fileName as the path of the .cl file.

See also
setFileName()

◆ ClFileLoader() [2/3]

CTL::ClFileLoader::ClFileLoader ( std::string  fileName)
explicit

Constructs a ClFileLoader object using fileName as the path of the .cl file.

See also
setFileName()

◆ ClFileLoader() [3/3]

CTL::ClFileLoader::ClFileLoader ( const QString &  fileName)
explicit

Constructs a ClFileLoader object using fileName as the path of the .cl file.

See also
setFileName()

Member Function Documentation

◆ absoluteOpenCLSourceDir()

const QString & CTL::ClFileLoader::absoluteOpenCLSourceDir ( )
staticprivate

Returns the absolute path to the "ocl_src" directory. If no OpenCL source directory has been set, it determines the absolute path "<executable's directory>/cl_src" in a platform-independent way provided that QCoreApplication has been instatiated in the main() of the application. In case CTL_LIBRARY was defined (CTL as pre-compiled library), the macro OCL_SOURCE_DIR is used.

◆ fileName()

const std::string & CTL::ClFileLoader::fileName ( ) const

Returns the relative path within the "cl_src" directory to the .cl file set by setFileName() or a constructor.

◆ isValid()

bool CTL::ClFileLoader::isValid ( ) const

Returns true if the .cl file is readable, otherwise false.

◆ loadExternalSourceCode() [1/3]

std::string CTL::ClFileLoader::loadExternalSourceCode ( const char *  absoluteFilePath)
static

Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.

◆ loadExternalSourceCode() [2/3]

std::string CTL::ClFileLoader::loadExternalSourceCode ( const std::string &  absoluteFilePath)
static

Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.

◆ loadExternalSourceCode() [3/3]

std::string CTL::ClFileLoader::loadExternalSourceCode ( const QString &  absoluteFilePath)
static

Returns the content of an .cl file specified by an absolute path absoluteFilePath. This convenience function allows using OpenCL kernel files that are not located in the "cl_src" folder.

◆ loadSourceCode()

std::string CTL::ClFileLoader::loadSourceCode ( ) const

Returns the content of the .cl file as a std::string.

◆ openCLSourceDir()

const QString & CTL::ClFileLoader::openCLSourceDir ( )
static

Returns the path to the OpenCL directory, where OpenCL C kernel files are stored. This could be the default path ("cl_src" next to the executable or specified by OCL_SOURCE_DIR) or the path that has been set by setOpenCLSourceDir().

◆ setFileName() [1/3]

void CTL::ClFileLoader::setFileName ( const char *  fileName)

◆ setFileName() [2/3]

void CTL::ClFileLoader::setFileName ( std::string  fileName)

(Re)sets the path of the .cl file. The fileName shall be passed to this method by the relative path wrt the "cl_src" directory.

See also
fileName()

◆ setFileName() [3/3]

void CTL::ClFileLoader::setFileName ( const QString &  fileName)

◆ setOpenCLSourceDir() [1/4]

void CTL::ClFileLoader::setOpenCLSourceDir ( const char *  path)
static

Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable).

See also
setFileName(const char* path)

◆ setOpenCLSourceDir() [2/4]

void CTL::ClFileLoader::setOpenCLSourceDir ( const QString &  path)
static

Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.

See also
setFileName(const QString& path)

◆ setOpenCLSourceDir() [3/4]

void CTL::ClFileLoader::setOpenCLSourceDir ( QString &&  path)
static

Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.

See also
setFileName(const QString& path)

◆ setOpenCLSourceDir() [4/4]

void CTL::ClFileLoader::setOpenCLSourceDir ( const std::string &  path)
static

Sets the path of the OpenCL source directory to path. The filename of an OpenCL C file (.cl) is a relative path w.r.t. this directory. If this function is never called or called with an empty string, a default directory is used, which is the folder "cl_src" in the directory of the current application (the executable), or, in case CTL_LIBRARY was defined, the macro OCL_SOURCE_DIR is used.

See also
setFileName(std::string path)

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