From 9eec329ebdf4cf079619edb58dbcd78ce42b8626 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Nov 2025 07:44:48 +0100 Subject: feat: lib: error_handler improvements, new method. FIX module improvements. Signed-off-by: Amlal El Mahrouss --- dev/lib/core/error_handler.hpp | 13 ++++++++++++- dev/lib/core/includes.hpp | 9 +++++++++ dev/lib/fix/fix.hpp | 10 +++++----- dev/lib/io/print.hpp | 24 +++++++++++++++--------- dev/lib/net/modem.hpp | 6 ++++++ 5 files changed, 47 insertions(+), 15 deletions(-) (limited to 'dev/lib') diff --git a/dev/lib/core/error_handler.hpp b/dev/lib/core/error_handler.hpp index 67bf7b4..4234721 100644 --- a/dev/lib/core/error_handler.hpp +++ b/dev/lib/core/error_handler.hpp @@ -23,7 +23,18 @@ namespace ocl basic_error_handler& operator=(const basic_error_handler&) = delete; basic_error_handler(const basic_error_handler&) = delete; - virtual void operator()(const std::basic_string& msg) + template + void error(const std::basic_string& msg) + { + this->operator()(msg); + + if constexpr (throw_too) + { + throw std::runtime_error(msg); + } + } + + void operator()(const std::basic_string& msg) { ocl::io::print(msg); } diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp index ff59535..78eccd3 100644 --- a/dev/lib/core/includes.hpp +++ b/dev/lib/core/includes.hpp @@ -12,3 +12,12 @@ #include #include #include + +namespace ocl +{ +#ifdef OCL_USE_UTF8 + using char_type = char8_t; +#else + using char_type = char; +#endif +} // namespace ocl \ No newline at end of file diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp index 9490004..67376e3 100644 --- a/dev/lib/fix/fix.hpp +++ b/dev/lib/fix/fix.hpp @@ -89,10 +89,10 @@ namespace ocl::fix class basic_range_data final { public: - std::size_t magic_len_; - std::basic_string magic_; - std::size_t body_len_; - std::vector, std::basic_string>> body_; + std::size_t magic_len_{}; + std::basic_string magic_{}; + std::size_t body_len_{}; + std::vector, std::basic_string>> body_{}; static inline const char_type* begin = detail::begin_fix(); @@ -205,7 +205,7 @@ namespace ocl::fix { if (!basic_range.is_valid()) { - handler("Invalid FIX packet"); + handler.template error("Invalid FIX packet"); } } diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp index 307c06f..466b698 100644 --- a/dev/lib/io/print.hpp +++ b/dev/lib/io/print.hpp @@ -13,13 +13,6 @@ namespace ocl::io { - template - inline void print(T fmt, Args... other) noexcept - { - std::cout << fmt; - print(other...); - } - template inline void print(T fmt) noexcept { @@ -28,14 +21,27 @@ namespace ocl::io inline void print() noexcept { - std::cout << std::endl; + } + + template + inline void print(Args... fmt) noexcept + { + print(fmt...); + print(); + } + + template + inline void print(T fmt, Args... other) noexcept + { + std::cout << fmt; + print(other...); } template inline void println(T... fmt) noexcept { print(fmt...); - print(); + print("\n"); } } // namespace ocl::io diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index 80b3b7a..7c07191 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -8,6 +8,8 @@ #ifndef _OCL_NET_NETWORK_HPP #define _OCL_NET_NETWORK_HPP +#include + #include #include #include @@ -110,6 +112,10 @@ namespace ocl::net static_assert(af != 0, "Address family is zero"); static_assert(kind != 0, "Kind is zero"); + must_pass(); + must_pass(); + must_pass<(port > 0) && (port < 65536)>(); + fd_ = ::socket(af, kind, 0); server_fd_ = is_server; -- cgit v1.2.3