diff options
Diffstat (limited to 'dev/lib')
| -rw-r--r-- | dev/lib/core/error_handler.hpp | 13 | ||||
| -rw-r--r-- | dev/lib/core/includes.hpp | 9 | ||||
| -rw-r--r-- | dev/lib/fix/fix.hpp | 10 | ||||
| -rw-r--r-- | dev/lib/io/print.hpp | 24 | ||||
| -rw-r--r-- | dev/lib/net/modem.hpp | 6 |
5 files changed, 47 insertions, 15 deletions
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<char>& msg) + template <bool throw_too = false> + void error(const std::basic_string<char>& msg) + { + this->operator()(msg); + + if constexpr (throw_too) + { + throw std::runtime_error(msg); + } + } + + void operator()(const std::basic_string<char>& 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 <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> #include <boost/container/allocator.hpp> + +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<char_type> magic_; - std::size_t body_len_; - std::vector<std::pair<std::basic_string<char_type>, std::basic_string<char_type>>> body_; + std::size_t magic_len_{}; + std::basic_string<char_type> magic_{}; + std::size_t body_len_{}; + std::vector<std::pair<std::basic_string<char_type>, std::basic_string<char_type>>> body_{}; static inline const char_type* begin = detail::begin_fix<char_type>(); @@ -205,7 +205,7 @@ namespace ocl::fix { if (!basic_range.is_valid()) { - handler("Invalid FIX packet"); + handler.template error<true>("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 <typename T, typename... Args> - inline void print(T fmt, Args... other) noexcept - { - std::cout << fmt; - print(other...); - } - template <typename T> inline void print(T fmt) noexcept { @@ -28,14 +21,27 @@ namespace ocl::io inline void print() noexcept { - std::cout << std::endl; + } + + template <typename... Args> + inline void print(Args... fmt) noexcept + { + print(fmt...); + print(); + } + + template <typename T, typename... Args> + inline void print(T fmt, Args... other) noexcept + { + std::cout << fmt; + print(other...); } template <typename... T> 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 <lib/tests/hpptest.hpp> + #include <unistd.h> #include <arpa/inet.h> #include <sys/socket.h> @@ -110,6 +112,10 @@ namespace ocl::net static_assert(af != 0, "Address family is zero"); static_assert(kind != 0, "Kind is zero"); + must_pass<af == AF_INET || af == AF_INET6>(); + must_pass<kind == SOCK_STREAM || kind == SOCK_DGRAM>(); + must_pass<(port > 0) && (port < 65536)>(); + fd_ = ::socket(af, kind, 0); server_fd_ = is_server; |
