CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
CASM::RuntimeLibrary Class Reference

#include <RuntimeLibrary.hh>

+ Inheritance diagram for CASM::RuntimeLibrary:

Detailed Description

Write, compile, load and use code at runtime.

Definition at line 17 of file RuntimeLibrary.hh.

Public Member Functions

 RuntimeLibrary (std::string _filename_base, std::string _compile_options, std::string _so_options, std::string compile_msg, const Logging &logging=Logging())
 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...
 
Loglog () const
 
Logdebug_log () const
 
Logerr_log () const
 

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...
 
static Logging null ()
 

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

CASM::RuntimeLibrary::RuntimeLibrary ( std::string  _filename_base,
std::string  _compile_options,
std::string  _so_options,
std::string  compile_msg,
const Logging logging = Logging() 
)

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

Definition at line 8 of file RuntimeLibrary.cc.

CASM::RuntimeLibrary::~RuntimeLibrary ( )

Definition at line 64 of file RuntimeLibrary.cc.

Member Function Documentation

void CASM::RuntimeLibrary::_close ( )
private

Close the current library.

This is also done on destruction.

Definition at line 120 of file RuntimeLibrary.cc.

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 81 of file RuntimeLibrary.cc.

void CASM::RuntimeLibrary::_load ( )
private

Load a library with a given name.

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

Definition at line 108 of file RuntimeLibrary.cc.

Log& CASM::Logging::debug_log ( ) const
inlineinherited

Definition at line 259 of file Log.hh.

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 332 of file RuntimeLibrary.cc.

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 361 of file RuntimeLibrary.cc.

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 274 of file RuntimeLibrary.cc.

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 303 of file RuntimeLibrary.cc.

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 252 of file RuntimeLibrary.cc.

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

Default c++ compiler options.

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

Definition at line 259 of file RuntimeLibrary.cc.

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 266 of file RuntimeLibrary.cc.

Log& CASM::Logging::err_log ( ) const
inlineinherited

Definition at line 263 of file Log.hh.

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 38 of file RuntimeLibrary.hh.

Log& CASM::Logging::log ( ) const
inlineinherited

Definition at line 255 of file Log.hh.

static Logging CASM::Logging::null ( )
inlinestaticinherited

Definition at line 267 of file Log.hh.

void CASM::RuntimeLibrary::rm ( )

Remove the current library and source code.

Definition at line 128 of file RuntimeLibrary.cc.

Member Data Documentation

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

Definition at line 88 of file RuntimeLibrary.hh.

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

Definition at line 87 of file RuntimeLibrary.hh.

void* CASM::RuntimeLibrary::m_handle
private

Definition at line 91 of file RuntimeLibrary.hh.

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

Definition at line 89 of file RuntimeLibrary.hh.


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