#include #include #include #include #include #include #include "example/db.hpp" #include "dynamic_lib.hpp" using std::cout; using std::endl; void write(const std::string& path, const std::string& content) { ofstream stream; stream.open (path.c_str()); stream << content; stream.close(); } std::string join(const std::vector& strings, const char *separator) { std::ostringstream oss; std::copy(strings.begin(), strings.end(), std::ostream_iterator(oss, separator)); return oss.str(); } template std::string prints(const Args&... args) { std::vector strings = {args...}; return join(strings, " "); } // dependent on specific dynamic code // "configuration" of DynamicLib // DynamicLib class MemgraphDynamicLib { public: const static std::string produce_name; const static std::string destruct_name; using produce = produce_t; using destruct = destruct_t; }; const std::string MemgraphDynamicLib::produce_name = "produce"; const std::string MemgraphDynamicLib::destruct_name = "destruct"; int main() { // -- compile example // string tmp_file_path = "tmp/tmp.cpp"; // string tmp_so_path = "tmp/tmp.so"; // string for_compile = "#include \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()); // -- end compile example // -- load example using db_lib = DynamicLib; db_lib mysql_db("./tmp/mysql.so"); mysql_db.load(); auto mysql = mysql_db.produce_method(); if (mysql) { mysql->name(); } 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); return 0; }