CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::RuntimeLibrary Class Reference

#include <RuntimeLibrary.hh>

Detailed Description

Write, compile, load and use code at runtime.

Definition at line 41 of file RuntimeLibrary.hh.

Public Member Functions

 RuntimeLibrary (std::string _filename_base, std::string _compile_options, std::string _so_options)
 Construct a RuntimeLibrary object, with the options to be used for compile the '.o' file and the '.so' file. More...
 
 ~RuntimeLibrary ()
 
template<typename Signature >
std::function< Signature > get_function (std::string function_name) const
 Obtain a function from the current library. More...
 
void rm ()
 Remove the current library and source code. More...
 

Static Public Member Functions

static std::pair< std::string, std::string > default_cxxflags ()
 Default c++ compiler options. More...
 
static std::pair< std::string, std::string > default_soflags ()
 Default c++ compiler options. More...
 
static std::pair< std::string, std::string > default_cxx ()
 Return default compiler. More...
 
static std::pair< fs::path, std::string > default_casm_includedir ()
 Return default includedir for CASM. More...
 
static std::pair< fs::path, std::string > default_casm_libdir ()
 Return default libdir for CASM. More...
 
static std::pair< fs::path, std::string > default_boost_includedir ()
 Return default includedir for boost. More...
 
static std::pair< fs::path, std::string > default_boost_libdir ()
 Return default libdir for boost. More...
 

Private Member Functions

void _compile ()
 Compile a shared library. More...
 
void _load ()
 Load a library with a given name. More...
 
void _close ()
 Close the current library. More...
 

Private Attributes

std::string m_filename_base
 
std::string m_compile_options
 
std::string m_so_options
 
void * m_handle
 

Constructor & Destructor Documentation

◆ RuntimeLibrary()

CASM::RuntimeLibrary::RuntimeLibrary ( std::string  _filename_base,
std::string  _compile_options,
std::string  _so_options 
)

Construct a RuntimeLibrary object, with the options to be used for compile the '.o' file and the '.so' file.

Definition at line 47 of file RuntimeLibrary.cc.

◆ ~RuntimeLibrary()

CASM::RuntimeLibrary::~RuntimeLibrary ( )

Definition at line 79 of file RuntimeLibrary.cc.

Member Function Documentation

◆ _close()

void CASM::RuntimeLibrary::_close ( )
private

Close the current library.

This is also done on destruction.

Definition at line 138 of file RuntimeLibrary.cc.

◆ _compile()

void CASM::RuntimeLibrary::_compile ( )
private

Compile a shared library.

Parameters
_filename_baseBase name for the source code file. For example, "/path/to/hello" looks for "/path/to/hello.cc", and compile "/path/to/hello.o" and "/path/to/hello.so".
Returns
Compiles file "/path/to/hello.cc" into an object file and shared library using the options provided when this RuntimeLibrary object was constructed. By default, "example.o" and "example.so".

To enable runtime symbol lookup use C-style functions, i.e use extern "C" for functions you want to use via get_function. This means no member functions or overloaded functions.

Definition at line 100 of file RuntimeLibrary.cc.

◆ _load()

void CASM::RuntimeLibrary::_load ( )
private

Load a library with a given name.

Parameters
_filename_baseFor "hello", this loads "hello.so"

Definition at line 126 of file RuntimeLibrary.cc.

◆ default_boost_includedir()

std::pair< fs::path, std::string > CASM::RuntimeLibrary::default_boost_includedir ( )
static

Return default includedir for boost.

Return include path option for boost.

Returns
In order of preference: $CASM_BOOST_INCLUDEDIR, or $CASM_BOOST_PREFIX/include, or "/usr/local/include"

Definition at line 347 of file RuntimeLibrary.cc.

◆ default_boost_libdir()

std::pair< fs::path, std::string > CASM::RuntimeLibrary::default_boost_libdir ( )
static

Return default libdir for boost.

Return lib path option for boost.

Returns
In order of preference: $CASM_BOOST_LIBDIR, or $CASM_BOOST_PREFIX/lib, or "/usr/local/lib"

Definition at line 376 of file RuntimeLibrary.cc.

◆ default_casm_includedir()

std::pair< fs::path, std::string > CASM::RuntimeLibrary::default_casm_includedir ( )
static

Return default includedir for CASM.

Return include path option for CASM.

Returns
In order of preference: $CASM_INCLUDEDIR, or $CASM_PREFIX/include, or "/usr/local/include"

Definition at line 289 of file RuntimeLibrary.cc.

◆ default_casm_libdir()

std::pair< fs::path, std::string > CASM::RuntimeLibrary::default_casm_libdir ( )
static

Return default libdir for CASM.

Return lib path option for CASM.

Returns
In order of preference: $CASM_LIBDIR, or $CASM_PREFIX/lib, or "/usr/local/lib"

Definition at line 318 of file RuntimeLibrary.cc.

◆ default_cxx()

std::pair< std::string, std::string > CASM::RuntimeLibrary::default_cxx ( )
static

Return default compiler.

Return default compiler and specifying variable.

Returns
"$CASM_CXX" if environment variable CASM_CXX exists, "$CXX" if environment variable CXX exists, otherwise "g++"

Definition at line 267 of file RuntimeLibrary.cc.

◆ default_cxxflags()

std::pair< std::string, std::string > CASM::RuntimeLibrary::default_cxxflags ( )
static

Default c++ compiler options.

Returns
"-O3 -Wall -fPIC --std=c++17"

Definition at line 274 of file RuntimeLibrary.cc.

◆ default_soflags()

std::pair< std::string, std::string > CASM::RuntimeLibrary::default_soflags ( )
static

Default c++ compiler options.

Default c++ shared library options.

Returns
"-shared -lboost_system"

Definition at line 281 of file RuntimeLibrary.cc.

◆ get_function()

template<typename Signature >
std::function<Signature> CASM::RuntimeLibrary::get_function ( std::string  function_name) const
inline

Obtain a function from the current library.

Must be a C-style function to enable symbol lookup, i.e your source code should use extern "C". This means no member functions or overloaded functions.

Definition at line 58 of file RuntimeLibrary.hh.

◆ rm()

void CASM::RuntimeLibrary::rm ( )

Remove the current library and source code.

Definition at line 147 of file RuntimeLibrary.cc.

Member Data Documentation

◆ m_compile_options

std::string CASM::RuntimeLibrary::m_compile_options
private

Definition at line 106 of file RuntimeLibrary.hh.

◆ m_filename_base

std::string CASM::RuntimeLibrary::m_filename_base
private

Definition at line 105 of file RuntimeLibrary.hh.

◆ m_handle

void* CASM::RuntimeLibrary::m_handle
private

Definition at line 109 of file RuntimeLibrary.hh.

◆ m_so_options

std::string CASM::RuntimeLibrary::m_so_options
private

Definition at line 107 of file RuntimeLibrary.hh.


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