updated build system

This commit is contained in:
Scott E. Graves 2024-10-17 10:20:07 -05:00
parent 39d644e115
commit 63ca3089da
22 changed files with 304 additions and 198 deletions

View File

@ -1,15 +1,15 @@
set(BINUTILS_VERSION 2.41)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 85)
set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(CPP_HTTPLIB_VERSION 0.16.3)
set(CURL2_VERSION 8_9_1)
set(CURL_VERSION 8.9.1)
set(EXPAT2_VERSION 2_6_2)
set(CURL2_VERSION 8_9_1)
set(EXPAT_VERSION 2.6.2)
set(EXPAT2_VERSION 2_6_2)
set(GCC_VERSION 14.2.0)
set(GTEST_VERSION 1.15.2)
set(ICU_VERSION 75-1)
@ -21,7 +21,7 @@ set(OPENSSL_VERSION 3.3.1)
set(PKG_CONFIG_VERSION 0.29.2)
set(PUGIXML_VERSION 1.14)
set(SPDLOG_VERSION 1.14.1)
set(SQLITE2_VERSION 3.46.1)
set(SQLITE_VERSION 3460100)
set(SQLITE2_VERSION 3.46.1)
set(STDUUID_VERSION 1.2.3)
set(ZLIB_VERSION 1.3.1)

View File

@ -572,8 +572,8 @@ RUN if [ -f "/3rd_party/flac-${MY_FLAC_VERSION}.tar.gz" ]; then \
&& cd build \
&& cmake .. \
-DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_PROGRAMS=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PROGRAMS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_TESTING=OFF \

View File

