diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1eb24f6..61b7919 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)
-project(storage VERSION 0.0.1 LANGUAGES CXX)
+project(lmdbal VERSION 0.2.0 LANGUAGES CXX)
cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0079 NEW)
@@ -28,63 +28,32 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()
-set(SOURCES
- exceptions.cpp
- storage.cpp
- database.cpp
-)
-
-set(HEADERS
- database.h
- exceptions.h
- storage.h
- storage.hpp
- cache.h
- cache.hpp
- serializer.h
- serializer.hpp
- serializer_uint8.hpp
- serializer_uint16.hpp
- serializer_uint32.hpp
- serializer_uint64.hpp
- serializer_int8.hpp
- serializer_int16.hpp
- serializer_int32.hpp
- serializer_int64.hpp
- serializer_float.hpp
- serializer_double.hpp
- serializer_stdstring.hpp
- serializer_qstring.hpp
- serializer_qbytearray.hpp
- operators.hpp
-)
-
if (BUILD_STATIC)
- add_library(storage STATIC ${SOURCES})
+ add_library(lmdbal STATIC ${SOURCES})
else ()
- add_library(storage SHARED ${SOURCES})
+ add_library(lmdbal SHARED ${SOURCES})
endif()
+add_subdirectory(src)
+
if (BUILD_TESTS)
add_subdirectory(test)
endif ()
-set_target_properties(storage PROPERTIES PUBLIC_HEADER "${HEADERS}")
+target_include_directories(lmdbal PUBLIC ${CMAKE_SOURCE_DIR}/src)
+target_include_directories(lmdbal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
+target_include_directories(lmdbal PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
-target_include_directories(storage PUBLIC ${CMAKE_SOURCE_DIR})
-target_include_directories(storage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_include_directories(storage PRIVATE ${Qt${QT_VERSION_MAJOR}_INCLUDE_DIRS})
-target_include_directories(storage PRIVATE ${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS})
-
-target_link_libraries(storage
+target_link_libraries(lmdbal
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
)
-target_link_libraries(storage PRIVATE lmdb)
+target_link_libraries(lmdbal PRIVATE lmdb)
-install(TARGETS storage
+install(TARGETS lmdbal
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/storage
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/storage
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lmdbal
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdbal
)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..f5ca470
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,37 @@
+set(SOURCES
+ exceptions.cpp
+ storage.cpp
+ base.cpp
+)
+
+set(HEADERS
+ base.h
+ exceptions.h
+ storage.h
+ storage.hpp
+ cache.h
+ cache.hpp
+ serializer.h
+ serializer.hpp
+ serializer_uint8.hpp
+ serializer_uint16.hpp
+ serializer_uint32.hpp
+ serializer_uint64.hpp
+ serializer_int8.hpp
+ serializer_int16.hpp
+ serializer_int32.hpp
+ serializer_int64.hpp
+ serializer_float.hpp
+ serializer_double.hpp
+ serializer_stdstring.hpp
+ serializer_qstring.hpp
+ serializer_qbytearray.hpp
+ operators.hpp
+)
+
+target_sources(lmdbal PRIVATE
+ ${SOURCES}
+ ${HEADERS}
+)
+
+set_target_properties(lmdbal PROPERTIES PUBLIC_HEADER "${HEADERS}")
diff --git a/database.cpp b/src/base.cpp
similarity index 73%
rename from database.cpp
rename to src/base.cpp
index 87f4419..1f9003a 100644
--- a/database.cpp
+++ b/src/base.cpp
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-#include "database.h"
+#include "base.h"
#include "exceptions.h"
#include "storage.h"
-LMDBDataBase::DataBase::DataBase(const QString& p_name, uint16_t mapSize):
+LMDBAL::Base::Base(const QString& p_name, uint16_t mapSize):
name(p_name.toStdString()),
opened(false),
size(mapSize),
@@ -27,19 +27,19 @@ LMDBDataBase::DataBase::DataBase(const QString& p_name, uint16_t mapSize):
transactions(new Transactions())
{}
-LMDBDataBase::DataBase::~DataBase() {
+LMDBAL::Base::~Base() {
close();
delete transactions;
- for (const std::pair& pair : tables)
+ for (const std::pair& pair : tables)
delete pair.second;
}
-void LMDBDataBase::DataBase::close() {
+void LMDBAL::Base::close() {
if (opened) {
- for (const std::pair& pair : tables) {
- StorageBase* table = pair.second;
+ for (const std::pair& pair : tables) {
+ iStorage* table = pair.second;
mdb_dbi_close(environment, table->dbi);
}
mdb_env_close(environment);
@@ -47,7 +47,7 @@ void LMDBDataBase::DataBase::close() {
}
}
-void LMDBDataBase::DataBase::open() {
+void LMDBAL::Base::open() {
if (!opened) {
mdb_env_create(&environment);
QString path = createDirectory();
@@ -59,8 +59,8 @@ void LMDBDataBase::DataBase::open() {
MDB_txn *txn;
mdb_txn_begin(environment, NULL, 0, &txn);
- for (const std::pair& pair : tables) {
- StorageBase* table = pair.second;
+ for (const std::pair& pair : tables) {
+ iStorage* table = pair.second;
int rc = table->createTable(txn);
if (rc)
throw Unknown(name, mdb_strerror(rc));
@@ -70,7 +70,7 @@ void LMDBDataBase::DataBase::open() {
}
}
-bool LMDBDataBase::DataBase::removeDirectory() {
+bool LMDBAL::Base::removeDirectory() {
if (opened)
throw Opened(name, "remove database directory");
@@ -84,7 +84,7 @@ bool LMDBDataBase::DataBase::removeDirectory() {
return true;
}
-QString LMDBDataBase::DataBase::createDirectory() {
+QString LMDBAL::Base::createDirectory() {
if (opened)
throw Opened(name, "create database directory");
@@ -101,13 +101,13 @@ QString LMDBDataBase::DataBase::createDirectory() {
return path;
}
-QString LMDBDataBase::DataBase::getName() const {
+QString LMDBAL::Base::getName() const {
return QString::fromStdString(name);}
-bool LMDBDataBase::DataBase::ready() const {
+bool LMDBAL::Base::ready() const {
return opened;}
-void LMDBDataBase::DataBase::drop() {
+void LMDBAL::Base::drop() {
if (!opened)
throw Closed("drop", name);
@@ -116,7 +116,7 @@ void LMDBDataBase::DataBase::drop() {
if (rc)
throw Unknown(name, mdb_strerror(rc));
- for (const std::pair& pair : tables) {
+ for (const std::pair& pair : tables) {
rc = pair.second->drop(txn);
if (rc)
throw Unknown(name, mdb_strerror(rc), pair.first);
@@ -125,20 +125,20 @@ void LMDBDataBase::DataBase::drop() {
mdb_txn_commit(txn);
}
-LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction() const {
+LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction() const {
return beginReadOnlyTransaction(emptyName);}
-LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction() const {
+LMDBAL::TransactionID LMDBAL::Base::beginTransaction() const {
return beginTransaction(emptyName);}
-void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id) const {
+void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id) const {
return abortTransaction(id, emptyName);}
-void LMDBDataBase::DataBase::commitTransaction(LMDBDataBase::TransactionID id) const {
+void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id) const {
return commitTransaction(id, emptyName);}
-LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction(const std::string& storageName) const {
+LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string& storageName) const {
if (!opened)
throw Closed("beginReadOnlyTransaction", name, storageName);
@@ -152,7 +152,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginReadOnlyTransaction(con
return txn;
}
-LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std::string& storageName) const {
+LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageName) const {
if (!opened)
throw Closed("beginTransaction", name, storageName);
@@ -166,7 +166,7 @@ LMDBDataBase::TransactionID LMDBDataBase::DataBase::beginTransaction(const std::
return txn;
}
-void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id, const std::string& storageName) const {
+void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string& storageName) const {
if (!opened)
throw Closed("abortTransaction", name, storageName);
@@ -178,7 +178,7 @@ void LMDBDataBase::DataBase::abortTransaction(LMDBDataBase::TransactionID id, co
transactions->erase(itr);
}
-void LMDBDataBase::DataBase::commitTransaction(LMDBDataBase::TransactionID id, const std::string& storageName) const {
+void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string& storageName) const {
if (!opened)
throw Closed("abortTransaction", name, storageName);
diff --git a/database.h b/src/base.h
similarity index 77%
rename from database.h
rename to src/base.h
index 27f318e..42cc26c 100644
--- a/database.h
+++ b/src/base.h
@@ -1,21 +1,21 @@
-// Squawk messenger.
+// Squawk messenger.
// Copyright (C) 2019 Yury Gubich
-//
+//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-#ifndef LMDBDATABASE_DATABASE_H
-#define LMDBDATABASE_DATABASE_H
+#ifndef LMDBAL_BASE_H
+#define LMDBAL_BASE_H
#include