2015-10-22 06:17:40 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
|
|
|
#include <iterator>
|
|
|
|
#include <cstdlib>
|
2015-10-23 05:54:28 +08:00
|
|
|
#include "example/db.hpp"
|
2015-10-25 23:11:52 +08:00
|
|
|
#include "dynamic_lib.hpp"
|
2016-02-08 05:56:52 +08:00
|
|
|
#include "utils/string/file.hpp"
|
2015-10-22 06:17:40 +08:00
|
|
|
|
2015-10-25 23:11:52 +08:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2015-10-22 06:17:40 +08:00
|
|
|
|
2015-10-25 23:11:52 +08:00
|
|
|
// dependent on specific dynamic code
|
|
|
|
// "configuration" of DynamicLib
|
|
|
|
// DynamicLib<MemgraphDynamicLib>
|
|
|
|
class MemgraphDynamicLib
|
2015-10-23 05:54:28 +08:00
|
|
|
{
|
2015-10-25 23:11:52 +08:00
|
|
|
public:
|
|
|
|
const static std::string produce_name;
|
|
|
|
const static std::string destruct_name;
|
2015-11-01 19:45:27 +08:00
|
|
|
using produce = produce_t;
|
|
|
|
using destruct = destruct_t;
|
2015-10-25 23:11:52 +08:00
|
|
|
};
|
|
|
|
const std::string MemgraphDynamicLib::produce_name = "produce";
|
|
|
|
const std::string MemgraphDynamicLib::destruct_name = "destruct";
|
2015-10-23 05:54:28 +08:00
|
|
|
|
2016-02-08 05:56:52 +08:00
|
|
|
int main()
|
2015-10-22 06:17:40 +08:00
|
|
|
{
|
2015-10-25 23:11:52 +08:00
|
|
|
// -- compile example
|
2015-10-23 05:54:28 +08:00
|
|
|
// string tmp_file_path = "tmp/tmp.cpp";
|
|
|
|
// string tmp_so_path = "tmp/tmp.so";
|
|
|
|
// string for_compile = "#include <iostream>\nint main() { std::cout << \"test\" << std::endl; return 0; }";
|
|
|
|
|
|
|
|
// write(tmp_file_path, for_compile);
|
|
|
|
// string test_command = prints("clang++", tmp_file_path, "-o", "test.out");
|
|
|
|
// system(test_command.c_str());
|
2015-10-25 23:11:52 +08:00
|
|
|
// -- end compile example
|
|
|
|
|
|
|
|
// -- load example
|
|
|
|
using db_lib = DynamicLib<MemgraphDynamicLib>;
|
2015-10-22 06:17:40 +08:00
|
|
|
|
2015-10-25 23:11:52 +08:00
|
|
|
db_lib mysql_db("./tmp/mysql.so");
|
|
|
|
mysql_db.load();
|
|
|
|
auto mysql = mysql_db.produce_method();
|
2015-10-23 05:54:28 +08:00
|
|
|
if (mysql) {
|
|
|
|
mysql->name();
|
|
|
|
}
|
2015-10-25 23:11:52 +08:00
|
|
|
mysql_db.destruct_method(mysql);
|
|
|
|
|
|
|
|
db_lib memsql_db("./tmp/memsql.so");
|
|
|
|
memsql_db.load();
|
|
|
|
auto memsql = memsql_db.produce_method();
|
|
|
|
if (memsql) {
|
|
|
|
memsql->name();
|
|
|
|
}
|
|
|
|
memsql_db.destruct_method(memsql);
|
2015-10-22 06:17:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|