Auto reformatted the base, ref #470

This commit is contained in:
emeric
2024-05-24 23:31:52 +02:00
parent 83b868673c
commit 39941d90a3
460 changed files with 8583 additions and 8514 deletions
@@ -19,7 +19,7 @@
#pragma once
#include <boost/crc.hpp> // for boost::crc_32_type
#include <boost/crc.hpp> // for boost::crc_32_type
namespace lms::core
{
@@ -40,4 +40,4 @@ namespace lms::core
using Crc32Type = boost::crc_32_type;
Crc32Type _result;
};
}
} // namespace lms::core
+8 -5
View File
@@ -27,7 +27,7 @@
namespace lms::core
{
template <typename T, typename underlying_type = std::uint32_t>
template<typename T, typename underlying_type = std::uint32_t>
class EnumSet
{
static_assert(std::is_enum<T>::value);
@@ -45,13 +45,13 @@ namespace lms::core
insert(value);
}
template <typename It>
template<typename It>
constexpr EnumSet(It begin, It end)
{
assign(begin, end);
}
template <typename It>
template<typename It>
constexpr void assign(It begin, It end)
{
clear();
@@ -158,7 +158,10 @@ namespace lms::core
private:
static_assert(std::numeric_limits<IndexType>::max() >= sizeof(underlying_type) * 8);
enum : IndexType { npos = sizeof(underlying_type) * 8 };
enum : IndexType
{
npos = sizeof(underlying_type) * 8
};
constexpr IndexType getFirstBitSetIndex(IndexType start = {}) const
{
@@ -190,4 +193,4 @@ namespace lms::core
underlying_type _bitfield{};
};
}
} // namespace lms::core
+3 -2
View File
@@ -29,6 +29,7 @@ namespace lms::core
class LmsException : public std::runtime_error
{
public:
LmsException(std::string_view error = "") : std::runtime_error{ std::string{ error } } {}
LmsException(std::string_view error = "")
: std::runtime_error{ std::string{ error } } {}
};
}
} // namespace lms::core
+4 -4
View File
@@ -48,9 +48,9 @@ namespace lms::core
};
using ReadCallback = std::function<void(ReadResult, std::size_t)>;
virtual void asyncRead(std::byte* data, std::size_t bufferSize, ReadCallback callback) = 0;
virtual void asyncRead(std::byte* data, std::size_t bufferSize, ReadCallback callback) = 0;
virtual std::size_t readSome(std::byte* data, std::size_t bufferSize) = 0;
virtual bool finished() const = 0;
virtual std::size_t readSome(std::byte* data, std::size_t bufferSize) = 0;
virtual bool finished() const = 0;
};
}
} // namespace lms::core
@@ -20,6 +20,7 @@
#include <filesystem>
#include <memory>
#include <boost/asio/io_service.hpp>
#include "IChildProcess.hpp"
@@ -35,4 +36,4 @@ namespace lms::core
};
std::unique_ptr<IChildProcessManager> createChildProcessManager(boost::asio::io_service& ioService);
}
} // namespace lms::core
+7 -7
View File
@@ -31,13 +31,13 @@ namespace lms::core
virtual ~IConfig() = default;
// Default values are returned in case of setting not found
virtual std::string_view getString(std::string_view setting, std::string_view def = "") = 0;
virtual void visitStrings(std::string_view setting, std::function<void(std::string_view)> _func, std::initializer_list<std::string_view> def = {}) = 0;
virtual std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def = std::filesystem::path()) = 0;
virtual unsigned long getULong(std::string_view setting, unsigned long def = 0) = 0;
virtual long getLong(std::string_view setting, long def = 0) = 0;
virtual bool getBool(std::string_view setting, bool def = false) = 0;
virtual std::string_view getString(std::string_view setting, std::string_view def = "") = 0;
virtual void visitStrings(std::string_view setting, std::function<void(std::string_view)> _func, std::initializer_list<std::string_view> def = {}) = 0;
virtual std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def = std::filesystem::path()) = 0;
virtual unsigned long getULong(std::string_view setting, unsigned long def = 0) = 0;
virtual long getLong(std::string_view setting, long def = 0) = 0;
virtual bool getBool(std::string_view setting, bool def = false) = 0;
};
std::unique_ptr<IConfig> createConfig(const std::filesystem::path& p);
}
} // namespace lms::core
+9 -9
View File
@@ -19,11 +19,11 @@
#pragma once
#include <string>
#include <sstream>
#include <string>
#include "core/Service.hpp"
#include "core/String.hpp"
#include "Service.hpp"
namespace lms::core::logging
{
@@ -93,11 +93,11 @@ namespace lms::core::logging
virtual bool isSeverityActive(Severity severity) const = 0;
virtual void processLog(const Log& log) = 0;
};
}
} // namespace lms::core::logging
#define LMS_LOG(module, severity, message) \
do \
{ \
if (auto* logger_ {::lms::core::Service<::lms::core::logging::ILogger>::get()}; logger_ && logger_->isSeverityActive(::lms::core::logging::Severity::severity)) \
::lms::core::logging::Log{ *logger_, ::lms::core::logging::Module::module, ::lms::core::logging::Severity::severity }.getOstream() << message; \
} while(0)
#define LMS_LOG(module, severity, message) \
do \
{ \
if (auto* logger_{ ::lms::core::Service<::lms::core::logging::ILogger>::get() }; logger_ && logger_->isSeverityActive(::lms::core::logging::Severity::severity)) \
::lms::core::logging::Log{ *logger_, ::lms::core::logging::Module::module, ::lms::core::logging::Severity::severity }.getOstream() << message; \
} while (0)
@@ -21,6 +21,7 @@
#include <optional>
#include <thread>
#include <boost/asio/io_service.hpp>
namespace lms::core
@@ -39,7 +40,7 @@ namespace lms::core
IOContextRunner& operator=(const IOContextRunner&) = delete;
boost::asio::io_service& _ioService;
std::optional<boost::asio::io_service::work> _work;
std::vector<std::thread> _threads;
std::optional<boost::asio::io_service::work> _work;
std::vector<std::thread> _threads;
};
}
} // namespace lms::core
@@ -25,13 +25,13 @@
// TODO, move elsewhere
namespace lms
{
// Helper class to serve a resource (must be saved as continuation data if not complete)
class IResourceHandler
{
public:
virtual ~IResourceHandler() = default;
// Helper class to serve a resource (must be saved as continuation data if not complete)
class IResourceHandler
{
public:
virtual ~IResourceHandler() = default;
[[nodiscard]] virtual Wt::Http::ResponseContinuation* processRequest(const Wt::Http::Request& request, Wt::Http::Response& response) = 0;
virtual void abort() = 0;
};
}
[[nodiscard]] virtual Wt::Http::ResponseContinuation* processRequest(const Wt::Http::Request& request, Wt::Http::Response& response) = 0;
virtual void abort() = 0;
};
} // namespace lms
+11 -11
View File
@@ -34,20 +34,20 @@
#define LMS_CONCAT_IMPL(x, y) x##y
#define LMS_CONCAT(x, y) LMS_CONCAT_IMPL(x, y)
#if LMS_SUPPORT_TRACING
#define LMS_SCOPED_TRACE(CATEGORY, LEVEL, NAME, ARGTYPE, ARGVALUE) \
std::optional<::lms::core::tracing::ScopedTrace> LMS_CONCAT(ScopedTrace_, __LINE__); \
if (::lms::core::tracing::ITraceLogger* traceLogger{ ::lms::core::Service<::lms::core::tracing::ITraceLogger>::get() }; traceLogger && traceLogger->isLevelActive(LEVEL)) \
LMS_CONCAT(ScopedTrace_, __LINE__).emplace(CATEGORY, LEVEL, NAME, ARGTYPE, ARGVALUE, traceLogger);
#if LMS_SUPPORT_TRACING
#define LMS_SCOPED_TRACE(CATEGORY, LEVEL, NAME, ARGTYPE, ARGVALUE) \
std::optional<::lms::core::tracing::ScopedTrace> LMS_CONCAT(ScopedTrace_, __LINE__); \
if (::lms::core::tracing::ITraceLogger * traceLogger{ ::lms::core::Service<::lms::core::tracing::ITraceLogger>::get() }; traceLogger && traceLogger->isLevelActive(LEVEL)) \
LMS_CONCAT(ScopedTrace_, __LINE__).emplace(CATEGORY, LEVEL, NAME, ARGTYPE, ARGVALUE, traceLogger);
#else
#define LMS_SCOPED_TRACE(CATEGORY, LEVEL, NAME) (void)0
#define LMS_SCOPED_TRACE(CATEGORY, LEVEL, NAME) (void)0
#endif
#define LMS_SCOPED_TRACE_OVERVIEW_WITH_ARG(CATEGORY, NAME, ARGTYPE, ARGVALUE) LMS_SCOPED_TRACE(CATEGORY, ::lms::core::tracing::Level::Overview, NAME, ARGTYPE, ARGVALUE)
#define LMS_SCOPED_TRACE_DETAILED_WITH_ARG(CATEGORY, NAME, ARGTYPE, ARGVALUE) LMS_SCOPED_TRACE(CATEGORY, ::lms::core::tracing::Level::Detailed, NAME, ARGTYPE, ARGVALUE)
#define LMS_SCOPED_TRACE_OVERVIEW_WITH_ARG(CATEGORY, NAME, ARGTYPE, ARGVALUE) LMS_SCOPED_TRACE(CATEGORY, ::lms::core::tracing::Level::Overview, NAME, ARGTYPE, ARGVALUE)
#define LMS_SCOPED_TRACE_DETAILED_WITH_ARG(CATEGORY, NAME, ARGTYPE, ARGVALUE) LMS_SCOPED_TRACE(CATEGORY, ::lms::core::tracing::Level::Detailed, NAME, ARGTYPE, ARGVALUE)
#define LMS_SCOPED_TRACE_OVERVIEW(CATEGORY, NAME) LMS_SCOPED_TRACE_OVERVIEW_WITH_ARG(CATEGORY, NAME, "", "")
#define LMS_SCOPED_TRACE_DETAILED(CATEGORY, NAME) LMS_SCOPED_TRACE_DETAILED_WITH_ARG(CATEGORY, NAME, "", "")
#define LMS_SCOPED_TRACE_OVERVIEW(CATEGORY, NAME) LMS_SCOPED_TRACE_OVERVIEW_WITH_ARG(CATEGORY, NAME, "", "")
#define LMS_SCOPED_TRACE_DETAILED(CATEGORY, NAME) LMS_SCOPED_TRACE_DETAILED_WITH_ARG(CATEGORY, NAME, "", "")
namespace lms::core::tracing
{
@@ -124,4 +124,4 @@ namespace lms::core::tracing
ITraceLogger* _traceLogger;
ITraceLogger::CompleteEvent _event;
};
}
} // namespace lms::core::tracing
+2 -2
View File
@@ -25,7 +25,7 @@
#include "Exception.hpp"
// TODO, move elsewhere?
// TODO, move elsewhere?
namespace lms::zip
{
struct Entry
@@ -51,4 +51,4 @@ namespace lms::zip
};
std::unique_ptr<IZipper> createArchiveZipper(const EntryContainer& entries);
}
} // namespace lms::zip
+24 -12
View File
@@ -31,7 +31,11 @@ namespace lms::core
public:
constexpr LiteralString() noexcept = default;
template<std::size_t N>
constexpr LiteralString(const char(&str)[N]) noexcept : _str{ str, N - 1 } { static_assert(N > 0); }
constexpr LiteralString(const char (&str)[N]) noexcept
: _str{ str, N - 1 }
{
static_assert(N > 0);
}
constexpr bool empty() const noexcept { return _str.empty(); }
constexpr const char* c_str() const noexcept { return _str.data(); }
@@ -48,7 +52,7 @@ namespace lms::core
os << str.str();
return os;
}
}
} // namespace lms::core
namespace std
{
@@ -60,7 +64,7 @@ namespace std
return hash<std::string_view>{}(str.str());
}
};
}
} // namespace std
namespace lms::core
{
@@ -69,15 +73,18 @@ namespace lms::core
using hash_type = std::hash<std::string_view>;
using is_transparent = void;
[[nodiscard]] size_t operator()(const LiteralString& str) const {
[[nodiscard]] size_t operator()(const LiteralString& str) const
{
return hash_type{}(str.str());
}
[[nodiscard]] size_t operator()(std::string_view str) const {
[[nodiscard]] size_t operator()(std::string_view str) const
{
return hash_type{}(str);
}
[[nodiscard]] size_t operator()(const std::string& str) const {
[[nodiscard]] size_t operator()(const std::string& str) const
{
return hash_type{}(str);
}
};
@@ -86,24 +93,29 @@ namespace lms::core
{
using is_transparent = void;
[[nodiscard]] bool operator()(const LiteralString& lhs, const LiteralString& rhs) const {
[[nodiscard]] bool operator()(const LiteralString& lhs, const LiteralString& rhs) const
{
return lhs == rhs;
}
[[nodiscard]] bool operator()(const LiteralString& lhs, const std::string& rhs) const {
[[nodiscard]] bool operator()(const LiteralString& lhs, const std::string& rhs) const
{
return lhs.str() == rhs;
}
[[nodiscard]] bool operator()(const LiteralString& lhs, std::string_view rhs) const {
[[nodiscard]] bool operator()(const LiteralString& lhs, std::string_view rhs) const
{
return lhs.str() == rhs;
}
[[nodiscard]] bool operator()(const std::string_view& lhs, LiteralString rhs) const {
[[nodiscard]] bool operator()(const std::string_view& lhs, LiteralString rhs) const
{
return lhs == rhs.str();
}
[[nodiscard]] bool operator()(const std::string& lhs, const LiteralString& rhs) const {
[[nodiscard]] bool operator()(const std::string& lhs, const LiteralString& rhs) const
{
return lhs == rhs.str();
}
};
}
} // namespace lms::core
+7 -6
View File
@@ -22,15 +22,16 @@
#include <boost/asio/ip/address.hpp>
#ifndef BOOST_ASIO_HAS_STD_HASH
#include <functional>
#include <functional>
namespace std
{
template<> struct hash<boost::asio::ip::address>
{
std::size_t operator()(const boost::asio::ip::address& ipAddr) const;
};
template<>
struct hash<boost::asio::ip::address>
{
std::size_t operator()(const boost::asio::ip::address& ipAddr) const;
};
}
} // namespace std
#endif // BOOST_ASIO_HAS_STD_HASH
+2 -2
View File
@@ -49,7 +49,7 @@ namespace lms::core::pathUtils
std::filesystem::path getLongestCommonPath(const std::filesystem::path& path1, const std::filesystem::path& path2);
template <typename Iterator>
template<typename Iterator>
std::filesystem::path getLongestCommonPath(Iterator first, Iterator last)
{
std::filesystem::path longestCommonPath;
@@ -64,4 +64,4 @@ namespace lms::core::pathUtils
return longestCommonPath;
}
}
} // namespace lms::core::pathUtils
+5 -5
View File
@@ -29,27 +29,27 @@ namespace lms::core::random
RandGenerator createSeededGenerator(uint_fast32_t seed);
template <typename T>
template<typename T>
T getRandom(T min, T max)
{
std::uniform_int_distribution<> dist{ min, max };
return dist(getRandGenerator());
}
template <typename T>
template<typename T>
T getRealRandom(T min, T max)
{
std::uniform_real_distribution<> dist{ min, max };
return dist(getRandGenerator());
}
template <typename Container>
template<typename Container>
void shuffleContainer(Container& container)
{
std::shuffle(std::begin(container), std::end(container), getRandGenerator());
}
template <typename Container>
template<typename Container>
typename Container::const_iterator pickRandom(const Container& container)
{
if (container.empty())
@@ -57,4 +57,4 @@ namespace lms::core::random
return std::next(std::begin(container), getRandom(0, static_cast<int>(container.size() - 1)));
}
}
} // namespace lms::core::random
@@ -48,4 +48,4 @@ namespace lms::core
std::mutex _sharedCountMutex;
std::unordered_map<std::thread::id, std::size_t> _sharedCounts;
};
}
} // namespace lms::core
+3 -3
View File
@@ -24,7 +24,7 @@
namespace lms::core
{
template <typename Class>
template<typename Class>
class Service
{
public:
@@ -57,7 +57,7 @@ namespace lms::core
static Class* get() { return _service.get(); }
static bool exists() { return _service.get(); }
template <typename SubClass>
template<typename SubClass>
static Class& assign(std::unique_ptr<SubClass> service)
{
assert(!_service);
@@ -70,4 +70,4 @@ namespace lms::core
static inline std::unique_ptr<Class> _service;
};
}
} // namespace lms::core
+1 -1
View File
@@ -39,4 +39,4 @@ namespace lms::core::logging
std::ostream& _os;
const EnumSet<Severity> _severities;
};
}
} // namespace lms::core::logging
+4 -4
View File
@@ -22,9 +22,9 @@
#include <initializer_list>
#include <optional>
#include <span>
#include <sstream>
#include <string>
#include <string_view>
#include <sstream>
#include <vector>
#define QUOTEME(x) QUOTEME_1(x)
@@ -34,7 +34,7 @@ namespace Wt
{
class WDate;
class WDateTime;
}
} // namespace Wt
namespace lms::core::stringUtils
{
@@ -67,7 +67,7 @@ namespace lms::core::stringUtils
{
T res;
std::istringstream iss{ std::string {str} };
std::istringstream iss{ std::string{ str } };
iss >> res;
if (iss.fail())
return std::nullopt;
@@ -100,4 +100,4 @@ namespace lms::core::stringUtils
[[nodiscard]] std::string toISO8601String(const Wt::WDateTime& dateTime);
[[nodiscard]] std::string toISO8601String(const Wt::WDate& date);
}
} // namespace lms::core::stringUtils
+26 -20
View File
@@ -23,27 +23,33 @@
namespace lms::core
{
namespace details
{
template<int... Is>
struct Seq { };
namespace details
{
template<int... Is>
struct Seq
{
};
template<int N, int... Is>
struct GenSeq : GenSeq<N - 1, N - 1, Is...> { };
template<int N, int... Is>
struct GenSeq : GenSeq<N - 1, N - 1, Is...>
{
};
template<int... Is>
struct GenSeq<0, Is...> : Seq<Is...> { };
template<int... Is>
struct GenSeq<0, Is...> : Seq<Is...>
{
};
template<typename T, typename Func, int... Is>
void forEachTypeInTuple(T&& t, Func f, Seq<Is...>)
{
auto l = { (f(std::get<Is>(t)), 0)... };
}
}
template<typename T, typename Func, int... Is>
void forEachTypeInTuple(T&& t, Func f, Seq<Is...>)
{
auto l = { (f(std::get<Is>(t)), 0)... };
}
} // namespace details
template<typename... Ts, typename Func>
void forEachTypeInTuple(std::tuple<Ts...> const& t, Func f)
{
details::forEachTypeInTuple(t, f, details::GenSeq<sizeof...(Ts)>());
}
}
template<typename... Ts, typename Func>
void forEachTypeInTuple(std::tuple<Ts...> const& t, Func f)
{
details::forEachTypeInTuple(t, f, details::GenSeq<sizeof...(Ts)>());
}
} // namespace lms::core
+3 -3
View File
@@ -41,11 +41,11 @@ namespace lms::core
UUID(std::string_view value);
std::string _value;
};
}
} // namespace lms::core
namespace lms::core::stringUtils
{
template <>
template<>
std::optional<UUID>
readAs(std::string_view str);
readAs(std::string_view str);
}
+15 -14
View File
@@ -24,18 +24,19 @@
namespace lms::core::utils
{
template<class T, class Compare = std::less<>>
constexpr T clamp(T v, T lo, T hi, Compare comp = {})
{
assert(!comp(hi, lo));
return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}
template<class T, class Compare = std::less<>>
constexpr T clamp(T v, T lo, T hi, Compare comp = {})
{
assert(!comp(hi, lo));
return comp(v, lo) ? lo : comp(hi, v) ? hi :
v;
}
template <typename Container, typename T>
void
push_back_if_not_present(Container& container, const T& val)
{
if (std::find(std::cbegin(container), std::cend(container), val) == std::cend(container))
container.push_back(val);
}
}
template<typename Container, typename T>
void
push_back_if_not_present(Container& container, const T& val)
{
if (std::find(std::cbegin(container), std::cend(container), val) == std::cend(container))
container.push_back(val);
}
} // namespace lms::core::utils
+1 -1
View File
@@ -37,4 +37,4 @@ namespace lms::core::logging
void processLog(const Log& log) override;
const Severity _minSeverity;
};
}
} // namespace lms::core::logging
@@ -36,7 +36,7 @@ namespace lms::core::http
Low,
};
Priority priority{ Priority::Normal };
Priority priority{ Priority::Normal };
std::string relativeUrl; // relative to baseUrl used by the client
using OnSuccessFunc = std::function<void(std::string_view msgBody)>;
@@ -56,4 +56,4 @@ namespace lms::core::http
Wt::Http::Message message;
};
}
} // namespace lms::core::http
+10 -9
View File
@@ -20,20 +20,21 @@
#pragma once
#include <string_view>
#include <boost/asio/io_context.hpp>
#include "core/http/ClientRequestParameters.hpp"
namespace lms::core::http
{
class IClient
{
public:
virtual ~IClient() = default;
class IClient
{
public:
virtual ~IClient() = default;
virtual void sendGETRequest(ClientGETRequestParameters&& request) = 0;
virtual void sendPOSTRequest(ClientPOSTRequestParameters&& request) = 0;
};
virtual void sendGETRequest(ClientGETRequestParameters&& request) = 0;
virtual void sendPOSTRequest(ClientPOSTRequestParameters&& request) = 0;
};
std::unique_ptr<IClient> createClient(boost::asio::io_context& ioContext, std::string_view baseUrl);
}
std::unique_ptr<IClient> createClient(boost::asio::io_context& ioContext, std::string_view baseUrl);
} // namespace lms::core::http