Address compiler warnings #10
Some checks failed
BlockStorage/repertory_osx/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head There was a failure building this commit

This commit is contained in:
2023-10-30 13:31:52 -05:00
parent e7413fb741
commit 639d14452b
10 changed files with 1129 additions and 631 deletions

View File

@ -82,7 +82,6 @@
#include <optional>
#include <random>
#include <sstream>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
@ -90,6 +89,14 @@
#include <unordered_map>
#include <vector>
#include <sodium.h>
template <typename data_type>
[[nodiscard]] constexpr auto repertory_rand() -> data_type {
data_type ret{};
randombytes_buf(&ret, sizeof(ret));
return ret;
}
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/asio.hpp>
@ -116,7 +123,6 @@
#endif
#include <pugixml.hpp>
#include <sodium.h>
#define CPPHTTPLIB_TCP_NODELAY true
#define CPPHTTPLIB_OPENSSL_SUPPORT
@ -136,12 +142,12 @@ using json = nlohmann::json;
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
using native_handle = HANDLE;
#else
#define REPERTORY_INVALID_HANDLE -1
#define REPERTORY_INVALID_HANDLE (-1)
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
using native_handle = int;
#endif
#define NANOS_PER_SECOND 1000000000L
constexpr const auto NANOS_PER_SECOND = 1000000000L;
#ifdef _WIN32
#ifdef CreateDirectory
@ -339,6 +345,7 @@ using WCHAR = wchar_t;
#define STATUS_OBJECT_NAME_NOT_FOUND std::int32_t(0xC0000034L)
#define STATUS_OBJECT_PATH_INVALID std::int32_t(0xC0000039L)
#define STATUS_UNEXPECTED_IO_ERROR std::int32_t(0xC00000E9L)
#define CONVERT_STATUS_NOT_IMPLEMENTED(e) \
((std::int32_t(e) == STATUS_NOT_IMPLEMENTED) ? -ENOTSUP : e)

View File

