summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ocl/core/allocator_op.hpp10
-rw-r--r--include/ocl/core/chunk_string.hpp8
-rw-r--r--include/ocl/core/config.hpp17
-rw-r--r--include/ocl/core/error.hpp21
-rw-r--r--include/ocl/core/error_handler.hpp46
-rw-r--r--include/ocl/core/handler.hpp42
-rw-r--r--include/ocl/core/is_same.hpp (renamed from include/ocl/core/equiv.hpp)8
-rw-r--r--include/ocl/core/option.hpp (renamed from include/ocl/core/opt.hpp)39
-rw-r--r--include/ocl/crc32/crc32.hpp (renamed from include/ocl/checksum/crc32.hpp)9
-rw-r--r--include/ocl/fix/checksum.hpp4
-rw-r--r--include/ocl/fix/parser.hpp4
-rw-r--r--include/ocl/io/print.hpp14
-rw-r--r--include/ocl/net/unique_socket.hpp (renamed from include/ocl/net/modem.hpp)41
13 files changed, 121 insertions, 142 deletions
diff --git a/include/ocl/core/allocator_op.hpp b/include/ocl/core/allocator_op.hpp
index 8fb8ce9..c086901 100644
--- a/include/ocl/core/allocator_op.hpp
+++ b/include/ocl/core/allocator_op.hpp
@@ -40,8 +40,8 @@ namespace ocl
template <typename ret_type, typename allocator_new, typename allocator_delete>
class allocator_op
{
- allocator_new m_alloc_{};
- allocator_delete m_free_{};
+ allocator_new alloc_op_{};
+ allocator_delete free_op_{};
public:
allocator_op() = default;
@@ -52,18 +52,18 @@ namespace ocl
ret_type* claim()
{
- return m_alloc_();
+ return alloc_op_();
}
template <typename... var_type>
auto construct(var_type... args) -> std::shared_ptr<ret_type>
{
- return std::shared_ptr<ret_type>(m_alloc_.template var_alloc<var_type...>(args...), allocator_delete{});
+ return std::shared_ptr<ret_type>(alloc_op_.template var_alloc<var_type...>(args...), allocator_delete{});
}
void unclaim(ret_type* ptr)
{
- m_free_(ptr);
+ free_op_(ptr);
}
};
diff --git a/include/ocl/core/chunk_string.hpp b/include/ocl/core/chunk_string.hpp
index 17d81bd..a2380f6 100644
--- a/include/ocl/core/chunk_string.hpp
+++ b/include/ocl/core/chunk_string.hpp
@@ -24,7 +24,7 @@ namespace ocl
using condition_type = bool;
private:
- char_type packed_chunks_[max_chunk_size] = {0};
+ char_type chunk_[max_chunk_size] = {0};
std::size_t chunk_total_{};
condition_type bad_{false};
@@ -84,7 +84,7 @@ namespace ocl
if (chunk_total_ < size_max_chunk)
{
- std::memcpy(packed_chunks_ + chunk_total_, ptr, sz);
+ std::memcpy(chunk_ + chunk_total_, ptr, sz);
chunk_total_ += sz;
}
@@ -102,14 +102,14 @@ namespace ocl
else
return ret;
- ret = packed_chunks_;
+ ret = chunk_;
return ret;
}
void print() noexcept
{
- ocl::io::print(packed_chunks_);
+ ocl::io::print(chunk_);
}
};
diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp
index 15439d8..c354672 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -8,38 +8,31 @@
#pragma once
#include <boost/config.hpp>
+#include <boost/core/addressof.hpp>
#include <boost/core/nvp.hpp>
#include <boost/core/demangle.hpp>
#include <boost/core/null_deleter.hpp>
#include <boost/container/allocator.hpp>
#include <boost/assert.hpp>
-#include <cstddef>
#include <cassert>
-#include <utility>
-#include <string>
-#include <vector>
-#include <cstdint>
+
#include <sys/types.h>
#include <unistd.h>
-#define OCL_DEPRECATED() [[deprecated]]
-#define OCL_DEPRECATED_MSG(MSG) [[deprecated( MSG )]]
+#define OCL_DEPRECATED() [[deprecated]]
+#define OCL_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
#ifdef __cplusplus
#define OCL_DECL extern "C"
/// DLL/Dylib/So specific macro.
#define OCL_EXPORT_DECL extern "C" BOOST_SYMBOL_EXPORT
#else
-#define OCL_DECL
+#define OCL_DECL
#define OCL_EXPORT_DECL
#endif
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/include/ocl/core/error.hpp b/include/ocl/core/error.hpp
deleted file mode 100644
index cf038f8..0000000
--- a/include/ocl/core/error.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * File: opt.hpp
- * Author: Amlal El Mahrouss,
- * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License
- */
-
-#ifndef _OCL_ERR_HPP
-#define _OCL_ERR_HPP
-
-#include <stdexcept>
-#include <core/error_handler.hpp>
-
-namespace ocl::error
-{
- using runtime_error = std::runtime_error;
- using fix_error = runtime_error;
- using math_error = runtime_error;
- using cgi_error = runtime_error;
-} // namespace ocl::error
-
-#endif // _OCL_ERR_HPP \ No newline at end of file
diff --git a/include/ocl/core/error_handler.hpp b/include/ocl/core/error_handler.hpp
deleted file mode 100644
index 971d91c..0000000
--- a/include/ocl/core/error_handler.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * File: core/basic_error_handler.hpp
- * Purpose: Error handler container.
- * Author: Amlal El Mahrouss (amlal@nekernel.org)
- * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License.
- */
-
-#ifndef _OCL_ERROR_HANDLER_HPP
-#define _OCL_ERROR_HANDLER_HPP
-
-#include <core/config.hpp>
-#include <io/print.hpp>
-
-namespace ocl
-{
- struct basic_error_handler;
-
- struct basic_error_handler
- {
- explicit basic_error_handler() = default;
- virtual ~basic_error_handler() = default;
-
- basic_error_handler& operator=(const basic_error_handler&) = default;
- basic_error_handler(const basic_error_handler&) = default;
-
- 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);
- }
- };
-
- using error_handler_type = basic_error_handler;
-} // namespace ocl
-
-#endif // ifndef _OCL_ERROR_HANDLER_HPP
diff --git a/include/ocl/core/handler.hpp b/include/ocl/core/handler.hpp
new file mode 100644
index 0000000..e31f0d4
--- /dev/null
+++ b/include/ocl/core/handler.hpp
@@ -0,0 +1,42 @@
+/*
+ * File: core/handler.hpp
+ * Purpose: Handler container.
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License.
+ */
+
+#ifndef _OCL_ERROR_HANDLER_HPP
+#define _OCL_ERROR_HANDLER_HPP
+
+#include <core/config.hpp>
+#include <io/print.hpp>
+#include <exception>
+
+namespace ocl
+{
+ struct handler;
+
+ struct handler
+ {
+ private:
+ template <typename T>
+ void handle_impl(T element) {}
+
+ public:
+ using error_type = std::exception;
+
+ explicit handler() = default;
+ virtual ~handler() = default;
+
+ handler& operator=(const handler&) = default;
+ handler(const handler&) = default;
+
+ template <typename T>
+ void operator()(T element)
+ {
+ this->handle_impl<T>(element);
+ }
+ };
+} // namespace ocl
+
+#endif // ifndef _OCL_ERROR_HANDLER_HPP
diff --git a/include/ocl/core/equiv.hpp b/include/ocl/core/is_same.hpp
index f98d86d..e6f42c4 100644
--- a/include/ocl/core/equiv.hpp
+++ b/include/ocl/core/is_same.hpp
@@ -1,5 +1,5 @@
/*
- * File: equiv.hpp
+ * File: is_same.hpp
* Purpose: Equivalence header.
* Author: Amlal El Mahrouss (amlal@nekernel.org)
* Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
@@ -10,10 +10,10 @@
#include <core/config.hpp>
/// @brief OCL equivalence namespace.
-namespace ocl::equiv
+namespace ocl::is_same
{
template <typename T>
- struct basic_hash_trait
+ struct basic_hash
{
/// @brief hash from T's result_type.
static typename T::result_type hash()
@@ -103,4 +103,4 @@ namespace ocl::equiv
return left_ / right_ == 1;
}
};
-} // namespace ocl::equiv
+} // namespace ocl::is_same
diff --git a/include/ocl/core/opt.hpp b/include/ocl/core/option.hpp
index 506f582..5bae9a2 100644
--- a/include/ocl/core/opt.hpp
+++ b/include/ocl/core/option.hpp
@@ -1,5 +1,5 @@
/*
- * File: opt.hpp
+ * File: option.hpp
* Author: Amlal El Mahrouss,
* Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License
*/
@@ -21,37 +21,42 @@ namespace ocl
};
template <typename char_type = char>
- struct opt final
+ struct option final
{
- explicit opt(const return_type& return_type)
- : m_ret(return_type)
+ explicit option(const return_type& return_type)
+ : ret_(return_type)
{
}
- opt& expect(const char_type* input)
+ ~option() = default;
+
+ option& operator=(const option&) = default;
+ option(const option&) = default;
+
+ option& expect(const char_type* input)
{
- if (m_ret == return_type::err)
+ if (ret_ == return_type::err)
{
- throw std::runtime_error(input ? input : "opt::error");
+ throw std::runtime_error(input ? input : "option::error");
}
return *this;
}
template <typename ErrorHandler>
- opt& expect_or_handle(const char_type* input)
+ option& expect_or_handle(const char_type* input)
{
- if (m_ret == return_type::err)
+ if (ret_ == return_type::err)
{
ErrorHandler err_handler;
- err_handler(input ? input : "opt::error");
+ err_handler(input ? input : "option::error");
}
return *this;
}
private:
- return_type m_ret{return_type::invalid};
+ return_type ret_{return_type::invalid};
};
template <typename Teller, typename... Lst>
@@ -64,10 +69,6 @@ namespace ocl
{
struct int_eq_teller
{
- explicit int_eq_teller()
- {
- }
-
bool operator()(int a, int b)
{
return (a == b);
@@ -76,10 +77,6 @@ namespace ocl
struct int_greater_than_teller
{
- explicit int_greater_than_teller()
- {
- }
-
bool operator()(int a, int b)
{
return (a > b);
@@ -88,10 +85,6 @@ namespace ocl
struct int_less_than_teller
{
- explicit int_less_than_teller()
- {
- }
-
bool operator()(int a, int b)
{
return (a < b);
diff --git a/include/ocl/checksum/crc32.hpp b/include/ocl/crc32/crc32.hpp
index 2bcab29..0ee1f8c 100644
--- a/include/ocl/checksum/crc32.hpp
+++ b/include/ocl/crc32/crc32.hpp
@@ -8,12 +8,13 @@
#ifndef _OCL_CRC32_HPP
#define _OCL_CRC32_HPP
+#include <core/config.hpp>
#include <cstdint>
#include <string>
#include <cstddef>
/// @brief Crc32 implementation in C++
-/// @author Amlal EL Mahrouss (amlal@nekernel.org)
+/// @author Amlal El Mahrouss (amlal@nekernel.org)
namespace ocl::crc32
{
@@ -55,9 +56,9 @@ namespace ocl::crc32
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
- template <typename char_type>
+ template <typename buffer_type>
inline std::uint32_t
- crc32(const char_type* in, size_t len) noexcept
+ crc32(buffer_type in, size_t len) noexcept
{
if (!in || *in == 0)
return 0;
@@ -74,7 +75,7 @@ namespace ocl::crc32
template <typename char_type = char>
inline std::uint32_t hash(const std::basic_string<char_type>& in)
{
- return detail::crc32(in.c_str(), in.size());
+ return detail::crc32<const char_type*>(in.c_str(), in.size());
}
} // namespace ocl::crc32
diff --git a/include/ocl/fix/checksum.hpp b/include/ocl/fix/checksum.hpp
index 9205664..807b9b0 100644
--- a/include/ocl/fix/checksum.hpp
+++ b/include/ocl/fix/checksum.hpp
@@ -8,3 +8,7 @@
#pragma once
#include <core/config.hpp>
+
+namespace ocl::fix
+{
+} \ No newline at end of file
diff --git a/include/ocl/fix/parser.hpp b/include/ocl/fix/parser.hpp
index 3d24cf0..71e0eb6 100644
--- a/include/ocl/fix/parser.hpp
+++ b/include/ocl/fix/parser.hpp
@@ -10,9 +10,9 @@
#include <core/config.hpp>
#include <io/print.hpp>
-
#include <algorithm>
#include <string>
+#include <vector>
namespace ocl::fix
{
@@ -216,7 +216,7 @@ namespace ocl::fix
}
}
- using fix_tag_type = std::uint32_t;
+ using fix_tag_type = std::basic_string<char>;
using range_data = basic_range_data<char>;
using visitor = basic_visitor<char>;
diff --git a/include/ocl/io/print.hpp b/include/ocl/io/print.hpp
index 9629e05..1220cec 100644
--- a/include/ocl/io/print.hpp
+++ b/include/ocl/io/print.hpp
@@ -9,14 +9,17 @@
#define _OCL_PRINT_HPP
#include <core/config.hpp>
+
#include <iostream>
+#define console_io_out std::cout
+
namespace ocl::io
{
template <typename T>
inline void print(T fmt) noexcept
{
- std::cout << fmt;
+ console_io_out << fmt;
}
inline void print() noexcept {}
@@ -31,7 +34,7 @@ namespace ocl::io
template <typename T, typename... Args>
inline void print(T fmt, Args... other) noexcept
{
- std::cout << fmt;
+ console_io_out << fmt;
print(other...);
}
@@ -39,8 +42,15 @@ namespace ocl::io
inline void println(T... fmt) noexcept
{
print(fmt...);
+
+#ifdef _WIN32
+ print("\r\n");
+#else
print("\n");
+#endif
}
} // namespace ocl::io
+#undef console_io_out
+
#endif // ifndef _OCL_PRINT_HPP
diff --git a/include/ocl/net/modem.hpp b/include/ocl/net/unique_socket.hpp
index 1e58d1d..906853f 100644
--- a/include/ocl/net/modem.hpp
+++ b/include/ocl/net/unique_socket.hpp
@@ -1,6 +1,6 @@
/*
- * File: net/modem.hpp
- * Purpose: Modem concept in modern C++
+ * File: net/unique_socket.hpp
+ * Purpose: RAII socket concept in modern C++
* Author: Amlal El Mahrouss (amlal@nekernel.org)
* Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
*/
@@ -16,20 +16,18 @@
#include <cstddef>
#include <cstring>
-#define OCL_MODEM_INTERFACE : public ocl::net::modem
-
#ifdef _WIN32
-#error !!! "Windows is not supported yet for <modem>" !!!
+#error !!! "Windows is not supported yet for <socket>" !!!
#endif // _WIN32
namespace ocl::net
{
- class modem;
+ class unique_socket;
/// =============================================================================
/// @brief Modem container concept, a container to read and write on a network stream.
/// =============================================================================
- class modem final
+ class unique_socket final
{
public:
using socket_type = int64_t;
@@ -44,22 +42,22 @@ namespace ocl::net
public:
const error_type& bad{bad_};
- explicit modem() = default;
+ unique_socket() = default;
- ~modem()
+ ~unique_socket()
{
this->destroy();
}
- modem& operator=(const modem&) = delete;
- modem(const modem&) = delete;
+ unique_socket& operator=(const unique_socket&) = delete;
+ unique_socket(const unique_socket&) = default;
static constexpr auto local_address_ip4 = "127.0.0.1";
static constexpr auto local_address_ip6 = "::1";
static constexpr const auto backlog_count = 5U;
/// =============================================================================
- /// @brief Check if the modem is valid.
+ /// @brief Check if the unique_socket is valid.
/// @return true if valid, false otherwise.
/// =============================================================================
@@ -120,16 +118,12 @@ namespace ocl::net
return ret >= 0L;
}
- template <int32_t af, int32_t kind, int32_t port>
- bool construct(const char* addr = modem::local_address_ip4, const bool& is_server = false) noexcept
+ template <uint16_t af, uint16_t kind, uint16_t port>
+ bool construct(const char* addr = unique_socket::local_address_ip4, const bool& is_server = false) noexcept
{
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);
is_server_ = is_server;
@@ -153,7 +147,7 @@ namespace ocl::net
bad_ = ret == -1;
- ::listen(fd_, modem::backlog_count);
+ ::listen(fd_, unique_socket::backlog_count);
return bad_ == false;
}
@@ -171,4 +165,13 @@ namespace ocl::net
return true;
}
};
+
+ template<typename char_type, uint16_t port>
+ inline unique_socket make_socket(const std::basic_string<char_type>& address, const bool is_server)
+ {
+ unique_socket sock;
+ sock.construct<AF_INET, SOCK_STREAM, port>(address.c_str(), is_server);
+
+ return sock;
+ }
} // namespace ocl::net