Interface to dynamically linked parametrizations. More...
#include <BasePlugin.h>
Public Member Functions | |
BasePlugin (SQLite3DB &db, const std::string &library, const std::string &function_name, const std::string &select_query, const std::string &output_table, const std::vector< std::string > outputs, const std::vector< std::string > reference_keys={"ref_id"}) | |
Constructor. More... | |
BasePlugin (BasePlugin &)=delete | |
virtual | ~BasePlugin () |
void | execute () override |
Execute the external function and copies the output in a new table. More... | |
Public Member Functions inherited from SQLamarr::BaseSqlInterface | |
BaseSqlInterface (SQLite3DB &db) | |
Constructor, acquiring the database without ownership. More... | |
virtual | ~BaseSqlInterface () |
void | sync_database (const std::string &db_uri) |
void | invalidate_cache (void) |
Invalidate the cache of the queries. More... | |
Protected Member Functions | |
virtual void | eval_parametrization (float *output, const float *input)=0 |
Evaluate the external parametrization. More... | |
template<typename Func_t > | |
Func_t | load_func (const std::string &fname) |
Load a generic-typed function from an external library. More... | |
Protected Member Functions inherited from SQLamarr::BaseSqlInterface | |
sqlite3_stmt * | get_statement (const std::string &name, const std::string &query) |
Creates or retrieve from cache a statement. More... | |
void | begin_transaction () |
Begin an SQL transaction stopping update to disk util end_transaction() is issued More... | |
void | end_transaction () |
End an SQL transaction re-enabling disk updates. More... | |
int | last_insert_row () |
Return the index of the last rows inserted in any table. More... | |
void | using_sql_function (const std::string &name, int argc, void(*xFunc)(sqlite3_context *, int, sqlite3_value **)) |
Register a static function in DB, enabling usage from SQL. More... | |
bool | exec_stmt (sqlite3_stmt *) |
Execute a statement, possibly throwing an exception on failure. More... | |
Additional Inherited Members | |
Protected Attributes inherited from SQLamarr::BaseSqlInterface | |
SQLite3DB & | m_database |
Reference to the SQLite database (not owned). More... | |
Interface to dynamically linked parametrizations.
A SQLamarr BasePlugin
is a parametrization defined in a shared object dynamically linked at run time. For an example to generate such parametrizations, please refer to the scikinC project.
The BasePlugin
class is an abstract class defining a generic interface. Client applications are expected to use specialized plugins, obtained by defining the function signature and its call.
In particular, the function eval_parametrization
is a pure virtual function that must be overridden with the logic to call the dynamically loaded function with the appropriate signature.
The BasePlugin
class implements selecting the input columns from the database, links the external library based on its path and the name of the function and finally creates a table with the output.
If a table with the same name as the output table exists in the database, it is overwritten without warning.
In order to match the output table to the input, one or more integer variables can be defined as reference keys which are not used as inputs for the parametrization, but transparently copied to the output table.
float* (float*, const float*)
float* (float*, const float*)
Definition at line 59 of file BasePlugin.h.
SQLamarr::BasePlugin::BasePlugin | ( | SQLite3DB & | db, |
const std::string & | library, | ||
const std::string & | function_name, | ||
const std::string & | select_query, | ||
const std::string & | output_table, | ||
const std::vector< std::string > | outputs, | ||
const std::vector< std::string > | reference_keys = {"ref_id"} |
||
) |
Constructor.
db | Reference to the database, passed without ownership |
library | Path to the shared object (library). If in CWD, prepend "./". |
function_name | Linking symbol of the target function as set at compile-time |
select_query | SQL Query selecting the inputs. Number and order of the parameters columns are relevant. Names not listed in `reference_keys` are ignored. |
output_table | SQL name of the output table. Must be alphanumeric. |
outputs | Vector of column names for the output table. The order must match the output produced by the compiled parametrization. |
reference_keys | List of column names ignored. |
Definition at line 29 of file BasePlugin.cpp.
|
delete |
|
inlinevirtual |
Definition at line 86 of file BasePlugin.h.
|
protectedpure virtual |
Evaluate the external parametrization.
This function can be overridden to provide custom preprocessing and postprocessing steps, or to link to functions with custom signature.
|
overridevirtual |
Execute the external function and copies the output in a new table.
Implements SQLamarr::Transformer.
Definition at line 124 of file BasePlugin.cpp.
|
protected |
Load a generic-typed function from an external library.
Definition at line 122 of file BasePlugin.h.