From 83bdb3bd0ce5ca6301aec047c1886c8d00e34085 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 28 Nov 2025 10:15:01 -0500 Subject: chore: basic_url has new ref_type, new deprecated macros. Signed-off-by: Amlal El Mahrouss --- include/ocl/core/config.hpp | 3 +++ include/ocl/net/url.hpp | 6 +++--- include/ocl/simd/basic_simd.hpp | 12 +++++++++--- include/ocl/simd/simd.hpp | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp index 7e74c81..4fdfc4e 100644 --- a/include/ocl/core/config.hpp +++ b/include/ocl/core/config.hpp @@ -23,6 +23,9 @@ #include #include +#define OCL_DEPRECATED() [[deprecated]] +#define OCL_DEPRECATED_MSG(MSG) [[deprecated( MSG )]] + #ifdef __cplusplus /// DLL/Dylib/So specific macro. #define OCL_EXPORT_DECL extern "C" BOOST_SYMBOL_EXPORT diff --git a/include/ocl/net/url.hpp b/include/ocl/net/url.hpp index 1b5f80c..361cd66 100644 --- a/include/ocl/net/url.hpp +++ b/include/ocl/net/url.hpp @@ -23,7 +23,7 @@ namespace ocl::net class basic_url final { public: - using reference = basic_url&; + using ref_type = basic_url&; enum { @@ -76,7 +76,7 @@ namespace ocl::net basic_url(const basic_url&) = default; private: - reference operator/=(const std::basic_string& in) + ref_type operator/=(const std::basic_string& in) { if (in.empty()) return *this; @@ -91,7 +91,7 @@ namespace ocl::net return *this; } - reference operator/=(const char_type& in) + ref_type operator/=(const char_type& in) { m_ss_ += in; return *this; diff --git a/include/ocl/simd/basic_simd.hpp b/include/ocl/simd/basic_simd.hpp index 7fba26b..d9d405e 100644 --- a/include/ocl/simd/basic_simd.hpp +++ b/include/ocl/simd/basic_simd.hpp @@ -11,18 +11,24 @@ #ifdef __x86_64__ #include -using simd_type = __m256; #endif #ifdef __aarch64__ #include -using simd_type = float32x4_t; #endif namespace ocl::simd { - struct basic_simd final + struct OCL_DEPRECATED_MSG("Unmaintained since v1.0.51") basic_simd final { +#ifdef __x86_64__ + using simd_type = __m256; +#endif + +#ifdef __aarch64__ + using simd_type = float32x4_t; +#endif + struct simd_traits final { simd_type __val; diff --git a/include/ocl/simd/simd.hpp b/include/ocl/simd/simd.hpp index 92bb713..14d6922 100644 --- a/include/ocl/simd/simd.hpp +++ b/include/ocl/simd/simd.hpp @@ -15,7 +15,7 @@ namespace ocl::simd { template - class real_type + class OCL_DEPRECATED_MSG("Unmaintained since v1.0.51") real_type { private: backend_type backend_; -- cgit v1.2.3 From 463a0c01f96d86c9c91f02903bc1d194c5e55b15 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 29 Nov 2025 09:57:50 -0500 Subject: chore&feat: basic URL API. Signed-off-by: Amlal El Mahrouss --- examples/url/CMakeLists.txt | 15 ++++++ examples/url/url.cc | 24 +++++++++ include/ocl/core/config.hpp | 2 + include/ocl/net/url.hpp | 117 ++++++++++++++++++++++++++++++-------------- 4 files changed, 120 insertions(+), 38 deletions(-) create mode 100644 examples/url/CMakeLists.txt create mode 100644 examples/url/url.cc diff --git a/examples/url/CMakeLists.txt b/examples/url/CMakeLists.txt new file mode 100644 index 0000000..7195d6c --- /dev/null +++ b/examples/url/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Url + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(Url fix.cc) + +set_property(TARGET Url PROPERTY CXX_STANDARD 20) +target_include_directories(Url PUBLIC ../../include/ocl) +target_link_libraries(Url PRIVATE Boost::container) diff --git a/examples/url/url.cc b/examples/url/url.cc new file mode 100644 index 0000000..b4cc924 --- /dev/null +++ b/examples/url/url.cc @@ -0,0 +1,24 @@ +/* + fix example + Written by Amlal El Mahrouss. + Licensed under the Boost Software License + */ + +#include +#include +#include +#include +#include + +/* finally test it */ +int main(int argc, char** argv) +{ + ocl::net::url url_type(ocl::net::url::file); + + url_type /= "bin"; + url_type /= "ls"; + + ocl::io::println(url_type.assemble()); + + return EXIT_SUCCESS; +} diff --git a/include/ocl/core/config.hpp b/include/ocl/core/config.hpp index 4fdfc4e..15439d8 100644 --- a/include/ocl/core/config.hpp +++ b/include/ocl/core/config.hpp @@ -27,9 +27,11 @@ #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_EXPORT_DECL #endif diff --git a/include/ocl/net/url.hpp b/include/ocl/net/url.hpp index 361cd66..71c18d6 100644 --- a/include/ocl/net/url.hpp +++ b/include/ocl/net/url.hpp @@ -7,6 +7,8 @@ #pragma once +#include + #include #include @@ -23,51 +25,69 @@ namespace ocl::net class basic_url final { public: - using ref_type = basic_url&; - enum { invalid = 0, - http, + http = 100, https, - mailto, + file, ftp, + mailto = 200, tel, bad = 0xff, }; + private: + auto to_string_() + { + if (m_protocol_ == https) + return "https://"; + + if (m_protocol_ == http) + return "http://"; + + if (m_protocol_ == file) + return "file://"; + + if (m_protocol_ == tel) + return "tel:"; + + if (m_protocol_ == mailto) + return "mailto:"; + + return "invalid:"; + } + + auto to_enum_(const std::basic_string& protocol) + { + if (protocol == "https") + return https; + + if (protocol == "http") + return http; + + if (protocol == "file") + return file; + + if (protocol == "tel") + return tel; + + if (protocol == "mailto") + return mailto; + + return invalid; + } + uint32_t m_protocol_{basic_url::invalid}; std::basic_stringstream m_ss_{}; std::basic_string m_port_{""}; public: - explicit basic_url(const std::basic_string& protocol) + using ref_type = basic_url&; + + explicit basic_url(const uint32_t& protocol) { - if (protocol.starts_with("https://")) - { - m_protocol_ = basic_url::https; - this->operator/=(protocol.substr(std::size("https://"))); - } - else if (protocol.starts_with("http://")) - { - m_protocol_ = basic_url::http; - this->operator/=(protocol.substr(std::size("http://"))); - } - else if (protocol.starts_with("mailto:")) - { - m_protocol_ = basic_url::mailto; - this->operator/=(protocol.substr(std::size("mailto:"))); - } - else if (protocol.starts_with("tel:")) - { - m_protocol_ = basic_url::tel; - this->operator/=(protocol.substr(std::size("tel:"))); - } - else if (protocol.starts_with("ftp:")) - { - m_protocol_ = basic_url::ftp; - this->operator/=(protocol.substr(std::size("ftp:"))); - } + m_protocol_ = protocol; } ~basic_url() = default; @@ -75,7 +95,7 @@ namespace ocl::net basic_url& operator=(const basic_url&) = default; basic_url(const basic_url&) = default; - private: + public: ref_type operator/=(const std::basic_string& in) { if (in.empty()) @@ -83,17 +103,28 @@ namespace ocl::net if (in.starts_with(":")) { + if (m_protocol_ == tel || m_protocol_ == mailto) + return *this; + m_port_ = in.substr(1); - return *this; + } + else if (in.starts_with("+")) + { + if (m_protocol_ != tel) + return *this; + + for (auto& ch : in) + { + if (ch == ' ') + return *this; + } } - m_ss_ += in; - return *this; - } + m_ss_ << in; + + if (!in.ends_with("/")) + m_ss_ << "/"; - ref_type operator/=(const char_type& in) - { - m_ss_ += in; return *this; } @@ -113,6 +144,16 @@ namespace ocl::net return this->m_port_; } + std::basic_string assemble() noexcept + { + std::basic_string out = to_string_(); + out += this->m_ss_.str(); + + out.pop_back(); + + return out; + } + bool is_valid() const noexcept { return m_ss_.size() > 0 && this->m_protocol_ != basic_url::bad || this->m_protocol_ != basic_url::invalid; -- cgit v1.2.3