finally, first working prototype
This commit is contained in:
parent
d67a3c32eb
commit
5f90a21fe6
11 changed files with 193 additions and 112 deletions
23
database.cpp
23
database.cpp
|
@ -18,7 +18,7 @@
|
|||
#include "exceptions.h"
|
||||
#include "table.h"
|
||||
|
||||
Core::DataBase::DataBase(const QString& p_name, uint16_t mapSize):
|
||||
DataBase::DataBase(const QString& p_name, uint16_t mapSize):
|
||||
name(p_name.toStdString()),
|
||||
opened(false),
|
||||
size(mapSize),
|
||||
|
@ -27,7 +27,7 @@ Core::DataBase::DataBase(const QString& p_name, uint16_t mapSize):
|
|||
{
|
||||
}
|
||||
|
||||
Core::DataBase::~DataBase()
|
||||
DataBase::~DataBase()
|
||||
{
|
||||
close();
|
||||
for (const std::pair<const std::string, _Table*>& pair : tables) {
|
||||
|
@ -35,7 +35,7 @@ Core::DataBase::~DataBase()
|
|||
}
|
||||
}
|
||||
|
||||
void Core::DataBase::close()
|
||||
void DataBase::close()
|
||||
{
|
||||
if (opened) {
|
||||
for (const std::pair<const std::string, _Table*>& pair : tables) {
|
||||
|
@ -47,7 +47,7 @@ void Core::DataBase::close()
|
|||
}
|
||||
}
|
||||
|
||||
void Core::DataBase::open()
|
||||
void DataBase::open()
|
||||
{
|
||||
if (!opened) {
|
||||
mdb_env_create(&environment);
|
||||
|
@ -71,7 +71,7 @@ void Core::DataBase::open()
|
|||
|
||||
for (const std::pair<const std::string, _Table*>& pair : tables) {
|
||||
_Table* table = pair.second;
|
||||
int rc = mdb_dbi_open(txn, pair.first.c_str(), MDB_CREATE, &table->dbi);
|
||||
int rc = table->createTable(txn);
|
||||
if (rc) {
|
||||
throw Unknown(name, mdb_strerror(rc));
|
||||
}
|
||||
|
@ -82,18 +82,9 @@ void Core::DataBase::open()
|
|||
}
|
||||
}
|
||||
|
||||
QString Core::DataBase::getName() const
|
||||
QString DataBase::getName() const
|
||||
{
|
||||
return QString::fromStdString(name);
|
||||
}
|
||||
|
||||
template <class K, class V>
|
||||
Core::DataBase::Table<K, V>* Core::DataBase::addTable(const QString& p_name) {
|
||||
std::string nm = p_name.toStdString();
|
||||
if (opened) {
|
||||
throw Core::DataBase::Opened(name, nm);
|
||||
}
|
||||
Core::DataBase::Table<K, V>* table = new Core::DataBase::Table<K, V>(nm, this);
|
||||
tables.insert(std::make_pair(nm, table));
|
||||
return table;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue