summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-29 09:58:32 -0500
committerGitHub <noreply@github.com>2025-11-29 09:58:32 -0500
commit83e5efd79e102713aef3178f003402dcd5613e67 (patch)
tree913c82e8c40c1963751dc4d5052d41d72dad6680
parente4aa91788918b5a0acf3c4f4ce2c8d560ad5949c (diff)
parent463a0c01f96d86c9c91f02903bc1d194c5e55b15 (diff)
Merge pull request #26 from amlel-el-mahrouss/develop
Develop
-rw-r--r--examples/url/CMakeLists.txt15
-rw-r--r--examples/url/url.cc24
-rw-r--r--include/ocl/core/config.hpp5
-rw-r--r--include/ocl/net/url.hpp119
-rw-r--r--include/ocl/simd/basic_simd.hpp12
-rw-r--r--include/ocl/simd/simd.hpp2
6 files changed, 134 insertions, 43 deletions
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 <core/error_handler.hpp>
+#include <net/url.hpp>
+#include <unistd.h>
+#include <io/print.hpp>
+#include <sys/socket.h>
+
+/* 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 7e74c81..15439d8 100644
--- a/include/ocl/core/config.hpp
+++ b/include/ocl/core/config.hpp
@@ -23,10 +23,15 @@
#include <sys/types.h>
#include <unistd.h>
+#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_EXPORT_DECL
#endif
diff --git a/include/ocl/net/url.hpp b/include/ocl/net/url.hpp
index 1b5f80c..71c18d6 100644
--- a/include/ocl/net/url.hpp
+++ b/include/ocl/net/url.hpp
@@ -7,6 +7,8 @@
#pragma once
+#include <core/config.hpp>
+
#include <string>
#include <sstream>
@@ -23,51 +25,69 @@ namespace ocl::net
class basic_url final
{
public:
- using reference = 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<char_type>& 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<char_type> m_ss_{};
std::basic_string<char_type> m_port_{""};
public:
- explicit basic_url(const std::basic_string<char_type>& 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,25 +95,36 @@ namespace ocl::net
basic_url& operator=(const basic_url&) = default;
basic_url(const basic_url&) = default;
- private:
- reference operator/=(const std::basic_string<char_type>& in)
+ public:
+ ref_type operator/=(const std::basic_string<char_type>& in)
{
if (in.empty())
return *this;
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_ << "/";
- reference operator/=(const char_type& in)
- {
- m_ss_ += in;
return *this;
}
@@ -113,6 +144,16 @@ namespace ocl::net
return this->m_port_;
}
+ std::basic_string<char_type> assemble() noexcept
+ {
+ std::basic_string<char_type> 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;
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 <immintrin.h>
-using simd_type = __m256;
#endif
#ifdef __aarch64__
#include <arm_neon.h>
-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 <typename backend_type>
- class real_type
+ class OCL_DEPRECATED_MSG("Unmaintained since v1.0.51") real_type
{
private:
backend_type backend_;