diff --git a/meson.build b/meson.build index 4f3a936..e27febf 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,5 @@ project('obelisk', + 'c', 'cpp', version : '1.0.0', license : 'BSD-3-Clause', diff --git a/src/lib/include/obelisk.h b/src/lib/include/obelisk.h index b06eb8b..afa02ad 100644 --- a/src/lib/include/obelisk.h +++ b/src/lib/include/obelisk.h @@ -1,3 +1,6 @@ +#ifndef OBELISK_INCLUDE_OBELISK_H +#define OBELISK_INCLUDE_OBELISK_H + #include /** @@ -15,6 +18,18 @@ namespace obelisk class Obelisk { public: + /** + * @brief Construct a new Obelisk object. + * + */ + Obelisk() = default; + + /** + * @brief Destroy the Obelisk object. + * + */ + ~Obelisk() = default; + /** * @brief Get the obelisk version. * @@ -28,5 +43,34 @@ namespace obelisk * @return int The version. */ int getLibVersion(); + + /** + * @brief Query the Obelisk KnowledgeBase to see if the Fact is true + * or not. + * + * @param[in] leftEntity The left entity. + * @param[in] verb The verb. + * @param[in] rightEntity The right entity. + * @return double Returns a value between 0 and 1 depending on + * whether it is true or false. + */ + double query(const std::string& leftEntity, + const std::string& verb, + const std::string& rightEntity); + + /** + * @brief Query the Obelisk KnowledgeBase and return the suggested + * action to take. + * + * @param[in] leftEntity The left entity. + * @param[in] verb The verb. + * @param[in] rightEntity The right entity. + * @return std::string Returns the suggested action. + */ + std::string query_action(const std::string& leftEntity, + const std::string& verb, + const std::string& rightEntity); }; } // namespace obelisk + +#endif diff --git a/src/lib/include/obelisk_c.h b/src/lib/include/obelisk_c.h new file mode 100644 index 0000000..616b7e2 --- /dev/null +++ b/src/lib/include/obelisk_c.h @@ -0,0 +1,28 @@ +#ifndef OBELISK_INCLUDE_OBELISK_PROGRAM_H +#define OBELISK_INCLUDE_OBELISK_PROGRAM_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief Get the obelisk version. + * + * @return const char* Returns a string containing the version. This must be + * freed by the caller. + */ + extern const char* obelisk_get_version(); + + /** + * @brief Get the obelisk library so version. + * + * @return int Returns the so version. + */ + extern int obelisk_get_lib_version(); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/src/lib/include/obelisk_wrapper.h b/src/lib/include/obelisk_wrapper.h new file mode 100644 index 0000000..737c129 --- /dev/null +++ b/src/lib/include/obelisk_wrapper.h @@ -0,0 +1,45 @@ +#ifndef OBELISK_INCLUDE_OBELISK_WRAPPER_H +#define OBELISK_INCLUDE_OBELISK_WRAPPER_H + +typedef struct CObelisk CObelisk; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief Create a obelisk object. + * + * @return CObelisk* Returns the obelisk object. + */ + CObelisk *create_obelisk(); + + /** + * @brief Calls the obelisk method getVersion. + * + * @param[in] p_obelisk The obelisk object pointer. + * @return const char* Returns the version. Must be freed by caller. + */ + const char *call_obelisk_getVersion(CObelisk *p_obelisk); + + /** + * @brief Calls the obelisk method getLibVersion. + * + * @param[in] p_obelisk The obelisk object pointer. + * @return int Returns the library so version. + */ + int call_obelisk_getLibVersion(CObelisk *p_obelisk); + + /** + * @brief Delete a obelisk object. + * + * @param[in] p_obelisk The obelisk object pointer. + */ + void destroy_obelisk(CObelisk *p_obelisk); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/src/lib/meson.build b/src/lib/meson.build index 30dff63..70f39d5 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -10,6 +10,8 @@ subdir('models') obelisk_lib_sources = files( 'obelisk.cpp', + 'obelisk.c', + 'obelisk_wrapper.cpp', 'knowledge_base.cpp' ) diff --git a/src/lib/obelisk.c b/src/lib/obelisk.c new file mode 100644 index 0000000..228d9d2 --- /dev/null +++ b/src/lib/obelisk.c @@ -0,0 +1,23 @@ +#include "obelisk_c.h" +#include "obelisk_wrapper.h" + +#include +#include + +const char* obelisk_get_version() +{ + CObelisk* obelisk = create_obelisk(); + size_t len = strlen(call_obelisk_getVersion(obelisk)) + 1; + char* version = malloc(len); + memcpy(version, call_obelisk_getVersion(obelisk), len); + destroy_obelisk(obelisk); + return version; +} + +int obelisk_get_lib_version() +{ + CObelisk* obelisk = create_obelisk(); + int version = call_obelisk_getLibVersion(obelisk); + destroy_obelisk(obelisk); + return version; +} diff --git a/src/lib/obelisk.cpp b/src/lib/obelisk.cpp index e5b979a..c0eb5bf 100644 --- a/src/lib/obelisk.cpp +++ b/src/lib/obelisk.cpp @@ -10,3 +10,15 @@ int obelisk::Obelisk::getLibVersion() { return obelisk::soVersion; } + +double obelisk::Obelisk::query(const std::string& leftEntity, + const std::string& verb, + const std::string& rightEntity) +{ +} + +std::string obelisk::Obelisk::query_action(const std::string& leftEntity, + const std::string& verb, + const std::string& rightEntity) +{ +} diff --git a/src/lib/obelisk_wrapper.cpp b/src/lib/obelisk_wrapper.cpp new file mode 100644 index 0000000..0720ae1 --- /dev/null +++ b/src/lib/obelisk_wrapper.cpp @@ -0,0 +1,32 @@ +#include "obelisk.h" +#include "obelisk_wrapper.h" + +extern "C" +{ + CObelisk* create_obelisk() + { + obelisk::Obelisk* obelisk = new obelisk::Obelisk(); + return reinterpret_cast(obelisk); + } + + const char* call_obelisk_getVersion(CObelisk* p_obelisk) + { + obelisk::Obelisk* obelisk + = reinterpret_cast(p_obelisk); + return obelisk->getVersion().c_str(); + } + + int call_obelisk_getLibVersion(CObelisk* p_obelisk) + { + obelisk::Obelisk* obelisk + = reinterpret_cast(p_obelisk); + return obelisk->getLibVersion(); + } + + void destroy_obelisk(CObelisk* p_obelisk) + { + obelisk::Obelisk* obelisk + = reinterpret_cast(p_obelisk); + delete obelisk; + } +}; diff --git a/src/lib/version.h.in b/src/lib/version.h.in index b6b0867..c9aee59 100644 --- a/src/lib/version.h.in +++ b/src/lib/version.h.in @@ -1,3 +1,6 @@ +#ifndef OBELISK_VERSION_H +#define OBELISK_VERSION_H + namespace obelisk { /** @@ -14,3 +17,5 @@ namespace obelisk const int soVersion = @so_version@; // clang-format on } // namespace obelisk + +#endif diff --git a/src/main.h b/src/main.h index 38e7a29..b330b53 100644 --- a/src/main.h +++ b/src/main.h @@ -1,3 +1,6 @@ +#ifndef OBELISK_MAIN_H +#define OBELISK_MAIN_H + #include /** @@ -46,3 +49,5 @@ Options: int mainLoop(const std::vector &sourceFiles, const std::string &kbFile); } // namespace obelisk + +#endif