@ -29,6 +29,11 @@
namespace {
struct repertory_exception_handler final
: repertory::utils::error::i_exception_handler {
void handle_error(std::string_view function_name,
std::string_view msg) const override {
repertory::utils::error::raise_error(function_name, msg);
}
void handle_exception(std::string_view function_name) const override {
repertory::utils::error::raise_error(function_name, "|exception|unknown");
}

View File

@ -18,6 +18,10 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
/mingw64/bin/zlib1.dll
)
if [ "${PROJECT_ENABLE_BACKWARD_CPP}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/msvcr90.dll)
fi
if [ "${PROJECT_ENABLE_BOOST}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libboost*.dll)
fi
@ -26,10 +30,18 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcli11*.dll)
fi
if [ "${PROJECT_ENABLE_CURL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcurl*.dll)
fi
if [ "${PROJECT_ENABLE_FLAC}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libFLAC*.dll)
fi
if [ "${PROJECT_ENABLE_FMT}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libfmt*.dll)
fi
if [ "${PROJECT_ENABLE_FONTCONFIG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(
/mingw64/bin/libexpat*.dll
@ -93,14 +105,26 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpugi*.dll)
fi
if [ "${PROJECT_ENABLE_ROCKSDB}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/librocksdb*.dll)
fi
if [ "${PROJECT_ENABLE_SDL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/SDL2*.dll)
fi
if [ "${PROJECT_ENABLE_SECP256K1}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsecp256k1*.dll)
fi
if [ "${PROJECT_ENABLE_SFML}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsfml*.dll)
fi
if [ "${PROJECT_ENABLE_SPDLOG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libspdlog*.dll)
fi
if [ "${PROJECT_ENABLE_SQLITE}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsqlite3-*.dll)
fi
@ -116,14 +140,32 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
)
fi
if [ "${PROJECT_ENABLE_TPL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiny-process*.dll)
fi
if [ "${PROJECT_ENABLE_VORBIS}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libvorbis*.dll)
fi
if [ "${PROJECT_ENABLE_WXWIDGETS}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libLerc.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsharpyuv-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libdeflate.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libglib-2*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libgraphite2.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libharfbuzz-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libjbig-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libpcre2-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiff-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwebp-*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwxbase*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libwxm*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/wxbase*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/wxm*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/libwxbase*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/libwxm*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/wxbase*.dll)
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/lib/gcc_x64_dll/wxm*.dll)
fi
@ -132,42 +174,13 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
PROJECT_MINGW64_COPY_DEPENDENCIES+=(
/mingw64/bin/libOpenCL*.dll
/mingw64/bin/libopencl*.dll
/mingw64/bin/libgallium_wgl.dll
/mingw64/bin/libva*.dll
/mingw64/bin/opengl*.dll
/mingw64/bin/vulkan*.dll
)
fi
if [ "${PROJECT_IS_MINGW_UNIX}" == "1" ]; then
if [ "${PROJECT_ENABLE_BACKWARD_CPP}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/msvcr90.dll)
fi
if [ "${PROJECT_ENABLE_FMT}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libfmt*.dll)
fi
if [ "${PROJECT_ENABLE_CURL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libcurl*.dll)
fi
if [ "${PROJECT_ENABLE_ROCKSDB}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/librocksdb*.dll)
fi
if [ "${PROJECT_ENABLE_SECP256K1}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libsecp256k1*.dll)
fi
if [ "${PROJECT_ENABLE_SPDLOG}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libspdlog*.dll)
fi
if [ "${PROJECT_ENABLE_TPL}" == "ON" ]; then
PROJECT_MINGW64_COPY_DEPENDENCIES+=(/mingw64/bin/libtiny-process*.dll)
fi
fi
rsync -av --progress ${PROJECT_EXTERNAL_BUILD_ROOT}/bin/*.dll "${PROJECT_DIST_DIR}/"
rsync -av --progress ${PROJECT_EXTERNAL_BUILD_ROOT}/lib/*.dll "${PROJECT_DIST_DIR}/"
if [ "${PROJECT_ENABLE_WXWIDGETS}" == "ON" ]; then
@ -175,7 +188,7 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th
fi
fi
if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; then
if [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; then
if [ "${PROJECT_BUILD_ARCH}" == "x86_64" ]; then
WINFSP_DLL_PART=x64
fi
@ -185,7 +198,7 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_WINFSP}" == "ON" ]; t
fi
fi
if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_ENABLE_VLC}" == "ON" ]; then
if [ "${PROJECT_ENABLE_VLC}" == "ON" ]; then
rsync -av --progress ${PROJECT_3RD_PARTY_DIR}/vlc/ "${PROJECT_DIST_DIR}/vlc/"
fi

View File

@ -121,6 +121,7 @@ if [ "${PROJECT_ENABLE_VORBIS}" == "ON" ]; then
fi
if [ "${PROJECT_ENABLE_FLAC}" == "ON" ]; then
PROJECT_ENABLE_LIBICONV=ON
PROJECT_ENABLE_OGG=ON
PROJECT_ENABLE_VORBIS=ON
fi

View File

@ -183,8 +183,6 @@ template <typename ctx_t> struct db_result final {
}
}
~db_result() { context_->clear(); }
private:
std::shared_ptr<ctx_t> context_;
mutable std::int32_t res_;

View File

@ -43,12 +43,9 @@ public:
: db_context_t(db3_, table_name_) {}
using w_t = db_where_t<context, db_delete_op_t>;
using wd_t = where_data_t<w_t>;
std::optional<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -67,8 +64,8 @@ public:
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto group(context::w_t::group_func_t func)
-> context::w_t::wn_t;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};

View File

@ -34,8 +34,6 @@ public:
bool or_replace{false};
std::map<std::string, db_types_t> values;
void clear() { values.clear(); }
};
using row = db_row<context>;

View File

@ -44,14 +44,15 @@ public:
[[nodiscard]] auto offset(std::int32_t value) -> db_select_op_t;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_select_op_t;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_select_op_t;
};
context(sqlite3 *db3_, std::string table_name_)
: db_context_t(db3_, table_name_) {}
using w_t = db_where_t<context, db_select_op_t>;
using wd_t = where_data_t<w_t>;
std::vector<std::string> columns;
std::map<std::string, std::string> count_columns;
@ -60,11 +61,8 @@ public:
std::optional<std::int32_t> limit;
std::optional<std::int32_t> offset;
std::optional<std::pair<std::string, bool>> order_by;
std::optional<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -81,8 +79,8 @@ private:
public:
[[nodiscard]] auto column(std::string column_name) -> db_select &;
[[nodiscard]] auto count(std::string column_name,
std::string as_column_name) -> db_select &;
[[nodiscard]] auto count(std::string column_name, std::string as_column_name)
-> db_select &;
[[nodiscard]] auto dump() const -> std::string;
@ -90,15 +88,15 @@ public:
[[nodiscard]] auto group_by(std::string column_name) -> db_select &;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto group(context::w_t::group_func_t func)
-> context::w_t::wn_t;
[[nodiscard]] auto limit(std::int32_t value) -> db_select &;
[[nodiscard]] auto offset(std::int32_t value) -> db_select &;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_select &;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_select &;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};

View File

@ -43,20 +43,18 @@ public:
[[nodiscard]] auto limit(std::int32_t value) -> db_update_op_t;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_update_op_t;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_update_op_t;
};
using w_t = db_where_t<context, db_update_op_t>;
using wd_t = where_data_t<w_t>;
std::map<std::string, db_types_t> column_values;
std::optional<std::int32_t> limit;
std::optional<std::pair<std::string, bool>> order_by;
std::optional<w_t> where;
std::map<std::size_t, std::vector<w_t::action_t>> where_actions;
std::vector<db_types_t> where_values;
void clear();
std::unique_ptr<wd_t> where_data;
};
using row = db_row<context>;
@ -71,20 +69,20 @@ private:
std::shared_ptr<context> context_;
public:
[[nodiscard]] auto column_value(std::string column_name,
db_types_t value) -> db_update &;
[[nodiscard]] auto column_value(std::string column_name, db_types_t value)
-> db_update &;
[[nodiscard]] auto dump() const -> std::string;
[[nodiscard]] auto go() const -> db_result<context>;
[[nodiscard]] auto
group(context::w_t::group_func_t func) -> context::w_t::wn_t;
[[nodiscard]] auto group(context::w_t::group_func_t func)
-> context::w_t::wn_t;
[[nodiscard]] auto limit(std::int32_t value) -> db_update &;
[[nodiscard]] auto order_by(std::string column_name,
bool ascending) -> db_update &;
[[nodiscard]] auto order_by(std::string column_name, bool ascending)
-> db_update &;
[[nodiscard]] auto where(std::string column_name) const -> context::w_t::cn_t;
};

View File

@ -26,6 +26,12 @@
#include "utils/db/sqlite/db_common.hpp"
namespace repertory::utils::db::sqlite {
template <typename w_t> struct where_data_t final {
w_t base;
std::map<std::size_t, std::vector<typename w_t::action_t>> actions;
std::vector<db_types_t> values;
};
template <typename cn_t, typename ctx_t, typename op_t, typename w_t,
typename wn_t>
struct db_next_t final {
@ -42,7 +48,7 @@ struct db_next_t final {
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return ctx->where->dump(idx);
return ctx->where_data->base.dump(idx);
}
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
@ -72,14 +78,14 @@ struct db_where_next_t final {
"AND",
};
ctx->where_actions[action_idx].emplace_back(next);
ctx->where_data->actions[action_idx].emplace_back(next);
return next;
}
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return ctx->where->dump(idx);
return ctx->where_data->base.dump(idx);
}
[[nodiscard]] auto go() const -> auto { return op_t{ctx}.go(); }
@ -97,7 +103,7 @@ struct db_where_next_t final {
"OR",
};
ctx->where_actions[action_idx].emplace_back(next);
ctx->where_data->actions[action_idx].emplace_back(next);
return next;
}
};
@ -111,12 +117,12 @@ struct db_comp_next_t final {
using wn_t = db_where_next_t<db_comp_next_t, ctx_t, op_t, w_t>;
[[nodiscard]] auto create(std::string operation, db_types_t value) {
ctx->where_actions[action_idx].emplace_back(db_comp_data_t{
ctx->where_data->actions[action_idx].emplace_back(db_comp_data_t{
column_name,
operation,
});
ctx->where_values.push_back(value);
ctx->where_data->values.push_back(value);
return wn_t{
action_idx,
@ -151,8 +157,8 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
using action_t = std::variant<db_comp_data_t, n_t, db_where_t>;
[[nodiscard]] static auto dump(std::int32_t &idx,
auto &&actions) -> std::string {
[[nodiscard]] static auto dump(std::int32_t &idx, auto &&actions)
-> std::string {
std::stringstream stream;
for (auto &&action : actions) {
@ -177,24 +183,24 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
[[nodiscard]] auto dump() const -> std::string { return op_t{ctx}.dump(); }
[[nodiscard]] auto dump(std::int32_t &idx) const -> std::string {
return dump(idx, ctx->where_actions[action_idx]);
return dump(idx, ctx->where_data->actions[action_idx]);
}
[[nodiscard]] auto get_actions() -> auto & {
return ctx->where_actions[action_idx];
return ctx->where_data->actions[action_idx];
}
[[nodiscard]] auto get_actions() const -> const auto & {
return ctx->where_actions[action_idx];
return ctx->where_data->actions[action_idx];
}
[[nodiscard]] auto group(group_func_t func) -> wn_t {
ctx->where_actions[action_idx];
ctx->where_data->actions[action_idx];
db_where_t where{ctx->where_actions.size(), ctx};
db_where_t where{ctx->where_data->actions.size(), ctx};
func(where);
ctx->where_actions[action_idx].emplace_back(where);
ctx->where_data->actions[action_idx].emplace_back(where);
return wn_t{
action_idx,
@ -203,7 +209,7 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
}
[[nodiscard]] auto where(std::string column_name) -> cn_t {
ctx->where_actions[action_idx];
ctx->where_data->actions[action_idx];
return cn_t{
action_idx,

View File

@ -33,6 +33,9 @@ struct i_exception_handler {
auto operator=(const i_exception_handler &) noexcept = delete;
auto operator=(i_exception_handler &&) noexcept = delete;
virtual void handle_error(std::string_view function_name,
std::string_view msg) const = 0;
virtual void handle_exception(std::string_view function_name) const = 0;
virtual void handle_exception(std::string_view function_name,
@ -43,6 +46,11 @@ protected:
};
struct iostream_exception_handler final : i_exception_handler {
void handle_error(std::string_view function_name,
std::string_view msg) const override {
std::cerr << function_name << '|' << msg;
}
void handle_exception(std::string_view function_name) const override {
std::cerr << function_name << "|exception|unknown" << std::endl;
}
@ -58,12 +66,18 @@ inline const iostream_exception_handler default_exception_handler{};
extern std::atomic<const i_exception_handler *> exception_handler;
#if defined(PROJECT_ENABLE_TESTING)
[[nodiscard]] inline auto
get_exception_handler() -> const i_exception_handler * {
[[nodiscard]] inline auto get_exception_handler()
-> const i_exception_handler * {
return exception_handler;
}
#endif // defined(PROJECT_ENABLE_TESTING)
[[nodiscard]] auto create_error_message(std::string_view function_name,
std::vector<std::string_view> items)
-> std::string;
void handle_error(std::string_view function_name, std::string_view msg);
void handle_exception(std::string_view function_name);
void handle_exception(std::string_view function_name, const std::exception &ex);

View File

@ -26,6 +26,10 @@
#include "utils/config.hpp"
namespace repertory::utils {
void create_console();
void free_console();
[[nodiscard]] auto get_local_app_data_directory() -> const std::string &;
[[nodiscard]] auto get_last_error_code() -> DWORD;

View File

@ -24,11 +24,6 @@
#if defined(PROJECT_ENABLE_SQLITE)
namespace repertory::utils::db::sqlite {
void db_delete::context::clear() {
where.reset();
where_values.clear();
}
auto db_delete::context::db_delete_op_t::dump() const -> std::string {
return db_delete{ctx}.dump();
}
@ -41,9 +36,9 @@ auto db_delete::dump() const -> std::string {
std::stringstream query;
query << "DELETE FROM \"" << context_->table_name << "\"";
if (context_->where.has_value()) {
if (context_->where_data) {
std::int32_t idx{};
query << " WHERE " << context_->where->dump(idx);
query << " WHERE " << context_->where_data->base.dump(idx);
}
query << ';';
@ -65,8 +60,13 @@ auto db_delete::go() const -> db_result<context> {
return {context_, res};
}
if (not context_->where_data) {
return {context_, res};
}
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
idx < static_cast<std::int32_t>(context_->where_data->values.size());
idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
@ -77,7 +77,7 @@ auto db_delete::go() const -> db_result<context> {
data.c_str(), -1, nullptr);
},
},
context_->where_values.at(static_cast<std::size_t>(idx)));
context_->where_data->values.at(static_cast<std::size_t>(idx)));
if (res != SQLITE_OK) {
return {context_, res};
}
@ -87,19 +87,23 @@ auto db_delete::go() const -> db_result<context> {
}
auto db_delete::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->group(std::move(func));
return context_->where_data->base.group(std::move(func));
}
auto db_delete::where(std::string column_name) const -> context::w_t::cn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->where(column_name);
return context_->where_data->base.where(column_name);
}
} // namespace repertory::utils::db::sqlite

View File

@ -24,16 +24,6 @@
#if defined(PROJECT_ENABLE_SQLITE)
namespace repertory::utils::db::sqlite {
void db_select::context::clear() {
columns.clear();
count_columns.clear();
limit.reset();
offset.reset();
order_by.reset();
where.reset();
where_values.clear();
}
auto db_select::context::db_select_op_t::dump() const -> std::string {
return db_select{ctx}.dump();
}
@ -72,8 +62,8 @@ auto db_select::column(std::string column_name) -> db_select & {
return *this;
}
auto db_select::count(std::string column_name,
std::string as_column_name) -> db_select & {
auto db_select::count(std::string column_name, std::string as_column_name)
-> db_select & {
context_->count_columns[column_name] = as_column_name;
return *this;
}
@ -108,9 +98,9 @@ auto db_select::dump() const -> std::string {
}
query << " FROM \"" << context_->table_name << "\"";
if (context_->where.has_value()) {
if (context_->where_data) {
std::int32_t idx{};
query << " WHERE " << context_->where->dump(idx);
query << " WHERE " << context_->where_data->base.dump(idx);
}
if (not context_->group_by.empty()) {
@ -156,8 +146,13 @@ auto db_select::go() const -> db_result<context> {
return {context_, res};
}
if (not context_->where_data) {
return {context_, res};
}
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
idx < static_cast<std::int32_t>(context_->where_data->values.size());
idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
@ -168,7 +163,7 @@ auto db_select::go() const -> db_result<context> {
data.c_str(), -1, nullptr);
},
},
context_->where_values.at(static_cast<std::size_t>(idx)));
context_->where_data->values.at(static_cast<std::size_t>(idx)));
if (res != SQLITE_OK) {
return {context_, res};
}
@ -178,11 +173,13 @@ auto db_select::go() const -> db_result<context> {
}
auto db_select::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->group(std::move(func));
return context_->where_data->base.group(std::move(func));
}
auto db_select::group_by(std::string column_name) -> db_select & {
@ -200,18 +197,20 @@ auto db_select::offset(std::int32_t value) -> db_select & {
return *this;
}
auto db_select::order_by(std::string column_name,
bool ascending) -> db_select & {
auto db_select::order_by(std::string column_name, bool ascending)
-> db_select & {
context_->order_by = {column_name, ascending};
return *this;
}
auto db_select::where(std::string column_name) const -> context::w_t::cn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->where(column_name);
return context_->where_data->base.where(column_name);
}
} // namespace repertory::utils::db::sqlite

View File

@ -24,14 +24,6 @@
#if defined(PROJECT_ENABLE_SQLITE)
namespace repertory::utils::db::sqlite {
void db_update::context::clear() {
column_values.clear();
limit.reset();
order_by.reset();
where.reset();
where_values.clear();
}
auto db_update::context::db_update_op_t::dump() const -> std::string {
return db_update{ctx}.dump();
}
@ -53,8 +45,8 @@ auto db_update::context::db_update_op_t::order_by(std::string column_name,
return *this;
}
auto db_update::column_value(std::string column_name,
db_types_t value) -> db_update & {
auto db_update::column_value(std::string column_name, db_types_t value)
-> db_update & {
context_->column_values[column_name] = value;
return *this;
}
@ -73,9 +65,9 @@ auto db_update::dump() const -> std::string {
query << '"' << column->first << "\"=?" + std::to_string(idx + 1);
}
if (context_->where.has_value()) {
if (context_->where_data) {
auto idx{static_cast<std::int32_t>(context_->column_values.size())};
query << " WHERE " << context_->where->dump(idx);
query << " WHERE " << context_->where_data->base.dump(idx);
}
if (context_->order_by.has_value()) {
@ -124,9 +116,15 @@ auto db_update::go() const -> db_result<context> {
}
}
if (not context_->where_data) {
return {context_, res};
}
for (std::int32_t idx = 0;
idx < static_cast<std::int32_t>(context_->where_values.size()); idx++) {
res = std::visit(overloaded{
idx < static_cast<std::int32_t>(context_->where_data->values.size());
idx++) {
res = std::visit(
overloaded{
[this, &idx](std::int64_t data) -> std::int32_t {
return sqlite3_bind_int64(
context_->stmt.get(),
@ -137,8 +135,7 @@ auto db_update::go() const -> db_result<context> {
data);
},
[this, &idx](const std::string &data) -> std::int32_t {
return sqlite3_bind_text(
context_->stmt.get(),
return sqlite3_bind_text(context_->stmt.get(),
idx +
static_cast<std::int32_t>(
context_->column_values.size()) +
@ -146,7 +143,7 @@ auto db_update::go() const -> db_result<context> {
data.c_str(), -1, nullptr);
},
},
context_->where_values.at(static_cast<std::size_t>(idx)));
context_->where_data->values.at(static_cast<std::size_t>(idx)));
if (res != SQLITE_OK) {
return {context_, res};
}
@ -156,11 +153,13 @@ auto db_update::go() const -> db_result<context> {
}
auto db_update::group(context::w_t::group_func_t func) -> context::w_t::wn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->group(std::move(func));
return context_->where_data->base.group(std::move(func));
}
auto db_update::limit(std::int32_t value) -> db_update & {
@ -168,18 +167,20 @@ auto db_update::limit(std::int32_t value) -> db_update & {
return *this;
}
auto db_update::order_by(std::string column_name,
bool ascending) -> db_update & {
auto db_update::order_by(std::string column_name, bool ascending)
-> db_update & {
context_->order_by = {column_name, ascending};
return *this;
}
auto db_update::where(std::string column_name) const -> context::w_t::cn_t {
if (not context_->where.has_value()) {
context_->where = context::w_t{0U, context_};
if (not context_->where_data) {
context_->where_data = std::make_unique<context::wd_t>(context::wd_t{
context::w_t{0U, context_},
});
}
return context_->where->where(column_name);
return context_->where_data->base.where(column_name);
}
} // namespace repertory::utils::db::sqlite

View File

@ -25,6 +25,27 @@ namespace repertory::utils::error {
std::atomic<const i_exception_handler *> exception_handler{
&default_exception_handler};
auto create_error_message(std::string_view function_name,
std::vector<std::string_view> items) -> std::string {
std::stringstream stream{};
stream << function_name;
for (auto &&item : items) {
stream << '|' << item;
}
return stream.str();
}
void handle_error(std::string_view function_name, std::string_view msg) {
const i_exception_handler *handler{exception_handler};
if (handler != nullptr) {
handler->handle_error(function_name, msg);
return;
}
default_exception_handler.handle_error(function_name, msg);
}
void handle_exception(std::string_view function_name) {
const i_exception_handler *handler{exception_handler};
if (handler != nullptr) {

View File

@ -52,8 +52,8 @@ namespace {
auto abs_path = repertory::utils::path::absolute(path);
#if defined(_WIN32)
return (::PathFileExistsA(abs_path.c_str()) &&
not ::PathIsDirectoryA(abs_path.c_str()));
return ((::PathFileExistsA(abs_path.c_str()) != 0) &&
(::PathIsDirectoryA(abs_path.c_str()) == 0));
#else // !defined(_WIN32)
struct stat64 st{};
return (stat64(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode));
@ -119,11 +119,15 @@ void file::open() {
}
#if defined(_WIN32)
file_ = file_t(_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO),
file_deleter());
file_ = file_t{
_fsopen(path_.c_str(), read_only_ ? "rb" : "rb+", _SH_DENYNO),
file_deleter(),
};
#else // !defined(_WIN32)
file_ =
file_t(fopen(path_.c_str(), read_only_ ? "rb" : "rb+"), file_deleter());
file_ = file_t{
fopen(path_.c_str(), read_only_ ? "rb" : "rb+"),
file_deleter(),
};
#endif // defined(_WIN32)
}
@ -150,8 +154,8 @@ auto file::open_file(std::string_view path, bool read_only) -> fs_file_t {
return new_file;
}
auto file::open_or_create_file(std::string_view path,
bool read_only) -> fs_file_t {
auto file::open_or_create_file(std::string_view path, bool read_only)
-> fs_file_t {
auto abs_path = utils::path::absolute(path);
if (not is_file(abs_path)) {
#if defined(_WIN32)
@ -196,7 +200,7 @@ auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
#if defined(_WIN32)
return ::CopyFileA(path_.c_str(), to_path.c_str(),
overwrite ? TRUE : FALSE);
overwrite ? TRUE : FALSE) != 0;
#else // !defined(_WIN32)
return std::filesystem::copy_file(
path_, to_path,
@ -264,8 +268,8 @@ auto file::move_to(std::string_view path) -> bool {
auto success{false};
#if defined(_WIN32)
success = !!::MoveFileExA(path_.c_str(), abs_path.c_str(),
MOVEFILE_REPLACE_EXISTING);
success = ::MoveFileExA(path_.c_str(), abs_path.c_str(),
MOVEFILE_REPLACE_EXISTING) != 0;
#else // !// defined(_WIN32)
std::error_code ec{};
std::filesystem::rename(path_, abs_path, ec);
@ -415,7 +419,7 @@ auto file::remove() -> bool {
return utils::retry_action([this]() -> bool {
#if defined(_WIN32)
return ::DeleteFileA(path_.c_str());
return ::DeleteFileA(path_.c_str()) != 0;
#else // !defined(_WIN32)
std::error_code ec{};
return std::filesystem::remove(path_, ec);

View File

@ -26,6 +26,39 @@
#include "utils/string.hpp"
namespace repertory::utils {
void create_console() {
if (AllocConsole() == 0) {
return;
}
FILE *dummy{nullptr};
freopen_s(&dummy, "CONOUT$", "w", stdout);
freopen_s(&dummy, "CONOUT$", "w", stderr);
freopen_s(&dummy, "CONIN$", "r", stdin);
std::cout.clear();
std::clog.clear();
std::cerr.clear();
std::cin.clear();
auto *out_w = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
auto *in_w = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
SetStdHandle(STD_OUTPUT_HANDLE, out_w);
SetStdHandle(STD_ERROR_HANDLE, out_w);
SetStdHandle(STD_INPUT_HANDLE, in_w);
std::wcout.clear();
std::wclog.clear();
std::wcerr.clear();
std::wcin.clear();
}
void free_console() {
FreeConsole();
}
auto get_last_error_code() -> DWORD { return ::GetLastError(); }
auto get_local_app_data_directory() -> const std::string & {

View File

@ -29,19 +29,16 @@ static std::vector<std::unique_ptr<repertory::utils::file::i_fs_item>>
static void delete_generated_files() {
repertory::recur_mutex_lock lock{file_mtx};
std::optional<std::string> parent_path;
std::map<std::string, bool> parent_paths;
for (auto &&path : generated_files) {
if (parent_path->empty()) {
parent_path = repertory::utils::path::get_parent_path(path->get_path());
}
[[maybe_unused]] auto removed = path->remove();
parent_paths[repertory::utils::path::get_parent_path(path->get_path())] =
true;
}
generated_files.clear();
if (parent_path.has_value()) {
for (auto &&entry : parent_paths) {
EXPECT_TRUE(
repertory::utils::file::directory(*parent_path).remove_recursively());
repertory::utils::file::directory(entry.first).remove_recursively());
}
}
@ -49,7 +46,9 @@ struct file_deleter final {
~file_deleter() { delete_generated_files(); }
};
static auto deleter{std::make_unique<file_deleter>()};
static auto deleter{
std::make_unique<file_deleter>(),
};
} // namespace
namespace repertory::test {

View File

@ -37,7 +37,11 @@ TEST(utils_error, check_default_exception_handler) {
}
TEST(utils_error, can_override_exception_handler) {
struct my_exc_handler : public utils::error::i_exception_handler {
struct my_exc_handler final : public utils::error::i_exception_handler {
MOCK_METHOD(void, handle_error,
(std::string_view function_name, std::string_view msg),
(const, override));
MOCK_METHOD(void, handle_exception, (std::string_view function_name),
(const, override));
@ -49,6 +53,9 @@ TEST(utils_error, can_override_exception_handler) {
my_exc_handler handler{};
utils::error::set_exception_handler(&handler);
EXPECT_CALL(handler, handle_error("test_func", "error")).WillOnce(Return());
utils::error::handle_error("test_func", "error");
EXPECT_CALL(handler, handle_exception("test_func")).WillOnce(Return());
utils::error::handle_exception("test_func");

View File

@ -26,7 +26,7 @@ static constexpr const auto file_type_count{1U};
}
namespace repertory {
TEST(utils_file, can_create_file) {
TEST(utils_file, can_create_and_remove_file) {
for (auto idx = 0U; idx < file_type_count; ++idx) {
auto path = test::generate_test_file_name("utils_file");
EXPECT_FALSE(utils::file::file(path).exists() ||
@ -37,6 +37,12 @@ TEST(utils_file, can_create_file) {
EXPECT_TRUE(*file);
EXPECT_TRUE(utils::file::file(path).exists());
EXPECT_TRUE(file->exists());
EXPECT_TRUE(file->remove());
EXPECT_FALSE(utils::file::file(path).exists());
EXPECT_FALSE(file->exists());
}
}