obelisk/src/knowledge_base.h

77 lines
2.0 KiB
C
Raw Normal View History

#ifndef OBELISK_KNOWLEDGE_BASE_H
#define OBELISK_KNOWLEDGE_BASE_H
2022-11-26 00:32:06 -03:00
#include "models/entity.h"
#include "models/fact.h"
#include "models/verb.h"
#include <sqlite3.h>
2022-11-01 01:04:41 -03:00
#include <functional>
#include <iostream>
2022-11-26 00:32:06 -03:00
#include <memory>
#include <string>
namespace obelisk
{
class KnowledgeBase
{
private:
const int DEFAULT_FLAGS
= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
const char* filename_;
sqlite3* dbConnection_ = nullptr;
int flags_;
void logSqliteError(int result);
void enableForeignKeys();
2022-11-01 01:04:41 -03:00
void createTable(std::function<const char*()> function);
public:
KnowledgeBase(const char* filename, int flags);
2022-11-26 00:32:06 -03:00
KnowledgeBase(const char* filename) :
KnowledgeBase(filename,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)
{
}
~KnowledgeBase();
void addEntities(std::vector<obelisk::Entity>& entities);
void addVerbs(std::vector<obelisk::Verb>& verbs);
void addFacts(std::vector<obelisk::Fact>& facts);
void getEntity(obelisk::Entity& entity);
void getVerb(obelisk::Verb& verb);
void getFact(obelisk::Fact& fact);
2022-11-27 23:58:40 -03:00
2022-11-01 01:04:41 -03:00
void getDouble(double& result, float var1, float var2);
void getFloat(float& result1, float& result2, double var);
};
class KnowledgeBaseException : public std::exception
{
private:
2022-11-01 01:04:41 -03:00
const std::string errorMessage_;
public:
2022-11-01 01:17:45 -03:00
KnowledgeBaseException() :
2022-11-01 01:38:54 -03:00
errorMessage_("an unknown error ocurred")
2022-11-01 01:17:45 -03:00
{
}
2022-11-01 01:04:41 -03:00
KnowledgeBaseException(const std::string& errorMessage) :
errorMessage_(errorMessage)
{
}
const char* what() const noexcept
{
return errorMessage_.c_str();
}
};
} // namespace obelisk
#endif