summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-25 01:09:51 -0500
committerGitHub <noreply@github.com>2025-11-25 01:09:51 -0500
commit11184da83066ebc60bfd8b5d077b2bedd4d5084b (patch)
treef43070a369c6e83dae119ba0291b4c2e70d10a51
parentb9b5224ed9d045437425ad129ffb83b9d0de850c (diff)
parent223e9f06e4db61b0bc79a6d56030bb9b6a681bfb (diff)
Merge pull request #23 from amlel-el-mahrouss/develop
feat: new FIX parser and improvements on the library in general.
-rw-r--r--examples/fix/fix.cc8
-rw-r--r--include/ocl/core/chunk_string.hpp2
-rw-r--r--include/ocl/core/config.hpp4
-rw-r--r--include/ocl/core/error_handler.hpp10
-rw-r--r--include/ocl/fix/parser.hpp69
-rw-r--r--include/ocl/memory/tracked_ptr.hpp4
-rw-r--r--include/ocl/net/url.hpp2
7 files changed, 57 insertions, 42 deletions
diff --git a/examples/fix/fix.cc b/examples/fix/fix.cc
index 3dbfafb..8c019ce 100644
--- a/examples/fix/fix.cc
+++ b/examples/fix/fix.cc
@@ -38,12 +38,8 @@ int main(int argc, char** argv)
ocl::basic_error_handler handler;
ocl::fix::must_pass<char, ocl::basic_error_handler>(fix, handler);
- for (auto fields : fix.body_)
- {
- ocl::io::print("key=", fields.first);
- ocl::io::print(":value=", fields.second);
- ocl::io::print("\n");
- }
+ ocl::io::print(":key=9\n");
+ ocl::io::print(":value=", fix["35"], "\n");
return 0;
}
diff --git a/include/ocl/core/chunk_string.hpp b/include/ocl/core/chunk_string.hpp
index c60b0a4..ebcfda3 100644
--- a/include/ocl/core/chunk_string.hpp
+++ b/include/ocl/core/chunk_string.hpp
@@ -1,5 +1,5 @@
/*
-* File: core/chunk_string.hpp
+ * File: core/chunk_string.hpp
* Purpose: String implementation for the OCL C++ library.
* Author: Amlal El Mahrouss (amlal@nekernel.org)
* Copyright 2025, Amlal El Mahrouss
diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp
index 59f2491..7e74c81 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -25,9 +25,9 @@
#ifdef __cplusplus
/// DLL/Dylib/So specific macro.
-# define OCL_EXPORT_DECL extern "C" BOOST_SYMBOL_EXPORT
+#define OCL_EXPORT_DECL extern "C" BOOST_SYMBOL_EXPORT
#else
-# define OCL_EXPORT_DECL
+#define OCL_EXPORT_DECL
#endif
namespace ocl
diff --git a/include/ocl/core/error_handler.hpp b/include/ocl/core/error_handler.hpp
index a09f450..dcb0c89 100644
--- a/include/ocl/core/error_handler.hpp
+++ b/include/ocl/core/error_handler.hpp
@@ -1,9 +1,9 @@
/*
-* 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.
-*/
+ * 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
diff --git a/include/ocl/fix/parser.hpp b/include/ocl/fix/parser.hpp
index a513a1f..5d4e5eb 100644
--- a/include/ocl/fix/parser.hpp
+++ b/include/ocl/fix/parser.hpp
@@ -8,7 +8,10 @@
#ifndef _OCL_FIX_PARSER_HPP
#define _OCL_FIX_PARSER_HPP
+#include <algorithm>
#include <core/config.hpp>
+#include <string>
+#include <io/print.hpp>
namespace ocl::fix
{
@@ -98,17 +101,14 @@ namespace ocl::fix
std::basic_string<char_type> operator[](const std::basic_string<char_type>& key)
{
if (key.empty())
- {
return std::basic_string<char_type>{};
- }
- for (const auto& pair : this->body_)
- {
- if (pair.first == key)
- {
- return pair.second;
- }
- }
+ auto it = std::find_if(this->body_.begin(), this->body_.end(), [&key](const std::pair<std::basic_string<char_type>, std::basic_string<char_type>>& in) {
+ return in.first == key;
+ });
+
+ if (it != this->body_.cend())
+ return it->second;
return std::basic_string<char_type>{};
}
@@ -130,7 +130,7 @@ namespace ocl::fix
{
public:
/// AMLALE: Yeah...
- static constexpr const char_type soh = 0x01;
+ static constexpr const int soh = '\x01';
static constexpr const char_type eq = '=';
static constexpr uint32_t base = 10U;
@@ -148,41 +148,60 @@ namespace ocl::fix
/// @brief Visit a FIX message and parse it into a basic_range_data object.
/// @param in The input FIX message as a string.
/// @warning This function may throw exceptions.
- basic_range_data<char_type> visit(const std::basic_string<char_type>& in)
+ basic_range_data<char_type> visit(std::basic_string<char_type> in)
{
- thread_local basic_range_data<char_type> ret{};
+ basic_range_data<char_type> ret{};
if (in.empty())
return ret;
- std::basic_string<char_type> in_tmp{"", in.size()};
+ std::basic_string<char_type> key;
- for (auto& ch : in)
+ std::size_t off = 0UL;
+
+ while (true)
{
- if (ch != basic_visitor::soh)
+ if (in.size() < off)
+ break;
+
+ if (in[off] != basic_visitor::eq)
{
- in_tmp += ch;
+ if (in[off] == basic_visitor::soh)
+ {
+ ++off;
+ continue;
+ }
+
+ key += in[off];
+ ++off;
continue;
}
- std::basic_string<char_type> key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq));
- std::basic_string<char_type> val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1);
+ if (in.size() < (off + 1))
+ break;
+
+ std::basic_string<char_type> val = in.substr(off + 1);
+
+ if (val.find(basic_visitor::soh) != std::basic_string<char_type>::npos)
+ {
+ val.erase(val.find(basic_visitor::soh));
+ }
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();
+ ret.body_.emplace_back(std::make_pair(key, val));
+
+ off += val.size() + 1;
+
+ key.clear();
}
- in_tmp.clear();
+ ret.body_len_ = ret.body_.size();
+
return ret;
}
};
diff --git a/include/ocl/memory/tracked_ptr.hpp b/include/ocl/memory/tracked_ptr.hpp
index 029e424..f763802 100644
--- a/include/ocl/memory/tracked_ptr.hpp
+++ b/include/ocl/memory/tracked_ptr.hpp
@@ -94,7 +94,7 @@ namespace ocl::memory
public:
using pointer_type = T*;
-
+
const tracked_allocator<T>& allocator() noexcept
{
return allocator_;
@@ -144,7 +144,7 @@ namespace ocl::memory
this->reset();
}
- tracked_ptr(const tracked_ptr&) = delete;
+ tracked_ptr(const tracked_ptr&) = delete;
tracked_ptr& operator=(const tracked_ptr&) = delete;
public:
diff --git a/include/ocl/net/url.hpp b/include/ocl/net/url.hpp
index ebfc57a..fab1eb7 100644
--- a/include/ocl/net/url.hpp
+++ b/include/ocl/net/url.hpp
@@ -36,7 +36,7 @@ namespace ocl::net
bad = 0xff,
};
- uint32_t m_protocol_{basic_url::invalid};
+ uint32_t m_protocol_{basic_url::invalid};
std::basic_stringstream<char_type> m_ss_{};
std::basic_string<char_type> m_port_{""};