summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--dev/examples/fix/CMakeLists.txt3
-rw-r--r--dev/examples/fix/fix.cc9
-rw-r--r--dev/lib/core/error_handler.hpp13
-rw-r--r--dev/lib/core/includes.hpp9
-rw-r--r--dev/lib/fix/fix.hpp10
-rw-r--r--dev/lib/io/print.hpp24
-rw-r--r--dev/lib/net/modem.hpp6
8 files changed, 57 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index 35e3f5b..9b31843 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
docs/html
docs/latex
+build*/
build/
.idea
diff --git a/dev/examples/fix/CMakeLists.txt b/dev/examples/fix/CMakeLists.txt
index db8921b..5ed31e7 100644
--- a/dev/examples/fix/CMakeLists.txt
+++ b/dev/examples/fix/CMakeLists.txt
@@ -6,7 +6,10 @@ project(
VERSION 1.0
LANGUAGES CXX)
+find_package(Boost REQUIRED COMPONENTS container)
+
add_executable(Fix fix.cc)
+target_link_libraries(Fix PRIVATE Boost::container)
set_property(TARGET Fix PROPERTY CXX_STANDARD 20)
target_include_directories(Fix PUBLIC ../../)
diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc
index ec6668a..4015a67 100644
--- a/dev/examples/fix/fix.cc
+++ b/dev/examples/fix/fix.cc
@@ -4,10 +4,12 @@
licensed under the MIT license
*/
+#include <lib/core/error_handler.hpp>
#include <lib/net/modem.hpp>
#include <lib/fix/fix.hpp>
#include <iostream>
#include <unistd.h>
+#include <lib/io/print.hpp>
#include <sys/socket.h>
/* finally test it */
@@ -22,12 +24,13 @@ int main(int argc, char** argv)
std::cout << "magic_len=" << fix.magic_len_ << std::endl;
std::cout << "is_valid=" << std::boolalpha << fix.is_valid() << std::endl;
- ocl::fix::must_pass(fix);
+ ocl::basic_error_handler handler;
+ ocl::fix::must_pass<char, ocl::basic_error_handler>(fix, handler);
for (auto fields : fix.body_)
{
- std::cout << "key=" << fields.first;
- std::cout << ":value=" << fields.second << std::endl;
+ ocl::io::print("key=", fields.first);
+ ocl::io::print(", value=", fields.second);
}
return 0;
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;