develop #15

Merged
cromer merged 64 commits from develop into master 2023-02-23 01:11:48 -03:00
10 changed files with 197 additions and 0 deletions
Showing only changes of commit 0e9cc0f832 - Show all commits

View File

@ -1,4 +1,5 @@
project('obelisk', project('obelisk',
'c',
'cpp', 'cpp',
version : '1.0.0', version : '1.0.0',
license : 'BSD-3-Clause', license : 'BSD-3-Clause',

View File

@ -1,3 +1,6 @@
#ifndef OBELISK_INCLUDE_OBELISK_H
#define OBELISK_INCLUDE_OBELISK_H
#include <string> #include <string>
/** /**
@ -15,6 +18,18 @@ namespace obelisk
class Obelisk class Obelisk
{ {
public: public:
/**
* @brief Construct a new Obelisk object.
*
*/
Obelisk() = default;
/**
* @brief Destroy the Obelisk object.
*
*/
~Obelisk() = default;
/** /**
* @brief Get the obelisk version. * @brief Get the obelisk version.
* *
@ -28,5 +43,34 @@ namespace obelisk
* @return int The version. * @return int The version.
*/ */
int getLibVersion(); 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 } // namespace obelisk
#endif

View File

@ -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

View File

@ -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

View File

@ -10,6 +10,8 @@ subdir('models')
obelisk_lib_sources = files( obelisk_lib_sources = files(
'obelisk.cpp', 'obelisk.cpp',
'obelisk.c',
'obelisk_wrapper.cpp',
'knowledge_base.cpp' 'knowledge_base.cpp'
) )

23
src/lib/obelisk.c Normal file
View File

@ -0,0 +1,23 @@
#include "obelisk_c.h"
#include "obelisk_wrapper.h"
#include <stdlib.h>
#include <string.h>
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;
}

View File

@ -10,3 +10,15 @@ int obelisk::Obelisk::getLibVersion()
{ {
return obelisk::soVersion; 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)
{
}

View File

@ -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<CObelisk*>(obelisk);
}
const char* call_obelisk_getVersion(CObelisk* p_obelisk)
{
obelisk::Obelisk* obelisk
= reinterpret_cast<obelisk::Obelisk*>(p_obelisk);
return obelisk->getVersion().c_str();
}
int call_obelisk_getLibVersion(CObelisk* p_obelisk)
{
obelisk::Obelisk* obelisk
= reinterpret_cast<obelisk::Obelisk*>(p_obelisk);
return obelisk->getLibVersion();
}
void destroy_obelisk(CObelisk* p_obelisk)
{
obelisk::Obelisk* obelisk
= reinterpret_cast<obelisk::Obelisk*>(p_obelisk);
delete obelisk;
}
};

View File

@ -1,3 +1,6 @@
#ifndef OBELISK_VERSION_H
#define OBELISK_VERSION_H
namespace obelisk namespace obelisk
{ {
/** /**
@ -14,3 +17,5 @@ namespace obelisk
const int soVersion = @so_version@; const int soVersion = @so_version@;
// clang-format on // clang-format on
} // namespace obelisk } // namespace obelisk
#endif

View File

@ -1,3 +1,6 @@
#ifndef OBELISK_MAIN_H
#define OBELISK_MAIN_H
#include <getopt.h> #include <getopt.h>
/** /**
@ -46,3 +49,5 @@ Options:
int mainLoop(const std::vector<std::string> &sourceFiles, int mainLoop(const std::vector<std::string> &sourceFiles,
const std::string &kbFile); const std::string &kbFile);
} // namespace obelisk } // namespace obelisk
#endif