@ -23,7 +23,13 @@
#define INCLUDE_EVENTS_EVENT_HPP_
namespace repertory {
enum class event_level { error, warn, normal, debug, verbose };
enum class event_level {
error,
warn,
normal,
debug,
verbose,
};
auto event_level_from_string(std::string level) -> event_level;
@ -37,10 +43,14 @@ protected:
: allow_async_(allow_async), ss_(ss.str()), j_(std::move(j)) {}
public:
event(const event &) = delete;
event(event &&) = delete;
auto operator=(const event &) -> event & = delete;
auto operator=(event &&) -> event & = delete;
virtual ~event() = default;
private:
const bool allow_async_;
bool allow_async_;
protected:
std::stringstream ss_;

View File

@ -22,8 +22,8 @@
#ifndef INCLUDE_TYPES_REMOTE_HPP_
#define INCLUDE_TYPES_REMOTE_HPP_
#define PACKET_SERVICE_FUSE std::uint32_t(1)
#define PACKET_SERVICE_WINFSP std::uint32_t(2)
#define PACKET_SERVICE_FUSE 1U
#define PACKET_SERVICE_WINFSP 2U
#ifdef _WIN32
#define PACKET_SERVICE_FLAGS PACKET_SERVICE_WINFSP
@ -44,48 +44,51 @@ using group_id = std::uint32_t;
using user_id = std::uint32_t;
enum class open_flags : std::uint32_t {
read_only = 0u,
write_only = 1u,
read_write = 2u,
create = 4u,
excl = 8u,
no_ctty = 16u,
truncate = 32u,
append = 64u,
non_blocking = 128u,
sync = 256u,
async = 512u,
directory = 1024u,
no_follow = 2048u,
clo_exec = 4096u,
direct = 8192u,
no_atime = 16384u,
path = 32768u,
temp_file = 65536u,
dsync = 131072u,
read_only = 0U,
write_only = 1U,
read_write = 2U,
create = 4U,
excl = 8U,
no_ctty = 16U,
truncate = 32U,
append = 64U,
non_blocking = 128U,
sync = 256U,
async = 512U,
directory = 1024U,
no_follow = 2048U,
clo_exec = 4096U,
direct = 8192U,
no_atime = 16384U,
path = 32768U,
temp_file = 65536U,
dsync = 131072U,
};
inline auto operator|(const open_flags &a, const open_flags &b) -> open_flags {
inline auto operator|(const open_flags &flag_1, const open_flags &flag_2)
-> open_flags {
using t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<t>(a) | static_cast<t>(b));
return static_cast<open_flags>(static_cast<t>(flag_1) |
static_cast<t>(flag_2));
}
#ifdef __GNUG__
__attribute__((unused))
#endif
inline auto
operator|=(open_flags &a, const open_flags &b) -> open_flags & {
a = a | b;
return a;
operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & {
flag_1 = flag_1 | flag_2;
return flag_1;
}
#ifdef __GNUG__
__attribute__((unused))
#endif
inline auto
operator&(const open_flags &a, const open_flags &b) -> open_flags {
operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags {
using t = std::underlying_type_t<open_flags>;
return static_cast<open_flags>(static_cast<t>(a) & static_cast<t>(b));
return static_cast<open_flags>(static_cast<t>(flag_1) &
static_cast<t>(flag_2));
}
#pragma pack(1)

View File

@ -38,11 +38,13 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
template <typename t>
[[nodiscard]] auto collection_excludes(t collection,
const typename t::value_type &v) -> bool;
const typename t::value_type &val)
-> bool;
template <typename t>
[[nodiscard]] auto collection_includes(t collection,
const typename t::value_type &v) -> bool;
const typename t::value_type &val)
-> bool;
[[nodiscard]] auto compare_version_strings(std::string version1,
std::string version2) -> int;
@ -53,7 +55,8 @@ template <typename t>
[[nodiscard]] auto create_uuid_string() -> std::string;
[[nodiscard]] auto create_volume_label(const provider_type &pt) -> std::string;
[[nodiscard]] auto create_volume_label(const provider_type &prov)
-> std::string;
template <typename t>
[[nodiscard]] auto divide_with_ceiling(const t &n, const t &d) -> t;
@ -66,7 +69,7 @@ template <typename t>
-> std::string;
template <typename t>
[[nodiscard]] auto from_hex_string(const std::string &str, t &v) -> bool;
[[nodiscard]] auto from_hex_string(const std::string &str, t &val) -> bool;
[[nodiscard]] auto generate_random_string(std::uint16_t length) -> std::string;
@ -77,7 +80,7 @@ template <typename t>
[[nodiscard]] auto get_file_time_now() -> std::uint64_t;
void get_local_time_now(struct tm &localTime);
void get_local_time_now(struct tm &local_time);
[[nodiscard]] auto get_next_available_port(std::uint16_t first_port,
std::uint16_t &available_port)
@ -85,11 +88,12 @@ void get_local_time_now(struct tm &localTime);
[[nodiscard]] auto get_time_now() -> std::uint64_t;
template <typename t>
[[nodiscard]] auto random_between(const t &begin, const t &end) -> t;
template <typename data_type>
[[nodiscard]] auto random_between(const data_type &begin, const data_type &end)
-> data_type;
template <typename t>
void remove_element_from(t &v, const typename t::value_type &value);
void remove_element_from(t &collection, const typename t::value_type &val);
[[nodiscard]] auto reset_curl(CURL *curl_handle) -> CURL *;
@ -97,28 +101,30 @@ void remove_element_from(t &v, const typename t::value_type &value);
-> bool;
void spin_wait_for_mutex(std::function<bool()> complete,
std::condition_variable &cv, std::mutex &mtx,
const std::string &txt = "");
std::condition_variable &cond, std::mutex &mtx,
const std::string &text = "");
void spin_wait_for_mutex(bool &complete, std::condition_variable &cv,
std::mutex &mtx, const std::string &txt = "");
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text = "");
template <typename t>
[[nodiscard]] auto to_hex_string(const t &v) -> std::string;
[[nodiscard]] auto to_hex_string(const t &val) -> std::string;
// template implementations
template <typename t>
[[nodiscard]] auto collection_excludes(t collection,
const typename t::value_type &v)
const typename t::value_type &val)
-> bool {
return std::find(collection.begin(), collection.end(), v) == collection.end();
return std::find(collection.begin(), collection.end(), val) ==
collection.end();
}
template <typename t>
[[nodiscard]] auto collection_includes(t collection,
const typename t::value_type &v)
const typename t::value_type &val)
-> bool {
return std::find(collection.begin(), collection.end(), v) != collection.end();
return std::find(collection.begin(), collection.end(), val) !=
collection.end();
}
template <typename t>
@ -127,12 +133,14 @@ template <typename t>
}
template <typename t>
[[nodiscard]] auto from_hex_string(const std::string &str, t &v) -> bool {
v.clear();
if (not(str.length() % 2u)) {
for (std::size_t i = 0u; i < str.length(); i += 2u) {
v.emplace_back(static_cast<typename t::value_type>(
strtol(str.substr(i, 2u).c_str(), nullptr, 16)));
[[nodiscard]] auto from_hex_string(const std::string &str, t &val) -> bool {
static constexpr const auto base16 = 16;
val.clear();
if (not(str.length() % 2U)) {
for (std::size_t i = 0U; i < str.length(); i += 2U) {
val.emplace_back(static_cast<typename t::value_type>(
strtol(str.substr(i, 2U).c_str(), nullptr, base16)));
}
return true;
}
@ -140,30 +148,32 @@ template <typename t>
return false;
}
template <typename t>
[[nodiscard]] auto random_between(const t &begin, const t &end) -> t {
srand(static_cast<unsigned int>(get_time_now()));
return begin + static_cast<t>(rand()) % ((end + 1) - begin);
template <typename data_type>
[[nodiscard]] auto random_between(const data_type &begin, const data_type &end)
-> data_type {
return begin + repertory_rand<data_type>() % ((end + 1) - begin);
}
template <typename t>
void remove_element_from(t &v, const typename t::value_type &value) {
v.erase(std::remove(v.begin(), v.end(), value), v.end());
void remove_element_from(t &collection, const typename t::value_type &value) {
collection.erase(std::remove(collection.begin(), collection.end(), value),
collection.end());
}
template <typename t>
[[nodiscard]] auto to_hex_string(const t &value) -> std::string {
std::string ret{};
std::array<char, 3> h{};
std::array<char, 3> tmp{};
for (const auto &num : value) {
#ifdef _WIN32
sprintf_s(h.data(), h.size() - 1U, "%x", static_cast<std::uint8_t>(num));
#else
sprintf(h.data(), "%x", static_cast<std::uint8_t>(num));
sprintf(tmp.data(), "%x", static_cast<std::uint8_t>(num));
#endif
ret += (strlen(h.data()) == 1) ? std::string("0") + h.data() : h.data();
ret +=
(strlen(tmp.data()) == 1) ? std::string("0") + tmp.data() : tmp.data();
}
return ret;