From f7b62e46454268aff9d252d4822f38a06638f083 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Thu, 16 Feb 2023 00:40:43 -0300 Subject: [PATCH] refactor select and insert methods to be less redundant --- src/knowledge_base.cpp | 12 ++++++------ src/models/entity.cpp | 4 ++-- src/models/entity.h | 4 ++-- src/models/fact.cpp | 4 ++-- src/models/fact.h | 4 ++-- src/models/verb.cpp | 4 ++-- src/models/verb.h | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/knowledge_base.cpp b/src/knowledge_base.cpp index f9e3ae9..cd4aa6f 100644 --- a/src/knowledge_base.cpp +++ b/src/knowledge_base.cpp @@ -87,7 +87,7 @@ void obelisk::KnowledgeBase::addEntities(std::vector& entities) { try { - entity.insertEntity(dbConnection_); + entity.insert(dbConnection_); } catch (obelisk::DatabaseConstraintException& exception) { @@ -106,7 +106,7 @@ void obelisk::KnowledgeBase::addVerbs(std::vector& verbs) { try { - verb.insertVerb(dbConnection_); + verb.insert(dbConnection_); } catch (obelisk::DatabaseConstraintException& exception) { @@ -125,7 +125,7 @@ void obelisk::KnowledgeBase::addFacts(std::vector& facts) { try { - fact.insertFact(dbConnection_); + fact.insert(dbConnection_); } catch (obelisk::DatabaseConstraintException& exception) { @@ -142,17 +142,17 @@ void obelisk::KnowledgeBase::addFacts(std::vector& facts) void obelisk::KnowledgeBase::getEntity(obelisk::Entity& entity) { - entity.selectEntity(dbConnection_); + entity.select(dbConnection_); } void obelisk::KnowledgeBase::getVerb(obelisk::Verb& verb) { - verb.selectVerb(dbConnection_); + verb.select(dbConnection_); } void obelisk::KnowledgeBase::getFact(obelisk::Fact& fact) { - fact.selectFact(dbConnection_); + fact.select(dbConnection_); } void obelisk::KnowledgeBase::getFloat(float& result1, float& result2, double var) diff --git a/src/models/entity.cpp b/src/models/entity.cpp index f051372..1ca6f7c 100644 --- a/src/models/entity.cpp +++ b/src/models/entity.cpp @@ -12,7 +12,7 @@ const char* obelisk::Entity::createTable() )"; } -void obelisk::Entity::selectEntity(sqlite3* dbConnection) +void obelisk::Entity::select(sqlite3* dbConnection) { if (dbConnection == nullptr) { @@ -76,7 +76,7 @@ void obelisk::Entity::selectEntity(sqlite3* dbConnection) } } -void obelisk::Entity::insertEntity(sqlite3* dbConnection) +void obelisk::Entity::insert(sqlite3* dbConnection) { if (dbConnection == nullptr) { diff --git a/src/models/entity.h b/src/models/entity.h index 7ede503..1796dd9 100644 --- a/src/models/entity.h +++ b/src/models/entity.h @@ -112,7 +112,7 @@ namespace obelisk * * @param[in] dbConnection The database connection to use. */ - void selectEntity(sqlite3* dbConnection); + void select(sqlite3* dbConnection); /** * @brief Insert an Entity into the database based on the object's @@ -120,7 +120,7 @@ namespace obelisk * * @param[in] dbConnection The database connection to use. */ - void insertEntity(sqlite3* dbConnection); + void insert(sqlite3* dbConnection); }; } // namespace obelisk diff --git a/src/models/fact.cpp b/src/models/fact.cpp index 69c1feb..cddc7e3 100644 --- a/src/models/fact.cpp +++ b/src/models/fact.cpp @@ -19,7 +19,7 @@ const char* obelisk::Fact::createTable() )"; } -void obelisk::Fact::selectFact(sqlite3* dbConnection) +void obelisk::Fact::select(sqlite3* dbConnection) { if (dbConnection == nullptr) { @@ -126,7 +126,7 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection) } } -void obelisk::Fact::insertFact(sqlite3* dbConnection) +void obelisk::Fact::insert(sqlite3* dbConnection) { if (dbConnection == nullptr) { diff --git a/src/models/fact.h b/src/models/fact.h index 94c4f17..76233fa 100644 --- a/src/models/fact.h +++ b/src/models/fact.h @@ -76,8 +76,8 @@ namespace obelisk bool& getIsTrue(); void setIsTrue(bool isTrue); - void selectFact(sqlite3* dbConnection); - void insertFact(sqlite3* dbConnection); + void select(sqlite3* dbConnection); + void insert(sqlite3* dbConnection); }; } // namespace obelisk diff --git a/src/models/verb.cpp b/src/models/verb.cpp index e47d5cd..b91503c 100644 --- a/src/models/verb.cpp +++ b/src/models/verb.cpp @@ -14,7 +14,7 @@ const char* obelisk::Verb::createTable() )"; } -void obelisk::Verb::selectVerb(sqlite3* dbConnection) +void obelisk::Verb::select(sqlite3* dbConnection) { if (dbConnection == nullptr) { @@ -76,7 +76,7 @@ void obelisk::Verb::selectVerb(sqlite3* dbConnection) } } -void obelisk::Verb::insertVerb(sqlite3* dbConnection) +void obelisk::Verb::insert(sqlite3* dbConnection) { if (dbConnection == nullptr) { diff --git a/src/models/verb.h b/src/models/verb.h index 5e9a042..be6599e 100644 --- a/src/models/verb.h +++ b/src/models/verb.h @@ -112,14 +112,14 @@ namespace obelisk * * @param[in] dbConnection The database connection to use. */ - void selectVerb(sqlite3* dbConnection); + void select(sqlite3* dbConnection); /** * @brief Insert a new verb into the KnowledgeBase. * * @param[in] dbConnection The database connection to use. */ - void insertVerb(sqlite3* dbConnection); + void insert(sqlite3* dbConnection); }; } // namespace obelisk