From fefcf4fe616d67e1eaa1cb5dacf6b5abde69a8f1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 15 Nov 2025 13:18:36 +0100 Subject: feat: cleanup FIX' parser.hpp includes. Signed-off-by: Amlal El Mahrouss --- dev/lib/fix/parser.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 723506e..243d01c 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -16,7 +16,6 @@ #include #include #include -#include namespace ocl::fix { -- cgit v1.2.3 From d5c23fd4c37e29bc74a15491d43ef6bba8d3915a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 17 Nov 2025 00:44:50 +0100 Subject: feat: lib: replace parser.hpp with fix.hpp Signed-off-by: Amlal El Mahrouss --- dev/examples/fix/fix.cc | 2 +- dev/lib/fix/fix.hpp | 215 ++++++++++++++++++++++++++++++++++++++++ dev/lib/fix/parser.hpp | 215 ---------------------------------------- dev/tests/fix_basic/fix_test.cc | 2 +- 4 files changed, 217 insertions(+), 217 deletions(-) create mode 100644 dev/lib/fix/fix.hpp delete mode 100644 dev/lib/fix/parser.hpp diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc index e3d669b..ec6668a 100644 --- a/dev/examples/fix/fix.cc +++ b/dev/examples/fix/fix.cc @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp new file mode 100644 index 0000000..2d2c742 --- /dev/null +++ b/dev/lib/fix/fix.hpp @@ -0,0 +1,215 @@ +/* + * File: fix/fix.hpp + * Purpose: Financial Information Exchange parser in C++ + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss + */ + +#ifndef _OCL_FIX_PARSER_HPP +#define _OCL_FIX_PARSER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ocl::fix +{ + template + class basic_visitor; + + template + struct basic_range; + + template + class basic_range_data; + + /// @brief Buffer+Length structure + template + using range_ptr_t = basic_range; + + namespace detail + { + template + const char_type* begin_fix(); + + template <> + inline const char* begin_fix() + { + return "FIX."; + } + + template <> + inline const char16_t* begin_fix() + { + return u"FIX."; + } + + template <> + inline const char8_t* begin_fix() + { + return u8"FIX."; + } + } // namespace detail + + template + struct basic_range final + { + char_type* bytes_{nullptr}; + size_t length_{}; + + bool is_valid() noexcept + { + return this->bytes_ && this->length_ > 0; + } + + explicit operator bool() + { + return this->is_valid(); + } + }; + + /// @brief Convert basic_range to usable string. + /// @note This function assumes that the basic_range is valid and contains ASCII bytes. + template + inline std::basic_string to_string(basic_range& basic_range) noexcept + { + if (basic_range.length_ < 0) + return std::basic_string{}; + + return std::basic_string(basic_range.ascii_bytes_, basic_range.length_); + } + + /// @brief a basic_range object containing the FIX packet values. + template + 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_; + + static inline const char_type* begin = detail::begin_fix(); + + explicit basic_range_data() = default; + ~basic_range_data() = default; + + basic_range_data& operator=(const basic_range_data&) = default; + basic_range_data(const basic_range_data&) = default; + + std::basic_string operator[](const std::basic_string& key) + { + if (key.empty()) + { + return std::basic_string{}; + } + + for (const auto& pair : this->body_) + { + if (pair.first == key) + { + return pair.second; + } + } + + return std::basic_string{}; + } + + bool is_valid() + { + return magic_.starts_with(basic_range_data::begin); + } + + explicit operator bool() + { + return this->is_valid(); + } + }; + + /// @brief basic_visitor object which returns a fix::basic_range_data instance. + template + class basic_visitor final + { + public: + static constexpr const char_type soh = '|'; + static constexpr const char_type eq = '='; + static constexpr uint32_t base = 10U; + + explicit basic_visitor() = default; + ~basic_visitor() = default; + + basic_visitor& operator=(const basic_visitor&) = default; + basic_visitor(const basic_visitor&) = default; + + basic_range operator()(const std::basic_string& in) + { + return this->visit(in); + } + + basic_range_data visit(const std::basic_string& in) + { + thread_local basic_range_data ret{}; + + if (in.empty()) + return ret; + + static thread_local std::basic_string in_tmp{}; + + in_tmp.reserve(in.size()); + + try + { + for (auto& ch : in) + { + if (ch != basic_visitor::soh) + { + in_tmp += ch; + continue; + } + + std::basic_string key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq)); + std::basic_string val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1); + + if (ret.magic_.empty()) + { + ret.magic_ = val; + ret.magic_len_ = ret.magic_.size(); + } + else + { + ret.body_.emplace_back(std::make_pair(key, val)); + ret.body_len_ += in_tmp.size(); + } + + in_tmp.clear(); + } + } + catch (...) + { + in_tmp.clear(); + return ret; + } + + in_tmp.clear(); + return ret; + } + }; + + template + inline void must_pass(basic_range_data& basic_range, error_handler& handler) + { + if (!basic_range.is_valid()) + { + handler("Invalid FIX packet"); + } + } + + using fix_tag_type = std::uint32_t; +} // namespace ocl::fix + +#endif // ifndef _OCL_FIX_PARSER_HPP diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp deleted file mode 100644 index 243d01c..0000000 --- a/dev/lib/fix/parser.hpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * File: fix/parser.hpp - * Purpose: Financial Information Exchange parser in C++ - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss - */ - -#ifndef _OCL_FIX_PARSER_HPP -#define _OCL_FIX_PARSER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ocl::fix -{ - template - class basic_visitor; - - template - struct basic_range; - - template - class basic_range_data; - - /// @brief Buffer+Length structure - template - using range_ptr_t = basic_range; - - namespace detail - { - template - const char_type* begin_fix(); - - template <> - inline const char* begin_fix() - { - return "FIX."; - } - - template <> - inline const char16_t* begin_fix() - { - return u"FIX."; - } - - template <> - inline const char8_t* begin_fix() - { - return u8"FIX."; - } - } // namespace detail - - template - struct basic_range final - { - char_type* bytes_{nullptr}; - size_t length_{}; - - bool is_valid() noexcept - { - return this->bytes_ && this->length_ > 0; - } - - explicit operator bool() - { - return this->is_valid(); - } - }; - - /// @brief Convert basic_range to usable string. - /// @note This function assumes that the basic_range is valid and contains ASCII bytes. - template - inline std::basic_string to_string(basic_range& basic_range) noexcept - { - if (basic_range.length_ < 0) - return std::basic_string{}; - - return std::basic_string(basic_range.ascii_bytes_, basic_range.length_); - } - - /// @brief a basic_range object containing the FIX packet values. - template - 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_; - - static inline const char_type* begin = detail::begin_fix(); - - explicit basic_range_data() = default; - ~basic_range_data() = default; - - basic_range_data& operator=(const basic_range_data&) = default; - basic_range_data(const basic_range_data&) = default; - - std::basic_string operator[](const std::basic_string& key) - { - if (key.empty()) - { - return std::basic_string{}; - } - - for (const auto& pair : this->body_) - { - if (pair.first == key) - { - return pair.second; - } - } - - return std::basic_string{}; - } - - bool is_valid() - { - return magic_.starts_with(basic_range_data::begin); - } - - explicit operator bool() - { - return this->is_valid(); - } - }; - - /// @brief basic_visitor object which returns a fix::basic_range_data instance. - template - class basic_visitor final - { - public: - static constexpr const char_type soh = '|'; - static constexpr const char_type eq = '='; - static constexpr uint32_t base = 10U; - - explicit basic_visitor() = default; - ~basic_visitor() = default; - - basic_visitor& operator=(const basic_visitor&) = default; - basic_visitor(const basic_visitor&) = default; - - basic_range operator()(const std::basic_string& in) - { - return this->visit(in); - } - - basic_range_data visit(const std::basic_string& in) - { - thread_local basic_range_data ret{}; - - if (in.empty()) - return ret; - - static thread_local std::basic_string in_tmp{}; - - in_tmp.reserve(in.size()); - - try - { - for (auto& ch : in) - { - if (ch != basic_visitor::soh) - { - in_tmp += ch; - continue; - } - - std::basic_string key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq)); - std::basic_string val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1); - - if (ret.magic_.empty()) - { - ret.magic_ = val; - ret.magic_len_ = ret.magic_.size(); - } - else - { - ret.body_.emplace_back(std::make_pair(key, val)); - ret.body_len_ += in_tmp.size(); - } - - in_tmp.clear(); - } - } - catch (...) - { - in_tmp.clear(); - return ret; - } - - in_tmp.clear(); - return ret; - } - }; - - template - inline void must_pass(basic_range_data& basic_range, error_handler& handler) - { - if (!basic_range.is_valid()) - { - handler("Invalid FIX packet"); - } - } - - using fix_tag_type = std::uint32_t; -} // namespace ocl::fix - -#endif // ifndef _OCL_FIX_PARSER_HPP diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index bdde392..65e5773 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -5,7 +5,7 @@ * Copyright 2025, Amlal El Mahrouss */ -#include +#include #include TEST(FIXTest, BasicFIXUsage) -- cgit v1.2.3 From 1d943dcfcddb68f489c126b1e0df41170287e63d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 17 Nov 2025 10:15:38 +0100 Subject: feat: lib: make licensing clear. Signed-off-by: Amlal El Mahrouss --- compile_flags.txt | 2 +- dev/lib/core/includes.hpp | 2 +- dev/lib/except/error.hpp | 5 +++-- dev/lib/fix/fix.hpp | 2 +- dev/lib/logic/equiv.hpp | 2 +- dev/lib/memory/allocator_system.hpp | 1 - dev/lib/memory/tracked_ptr.hpp | 2 +- dev/lib/net/modem.hpp | 3 +-- dev/lib/net/url.hpp | 2 +- dev/lib/tests/gtest.hpp | 2 +- dev/lib/tests/hpptest.hpp | 2 +- dev/tests/chunk_string/chunk_test.cc | 2 +- dev/tests/fix_basic/fix_test.cc | 2 +- dev/tests/network_basic/net_test.cc | 2 +- dev/tests/tracked_ptr_basic/tracked_ptr_test.cc | 2 +- dev/tests/tracked_ptr_leak/tracked_ptr_test.cc | 2 +- 16 files changed, 17 insertions(+), 18 deletions(-) diff --git a/compile_flags.txt b/compile_flags.txt index 1c9f6fb..da935d4 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,4 +2,4 @@ -std=c++20 -DEMBFS_28BIT_LBA -xc++ --I/opt/homebrew/Cellar/boost/1.87.0/include \ No newline at end of file +-I/opt/homebrew/Cellar/boost/1.89.0/include \ No newline at end of file diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp index f988fc1..ff59535 100644 --- a/dev/lib/core/includes.hpp +++ b/dev/lib/core/includes.hpp @@ -2,7 +2,7 @@ * File: core/includes.hpp * Purpose: Core includes for the OCL library. * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #pragma once diff --git a/dev/lib/except/error.hpp b/dev/lib/except/error.hpp index 16bf5eb..73e0074 100644 --- a/dev/lib/except/error.hpp +++ b/dev/lib/except/error.hpp @@ -8,13 +8,14 @@ #define _OCL_ERR_HPP #include +#include -namespace ocl +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 +} // namespace ocl::error #endif // _OCL_ERR_HPP \ No newline at end of file diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp index 2d2c742..8035d55 100644 --- a/dev/lib/fix/fix.hpp +++ b/dev/lib/fix/fix.hpp @@ -2,7 +2,7 @@ * File: fix/fix.hpp * Purpose: Financial Information Exchange parser in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #ifndef _OCL_FIX_PARSER_HPP diff --git a/dev/lib/logic/equiv.hpp b/dev/lib/logic/equiv.hpp index 5b022f8..704e451 100644 --- a/dev/lib/logic/equiv.hpp +++ b/dev/lib/logic/equiv.hpp @@ -2,7 +2,7 @@ * File: equiv.hpp * Purpose: Equivalence runtime c++ header. * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #pragma once diff --git a/dev/lib/memory/allocator_system.hpp b/dev/lib/memory/allocator_system.hpp index 1243ed5..6fd0119 100644 --- a/dev/lib/memory/allocator_system.hpp +++ b/dev/lib/memory/allocator_system.hpp @@ -9,7 +9,6 @@ #define _OCL_ALLOCATOR_SYSTEM_HPP #include -#include #include namespace ocl diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp index d2f8450..61daada 100644 --- a/dev/lib/memory/tracked_ptr.hpp +++ b/dev/lib/memory/tracked_ptr.hpp @@ -2,7 +2,7 @@ * File: memory/tracked_ptr.hpp * Purpose: Custom smart pointer implementation in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #pragma once diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index 074f182..450aee1 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -2,7 +2,7 @@ * File: net/modem.hpp * Purpose: Modem concept in modern C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #ifndef _OCL_NET_NETWORK_HPP @@ -12,7 +12,6 @@ #include #include #include -#include #include #define OCL_MODEM_INTERFACE : public ocl::net::basic_modem diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index ff6aebe..a337538 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -2,7 +2,7 @@ * File: net/url.hpp * Purpose: URL container in modern C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #pragma once diff --git a/dev/lib/tests/gtest.hpp b/dev/lib/tests/gtest.hpp index deb2ddf..31ae5d7 100644 --- a/dev/lib/tests/gtest.hpp +++ b/dev/lib/tests/gtest.hpp @@ -2,7 +2,7 @@ * File: tests/gtest.hpp * Purpose: Google Test wrapper for the OCL library. * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp index f520339..5f78179 100644 --- a/dev/lib/tests/hpptest.hpp +++ b/dev/lib/tests/hpptest.hpp @@ -2,7 +2,7 @@ * File: tests/hpptest.hpp * Purpose: HPP Test wrapper for the OCL library. * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #pragma once diff --git a/dev/tests/chunk_string/chunk_test.cc b/dev/tests/chunk_string/chunk_test.cc index be7a457..973ce43 100644 --- a/dev/tests/chunk_string/chunk_test.cc +++ b/dev/tests/chunk_string/chunk_test.cc @@ -2,7 +2,7 @@ * File: tests/chunk_test.cc * Purpose: Chunk unit tests in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index 65e5773..5599ed4 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -2,7 +2,7 @@ * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc index 61d0b28..f8b9f2d 100644 --- a/dev/tests/network_basic/net_test.cc +++ b/dev/tests/network_basic/net_test.cc @@ -2,7 +2,7 @@ * File: tests/net_test.cc * Purpose: Network unit tests in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include diff --git a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc index 1e97188..61d4f7d 100644 --- a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc @@ -2,7 +2,7 @@ * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include diff --git a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc index f349f47..fb21c34 100644 --- a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc @@ -2,7 +2,7 @@ * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss + * Copyright 2025, Amlal El Mahrouss, licensed under the MIT license. */ #include -- cgit v1.2.3