diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-09-04 11:25:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-04 11:25:04 +0200 |
| commit | 6789dd7d88a192e3f55b95798cb393e7d12f368a (patch) | |
| tree | 7f04815ad5214f97d0fb2becceceed7ce8089b3d | |
| parent | 443588a42fe9cf48b5f63184b94afe483cb0e761 (diff) | |
| parent | fda7082c54ad46a56ac885d4686b82bad8dbc7c9 (diff) | |
Merge pull request #4 from amlel-el-mahrouss/devv1.0.43
OCL — v1.0.43
44 files changed, 748 insertions, 390 deletions
@@ -42,7 +42,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "SNU Open C++ Library" +PROJECT_NAME = "Open C++ Library" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -54,7 +54,7 @@ PROJECT_NUMBER = dev # for a project that appears at the top of each page and should give viewers a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = SOCL +PROJECT_BRIEF = OCL # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 @@ -74,7 +74,7 @@ PROJECT_ICON = # entered, it will be relative to the location where Doxygen was started. If # left blank the current directory will be used. -OUTPUT_DIRECTORY = /Volumes/Projects/src/snu-lib/docs +OUTPUT_DIRECTORY = ./ocl/docs # If the CREATE_SUBDIRS tag is set to YES then Doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format @@ -991,7 +991,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = /Volumes/Projects/src/snu-lib +INPUT = /Volumes/Projects/src/ocl # This tag can be used to specify the character encoding of the source files # that Doxygen parses. Internally Doxygen uses the UTF-8 encoding. Doxygen uses @@ -1 +1 @@ -@amlel-el-mahrouss - founder@snu.systems - Library Author and Chief Architect +@amlel-el-mahrouss - amlal@nekernel.org - Library Author and Chief Architect @@ -1,4 +1,4 @@ -# SNU Open C++ Library +# Open C++ Library [](LICENSE) @@ -21,12 +21,12 @@ A C++ library with additional modules for your C++ SDLC. int main(int argc, char** argv) { - auto opt = snu::opt(snu::eval_eq(50, 50)).expect("snu::eval_eq, does not match!"); - opt = snu::opt(snu::eval_eq(50, 40)); + auto opt = ocl::opt(ocl::eval_eq(50, 50)).expect("ocl::eval_eq, does not match!"); + opt = ocl::opt(ocl::eval_eq(50, 40)); opt.expect("this time it doesn't."); return EXIT_SUCCESS; } ``` -##### (c) 2025 SNU Systems, Corp. +##### (c) 2025 Amlal El Mahrouss, licensed under the MIT license. diff --git a/compile_flags.txt b/compile_flags.txt index b820259..1c9f6fb 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,4 +1,5 @@ -Idev -std=c++20 -DEMBFS_28BIT_LBA --xc++
\ No newline at end of file +-xc++ +-I/opt/homebrew/Cellar/boost/1.87.0/include
\ No newline at end of file diff --git a/dev/examples/allocator_system/CMakeLists.txt b/dev/examples/allocator_system/CMakeLists.txt new file mode 100644 index 0000000..ee19842 --- /dev/null +++ b/dev/examples/allocator_system/CMakeLists.txt @@ -0,0 +1,16 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Alloc + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(Alloc allocator_system.cc) + +target_link_libraries(Alloc PRIVATE Boost::container) + +set_property(TARGET Alloc PROPERTY CXX_STANDARD 20) +target_include_directories(Alloc PUBLIC ../../) diff --git a/dev/examples/allocator_system/allocator_system.cc b/dev/examples/allocator_system/allocator_system.cc new file mode 100644 index 0000000..c3cd689 --- /dev/null +++ b/dev/examples/allocator_system/allocator_system.cc @@ -0,0 +1,50 @@ +/* + * File: allocator_system.cc + * Purpose: Allocator System container. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss. Licensed under the BSL 1.0 license + */ + +#include <lib/core/allocator_system.hpp> +#include <iostream> + +struct MyClass +{ + int a; + std::string b; + + MyClass() : a(0), b("default") + { + std::cout << "MyClass() constructed\n"; + } + + MyClass(int x, std::string y) : a(x), b(std::move(y)) + { + std::cout << "MyClass(int, string) constructed\n"; + } + + ~MyClass() + { + std::cout << "~MyClass() destroyed\n"; + } +}; + +int main() +{ + using Alloc = ocl::standard_allocator_type<MyClass>; + Alloc allocator; + + // Test 1: claim() + unclaim() + std::cout << "=== Test 1: claim/unclaim ===\n"; + MyClass* raw = allocator.claim(); + std::cout << "raw->a = " << raw->a << ", raw->b = " << raw->b << "\n"; + allocator.unclaim(raw); // Manual delete + + // Test 2: construct() → shared_ptr + std::cout << "\n=== Test 2: construct (shared_ptr) ===\n"; + auto ptr = allocator.construct<int, std::string>(42, "hello"); + std::cout << "ptr->a = " << ptr->a << ", ptr->b = " << ptr->b << "\n"; + + // `shared_ptr` will automatically delete the object + std::cout << "\n=== End of main ===\n"; +} diff --git a/dev/examples/cgi/CMakeLists.txt b/dev/examples/cgi/CMakeLists.txt index 391899f..9c3cbf6 100644 --- a/dev/examples/cgi/CMakeLists.txt +++ b/dev/examples/cgi/CMakeLists.txt @@ -6,7 +6,11 @@ project( VERSION 1.0 LANGUAGES CXX) +find_package(Boost REQUIRED COMPONENTS container) + add_executable(CGI cgi.cc) +target_link_libraries(CGI PRIVATE Boost::container) + set_property(TARGET CGI PROPERTY CXX_STANDARD 20) target_include_directories(CGI PUBLIC ../../) diff --git a/dev/examples/cgi/cgi.cc b/dev/examples/cgi/cgi.cc index 2cb8f3a..692f90c 100644 --- a/dev/examples/cgi/cgi.cc +++ b/dev/examples/cgi/cgi.cc @@ -4,17 +4,14 @@ licensed under the MIT license */ -#include <lib/utility/cgi.hpp> -#include <fstream> -#include <sstream> -#include <string> +#include <lib/utility/cgi_writer.hpp> -const std::string error_html = R"( +static ocl::basic_chunk_string<char> text_sample = R"( <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> - <title>Error | SOCL</title> + <title>Error | OCL</title> <style> body { font-family: monospace; @@ -62,7 +59,7 @@ const std::string error_html = R"( <tr><td colspan="3"><hr></td></tr> </table> - <address>SOCL's Common Gateway Server.</address> + <address>OCL's Common Gateway Server.</address> </body> </html> )"; @@ -71,12 +68,8 @@ const std::string error_html = R"( /* @brief this stub loads a 'index.html' or returns an error message if not found. */ int main(int argc, char** argv) { - snu::cgi::basic_writer<> writer; - - std::stringstream ss_file; - ss_file << error_html; - - writer.html(ss_file); + ocl::cgi::basic_writer<> writer; + writer << text_sample; return 0; } diff --git a/dev/examples/equiv/equiv.cc b/dev/examples/equiv/equiv.cc index 896637d..12207f4 100644 --- a/dev/examples/equiv/equiv.cc +++ b/dev/examples/equiv/equiv.cc @@ -11,9 +11,9 @@ int main(int argc, char** argv) { std::cout << std::boolalpha; - std::cout << snu::equiv::is_same<bool, int>::value << std::endl; - std::cout << snu::equiv::is_same<bool, bool>::value << std::endl; - std::cout << snu::equiv::is_same<int, int>::value << std::endl; + std::cout << ocl::equiv::is_same<bool, int>::value << std::endl; + std::cout << ocl::equiv::is_same<bool, bool>::value << std::endl; + std::cout << ocl::equiv::is_same<int, int>::value << std::endl; return 0; } diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc index ce48186..e3d669b 100644 --- a/dev/examples/fix/fix.cc +++ b/dev/examples/fix/fix.cc @@ -4,7 +4,7 @@ licensed under the MIT license */ -#include <lib/net/network.hpp> +#include <lib/net/modem.hpp> #include <lib/fix/parser.hpp> #include <iostream> #include <unistd.h> @@ -15,14 +15,14 @@ int main(int argc, char** argv) { constexpr auto default_fix = "8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"; - snu::fix::basic_visitor<char> basic_visitor; - snu::fix::basic_range_data<char> fix = basic_visitor.visit(default_fix); + ocl::fix::basic_visitor<char> basic_visitor; + ocl::fix::basic_range_data<char> fix = basic_visitor.visit(default_fix); std::cout << "magic=" << fix.magic_ << std::endl; std::cout << "magic_len=" << fix.magic_len_ << std::endl; std::cout << "is_valid=" << std::boolalpha << fix.is_valid() << std::endl; - snu::fix::must_pass(fix); + ocl::fix::must_pass(fix); for (auto fields : fix.body_) { diff --git a/dev/examples/opt/opt.cc b/dev/examples/opt/opt.cc index c1c2745..b34f2c7 100644 --- a/dev/examples/opt/opt.cc +++ b/dev/examples/opt/opt.cc @@ -26,7 +26,7 @@ static auto do_some(const std::string recv_data, const std::string check_data) const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */ const int opt_hash = do_hash(recv_data); /* we assume that the hash is correct */ - auto opt = snu::opt(snu::eval_eq(hash_to_check, opt_hash)); /* do the compute */ + auto opt = ocl::opt(ocl::eval_eq(hash_to_check, opt_hash)); /* do the compute */ return opt; } @@ -35,7 +35,7 @@ int main(int argc, char** argv) { // ... let's assume we fetch data from network... - snu::io::println("Testing data..."); + ocl::io::println("Testing data..."); auto opt = do_some("Ohio", "Ohio"); opt.expect("Checksum failed, Ohio isn't Ohio!"); diff --git a/dev/examples/tracked_ptr/tracked_ptr.cc b/dev/examples/tracked_ptr/tracked_ptr.cc index 61073a6..6e3f4a2 100644 --- a/dev/examples/tracked_ptr/tracked_ptr.cc +++ b/dev/examples/tracked_ptr/tracked_ptr.cc @@ -5,17 +5,17 @@ */ #include <lib/memory/tracked_ptr.hpp> -#include <iostream> +#include <lib/io/print.hpp> -void summon_tracked_ptr() +static void summon_tracked_ptr() { - snu::memory::tracked_ptr<int> ptr = snu::memory::make_tracked(42); + ocl::memory::tracked_ptr<int> ptr = ocl::memory::make_tracked<int>(42); std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; } -void summon_leak_tracked_ptr() +static void summon_leak_tracked_ptr() { - snu::memory::tracked_ptr<int>* ptr = new snu::memory::tracked_ptr<int>(42); + ocl::memory::tracked_ptr<int>* ptr = new ocl::memory::tracked_ptr<int>(42); std::cout << ptr->data() << "=" << ptr->manager().allocator().allocated_count_ << std::endl; } @@ -27,12 +27,11 @@ int main(int argc, char** argv) summon_tracked_ptr(); summon_tracked_ptr(); - snu::memory::tracked_ptr<int> ptr; + ocl::memory::tracked_ptr<int> ptr; std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; - std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; summon_leak_tracked_ptr(); @@ -47,7 +46,7 @@ int main(int argc, char** argv) std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; - snu::memory::must_pass(ptr); + ocl::memory::must_pass(ptr); return EXIT_SUCCESS; } diff --git a/dev/lib/core/allocator_system.hpp b/dev/lib/core/allocator_system.hpp new file mode 100644 index 0000000..1243ed5 --- /dev/null +++ b/dev/lib/core/allocator_system.hpp @@ -0,0 +1,75 @@ +/* + * File: core/allocator_system.hpp + * Purpose: Allocator System container. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss. Licensed under the BSL 1.0 license + */ + +#ifndef _OCL_ALLOCATOR_SYSTEM_HPP +#define _OCL_ALLOCATOR_SYSTEM_HPP + +#include <lib/core/includes.hpp> +#include <stdexcept> +#include <memory> + +namespace ocl +{ + template <typename type> + struct new_op final + { + inline auto operator()() -> type* + { + return new type; + } + + template <typename... var_type> + inline auto var_alloc(var_type... args) -> type* + { + return new type{args...}; + } + }; + + template <typename type> + struct delete_op final + { + inline auto operator()(type* t) -> void + { + delete t; + } + }; + + template <typename ret_type, typename allocator_new, typename allocator_delete> + class allocator_system + { + allocator_new alloc_; + allocator_delete del_; + + public: + allocator_system() = default; + ~allocator_system() = default; + + allocator_system& operator=(const allocator_system&) = delete; + allocator_system(const allocator_system&) = delete; + + ret_type* claim() noexcept + { + return alloc_(); + } + + template <typename... var_type> + auto construct(var_type... args) -> std::shared_ptr<ret_type> + { + return std::shared_ptr<ret_type>(alloc_.template var_alloc<var_type...>(args...), allocator_delete{}); + } + + void unclaim(ret_type* ptr) + { + del_(ptr); + } + }; + + template <typename type> + using standard_allocator_type = allocator_system<type, new_op<type>, delete_op<type>>; +} // namespace ocl + +#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP diff --git a/dev/lib/core/error_handler.hpp b/dev/lib/core/error_handler.hpp new file mode 100644 index 0000000..593e54a --- /dev/null +++ b/dev/lib/core/error_handler.hpp @@ -0,0 +1,35 @@ +/* +* File: core/basic_error_handler.hpp +* Purpose: Error handler container. +* Author: Amlal El Mahrouss (amlal@nekernel.org) +* Copyright 2025, Amlal El Mahrouss. +*/ + +#ifndef _OCL_ERROR_HANDLER_HPP +#define _OCL_ERROR_HANDLER_HPP + +#include <lib/core/includes.hpp> +#include <stdexcept> + +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&) = delete; + basic_error_handler(const basic_error_handler&) = delete; + + virtual void operator()(const std::basic_string<char>& msg) + { + ((void)msg); + } + }; + + using standard_error_handler = basic_error_handler; +} // namespace ocl + +#endif // ifndef _OCL_ERROR_HANDLER_HPP diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp index e482a7c..f988fc1 100644 --- a/dev/lib/core/includes.hpp +++ b/dev/lib/core/includes.hpp @@ -1,8 +1,8 @@ /* * File: core/includes.hpp - * Purpose: Core includes for the SOCL library. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Purpose: Core includes for the OCL library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once @@ -11,6 +11,4 @@ #include <boost/core/nvp.hpp> #include <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> -#include <memory> -#include <utility> -#include <filesystem> +#include <boost/container/allocator.hpp> diff --git a/dev/lib/except/error.hpp b/dev/lib/except/error.hpp index 486d2e6..16bf5eb 100644 --- a/dev/lib/except/error.hpp +++ b/dev/lib/except/error.hpp @@ -1,20 +1,20 @@ /* * File: opt.hpp * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp. + * Copyright 2023-2025, Amlal El Mahrouss */ -#ifndef _SNU_ERR_HPP -#define _SNU_ERR_HPP +#ifndef _OCL_ERR_HPP +#define _OCL_ERR_HPP #include <stdexcept> -namespace snu::except +namespace ocl { using runtime_error = std::runtime_error; using fix_error = runtime_error; using math_error = runtime_error; using cgi_error = runtime_error; -} // namespace snu::except +} // namespace ocl -#endif // _SNU_ERR_HPP
\ No newline at end of file +#endif // _OCL_ERR_HPP
\ No newline at end of file diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 8181359..723506e 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -1,12 +1,12 @@ /* * File: fix/parser.hpp * Purpose: Financial Information Exchange parser in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ -#ifndef _SNU_FIX_PARSER_HPP -#define _SNU_FIX_PARSER_HPP +#ifndef _OCL_FIX_PARSER_HPP +#define _OCL_FIX_PARSER_HPP #include <cstddef> #include <cassert> @@ -18,7 +18,7 @@ #include <unistd.h> #include <signal.h> -namespace snu::fix +namespace ocl::fix { template <typename char_type> class basic_visitor; @@ -60,8 +60,8 @@ namespace snu::fix template <typename char_type = char> struct basic_range final { - char_type* bytes_; - size_t length_; + char_type* bytes_{nullptr}; + size_t length_{}; bool is_valid() noexcept { @@ -77,7 +77,7 @@ namespace snu::fix /// @brief Convert basic_range to usable string. /// @note This function assumes that the basic_range is valid and contains ASCII bytes. template <typename char_type = char> - std::basic_string<char_type> to_string(basic_range<char_type>& basic_range) noexcept + inline std::basic_string<char_type> to_string(basic_range<char_type>& basic_range) noexcept { if (basic_range.length_ < 0) return std::basic_string<char_type>{}; @@ -201,14 +201,16 @@ namespace snu::fix } }; - template <typename char_type = char> - inline void must_pass(basic_range_data<char_type>& basic_range) + template <typename char_type = char, typename error_handler> + inline void must_pass(basic_range_data<char_type>& basic_range, error_handler& handler) { if (!basic_range.is_valid()) { - ::kill(::getpid(), SIGTRAP); + handler("Invalid FIX packet"); } } -} // namespace snu::fix -#endif // ifndef _SNU_FIX_PARSER_HPP + using fix_tag_type = std::uint32_t; +} // namespace ocl::fix + +#endif // ifndef _OCL_FIX_PARSER_HPP diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp index eb425c1..4b32ddb 100644 --- a/dev/lib/io/print.hpp +++ b/dev/lib/io/print.hpp @@ -1,18 +1,17 @@ /* * File: print.hpp - * Purpose: SNU Print library - * Author: Amlal El Mahrouss. (founder@snu.systems) - * Copyright 2025, SNU Systems Corp. + * Purpose: OCL Print library + * Author: Amlal El Mahrouss. (amlal@nekernel.org) + * Copyright 2025 */ -#ifndef _SNU_PRINT_HPP -#define _SNU_PRINT_HPP +#ifndef _OCL_PRINT_HPP +#define _OCL_PRINT_HPP -#include <initializer_list> #include <iostream> #include <ostream> -namespace snu::io +namespace ocl::io { template <typename T, typename... Args> inline void print(T fmt, Args... other) noexcept @@ -37,6 +36,6 @@ namespace snu::io { print(fmt...); } -} // namespace snu::io +} // namespace ocl::io -#endif // ifndef _SNU_PRINT_HPP +#endif // ifndef _OCL_PRINT_HPP diff --git a/dev/lib/logic/equiv.hpp b/dev/lib/logic/equiv.hpp index 2f63673..5b022f8 100644 --- a/dev/lib/logic/equiv.hpp +++ b/dev/lib/logic/equiv.hpp @@ -1,13 +1,14 @@ /* * File: equiv.hpp * Purpose: Equivalence runtime c++ header. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once -namespace snu::equiv +/// @brief OCL equivalence namespace. +namespace ocl::equiv { template <typename T> struct basic_hash_trait @@ -59,7 +60,7 @@ namespace snu::equiv struct equiv_is_int8 { private: - T left_ = 255, right_ = 255; + T left_ = 127, right_ = 127; public: using result = T; @@ -74,7 +75,8 @@ namespace snu::equiv struct equiv_not_int8 { private: - T left_ = 255, right_ = 255; + // these shall overflow if not int8. + T left_ = 127, right_ = 127; public: using result = T; @@ -96,7 +98,7 @@ namespace snu::equiv constexpr result hash() { - return left_ / right_; + return left_ / right_ == 1; } }; -} // namespace snu::equiv
\ No newline at end of file +} // namespace ocl::equiv diff --git a/dev/lib/logic/math.hpp b/dev/lib/logic/math.hpp index cab995a..e796eae 100644 --- a/dev/lib/logic/math.hpp +++ b/dev/lib/logic/math.hpp @@ -1,7 +1,7 @@ /* * File: math.hpp * Purpose: Mathematics c++ header. - * Author: Amlal El Mahrouss (founder@snu.systems) + * Author: Amlal El Mahrouss (amlal@nekernel.org) * Copyright 2025, Amlal El Mahrouss. */ @@ -9,7 +9,7 @@ #include <cmath> -namespace snu::math +namespace ocl { template <std::size_t T> struct is_non_boolean_integer final @@ -32,4 +32,4 @@ namespace snu::math constexpr inline auto not_a_number = NAN; constexpr inline auto positive_infinity = INFINITY; constexpr inline auto negative_infinity = -positive_infinity; -} // namespace snu::math
\ No newline at end of file +} // namespace ocl
\ No newline at end of file diff --git a/dev/lib/logic/opt.hpp b/dev/lib/logic/opt.hpp index a8e66b4..442756c 100644 --- a/dev/lib/logic/opt.hpp +++ b/dev/lib/logic/opt.hpp @@ -1,16 +1,16 @@ /* * File: opt.hpp * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp. + * Copyright 2023-2025, Amlal El Mahrouss */ -#ifndef _SNU_OPT_HPP -#define _SNU_OPT_HPP +#ifndef _OCL_OPT_HPP +#define _OCL_OPT_HPP #include <lib/except/error.hpp> #include <utility> -namespace snu +namespace ocl { enum class return_type { @@ -116,6 +116,6 @@ namespace snu { return return_type::err; } -} // namespace snu +} // namespace ocl -#endif /* ifndef _SNU_OPT_HPP */ +#endif /* ifndef _OCL_OPT_HPP */ diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp index c767b67..d2f8450 100644 --- a/dev/lib/memory/tracked_ptr.hpp +++ b/dev/lib/memory/tracked_ptr.hpp @@ -1,22 +1,22 @@ /* * File: memory/tracked_ptr.hpp * Purpose: Custom smart pointer implementation in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once #include <cstddef> #include <utility> -#include <memory> +#include <new> #include <atomic> #include <sys/types.h> #include <unistd.h> #include <signal.h> -namespace snu::memory +namespace ocl::memory { template <typename T> class tracked_allocator; @@ -45,19 +45,24 @@ namespace snu::memory template <typename... U> void retain(T*& ptr, U&&... args) { - ptr = new T(args...); + ptr = new T(std::forward<U>(args)...); if (ptr) { ++allocated_count_; + return; } - else - { - throw std::bad_alloc(); - } + + throw std::bad_alloc(); + } + + template <typename... U> + void must_retain(T*& ptr, U&&... args) noexcept + { + this->retain(ptr, args...); } - void dispose(T*& ptr) + void dispose(T*& ptr) noexcept { if (ptr) { @@ -96,10 +101,17 @@ namespace snu::memory { T* ptr = nullptr; allocator_.retain(ptr, std::forward<U>(args)...); + return ptr; } - void dispose(T*& ptr) + template <typename... U> + T* must_retain(U&&... args) noexcept + { + return this->retain(std::forward<U>(args)...); + } + + void dispose(T*& ptr) noexcept { allocator_.dispose(ptr); } @@ -128,7 +140,7 @@ namespace snu::memory this->reset(); } - tracked_ptr(const tracked_ptr&) = delete; + tracked_ptr(const tracked_ptr&) = delete; tracked_ptr& operator=(const tracked_ptr&) = delete; public: @@ -190,13 +202,13 @@ namespace snu::memory } private: - T* ptr_ = nullptr; + T* ptr_{nullptr}; }; template <typename T> - inline auto make_tracked(T arg) -> tracked_ptr<T> + inline auto make_tracked() -> tracked_ptr<T> { - return tracked_ptr<T>(std::forward<T>(arg)); + return tracked_ptr<T>(); } template <typename U, typename... T> @@ -220,4 +232,4 @@ namespace snu::memory ::kill(::getpid(), SIGTRAP); } } -} // namespace snu::memory
\ No newline at end of file +} // namespace ocl::memory diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp new file mode 100644 index 0000000..074f182 --- /dev/null +++ b/dev/lib/net/modem.hpp @@ -0,0 +1,156 @@ +/* + * File: net/modem.hpp + * Purpose: Modem concept in modern C++ + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss + */ + +#ifndef _OCL_NET_NETWORK_HPP +#define _OCL_NET_NETWORK_HPP + +#include <unistd.h> +#include <arpa/inet.h> +#include <sys/socket.h> +#include <string> +#include <utility> +#include <cstddef> + +#define OCL_MODEM_INTERFACE : public ocl::net::basic_modem + +namespace ocl::net +{ + class basic_modem; + + typedef int64_t socket_type; + + /// @brief Modem container concept, a container to read and write on a network stream. + class basic_modem + { + private: + socket_type fd_{}; + bool server_fd_{false}; + bool bad_{true}; + + public: + const bool& bad{bad_}; + + explicit basic_modem() = default; + + virtual ~basic_modem() + { + this->destroy(); + } + + basic_modem& operator=(const basic_modem&) = delete; + basic_modem(const basic_modem&) = delete; + + static constexpr auto local_address_ip4 = "127.0.0.1"; + static constexpr auto local_address_ip6 = "::1"; + static constexpr const auto backlog_count = 5U; + + bool is_valid() const noexcept + { + return this->fd_ != -1 && !this->bad_; + } + + template <typename ptr_type> + bool receive(ptr_type& out, std::size_t len) noexcept + { + static_assert(std::is_pointer<ptr_type>::value, "ptr_type is not a pointer!"); + + if (!out) + return false; + + if (!len) + return false; + + socket_type cl_{fd_}; + + if (this->server_fd_) + cl_ = ::accept(fd_, nullptr, nullptr); + + auto ret = ::recv(cl_, out, len, 0); + + return ret > 0L; + } + + template <typename ptr_type> + bool transmit(ptr_type& out, std::size_t len) noexcept + { + static_assert(std::is_pointer<ptr_type>::value, "ptr_type is not a pointer!"); + + if (!out) + return false; + + if (!len) + return false; + + auto ret = ::send(fd_, out, len, 0); + + bad_ = !(ret >= 0L); + + return ret >= 0L; + } + + template <typename char_type> + bool transmit(const std::basic_string<char_type>& out) noexcept + { + if (out.empty()) + return false; + + auto ret = ::send(fd_, out.data(), out.size(), 0); + + bad_ = !(ret >= 0L); + + return ret >= 0L; + } + + template <int32_t af, int32_t kind, int32_t port> + bool construct(const char* addr = basic_modem::local_address_ip4, const bool& is_server = false) noexcept + { + static_assert(af != 0, "Address family is zero"); + static_assert(kind != 0, "Kind is zero"); + + fd_ = ::socket(af, kind, 0); + server_fd_ = is_server; + + if (fd_ == -1) + return false; + + struct sockaddr_in addr_; + std::memset(&addr_, 0, sizeof(struct sockaddr_in)); + + addr_.sin_addr.s_addr = ::inet_addr(addr); + addr_.sin_port = htons(port); + addr_.sin_family = af; + + if (!is_server) + { + const auto ret = ::connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(addr_)); + return ret == 0L; + } + + ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); + ::listen(fd_, basic_modem::backlog_count); + + bad_ = false; + + return true; + } + + bool destroy() noexcept + { + if (!fd_) + return false; + + ::shutdown(fd_, SHUT_RDWR); + ::close(fd_); + + fd_ = 0L; + + return true; + } + }; +} // namespace ocl::net + +#endif // ifndef _OCL_NET_NETWORK_HPP diff --git a/dev/lib/net/network.hpp b/dev/lib/net/network.hpp deleted file mode 100644 index 67f3740..0000000 --- a/dev/lib/net/network.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * File: net/network.hpp - * Purpose: Modem concept in modern C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. - */ - -#ifndef _SNU_NET_NETWORK_HPP -#define _SNU_NET_NETWORK_HPP - -#include <unistd.h> -#include <arpa/inet.h> -#include <sys/socket.h> -#include <string> -#include <utility> -#include <cstddef> - -#define SNU_MODEM_INTERFACE : protected snu::net::basic_modem - -namespace snu::net -{ - template <typename char_type> - class basic_modem; - - typedef int64_t socket_type; - - /// @brief Delivery modem concept, a container to read and write on a network stream. - template <typename char_type> - class basic_modem - { - public: - explicit basic_modem() = default; - virtual ~basic_modem() = default; - - basic_modem& operator=(const basic_modem&) = default; - basic_modem(const basic_modem&) = default; - - static constexpr auto local_address_ip6 = "127.0.0.1"; - static constexpr auto local_address_ip4 = "::1"; - - static constexpr auto backlog_count = 18U; - - socket_type fd_{}; - - bool is_valid() const noexcept - { - return this->fd_ != -1; - } - - template <typename ptr_type> - bool receive(ptr_type& out, std::size_t len) noexcept - { - static_assert(std::is_pointer<ptr_type>::value, "ptr_type is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - auto ret = ::recv(fd_, out, len, 0); - - return ret > 0; - } - - template <typename ptr_type> - bool transmit(ptr_type& out, std::size_t len) noexcept - { - static_assert(std::is_pointer<ptr_type>::value, "char_type is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - auto ret = ::send(fd_, out, len, 0); - - return ret > 0; - } - - template <typename ptr_type> - bool transmit(std::basic_string<ptr_type> out) noexcept - { - if (out.empty()) - return false; - - auto ret = ::send(fd_, out.data(), out.size(), 0); - - return ret > 0; - } - - template <int32_t af, int32_t kind, int32_t ip_proto, int32_t port> - bool construct(const char* addr = basic_modem::local_address_ip4, const bool& is_server = false) noexcept - { - static_assert(af != 0, "Address family is zero"); - static_assert(kind != 0, "Type is zero"); - - fd_ = ::socket(af, kind, ip_proto); - - if (fd_ == -1) - return false; - - struct sockaddr_in addr_ - { - }; - - addr_.sin_addr.s_addr = ::inet_addr(addr); - addr_.sin_port = port; - - if (!is_server) - { - const auto ret = ::connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(decltype(addr_))); - return ret == 0; - } - - ::listen(fd_, basic_modem::backlog_count); - - return true; - } - - bool destroy() noexcept - { - if (!fd_) - return false; - - ::shutdown(fd_, SHUT_RDWR); - ::close(fd_); - - fd_ = 0U; - - return true; - } - }; -} // namespace snu::net - -#endif // ifndef _SNU_NET_NETWORK_HPP diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index f6dba95..ff6aebe 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -1,8 +1,8 @@ /* * File: net/url.hpp * Purpose: URL container in modern C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once @@ -11,9 +11,9 @@ #include <iostream> #include <sstream> -/// @author Amlal El Mahrouss (founder@snu.systems) +/// @author Amlal El Mahrouss (amlal@nekernel.org) -namespace snu::net +namespace ocl::net { template <typename char_type> class basic_url; @@ -61,4 +61,4 @@ namespace snu::net return ss_.size() > 0; } }; -} // namespace snu::net +} // namespace ocl::net diff --git a/dev/lib/tests/gtest.hpp b/dev/lib/tests/gtest.hpp index 14474c0..deb2ddf 100644 --- a/dev/lib/tests/gtest.hpp +++ b/dev/lib/tests/gtest.hpp @@ -1,8 +1,8 @@ /* * File: tests/gtest.hpp - * Purpose: Google Test wrapper for the SOCL library. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Purpose: Google Test wrapper for the OCL library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #include <gtest/gtest.h> diff --git a/dev/lib/tests/hpptest.hpp b/dev/lib/tests/hpptest.hpp index 4c99ce6..f520339 100644 --- a/dev/lib/tests/hpptest.hpp +++ b/dev/lib/tests/hpptest.hpp @@ -1,22 +1,21 @@ /* * File: tests/hpptest.hpp - * Purpose: HPP Test wrapper for the SOCL library. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Purpose: HPP Test wrapper for the OCL library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once - -#ifdef SOCL_HPPTEST -namespace snu::hpptest +#ifdef OCL_HPPTEST +namespace ocl::hpptest { typedef bool condition_type; template <condition_type expr = true> consteval inline void must_pass() { - SOCL_HPPTEST_ASSERT(expr); + OCL_HPPTEST_ASSERT(expr); } -} // namespace snu::hpptest +} // namespace ocl::hpptest #endif diff --git a/dev/lib/utility/cgi.hpp b/dev/lib/utility/cgi.hpp deleted file mode 100644 index 57625b8..0000000 --- a/dev/lib/utility/cgi.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * File: cgi.hpp - * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss. - */ - -#ifndef _SNU_CGI_HPP -#define _SNU_CGI_HPP - -#include <cstdio> -#include <string> -#include <sstream> - -namespace snu -{ - namespace cgi - { - /// @brief CGI Writer class, writes to stdout; as CGI expects. - template <typename char_type = char> - class basic_writer - { - private: - basic_writer& eval_(const std::basic_string<char>& mime, const std::basic_stringstream<char_type>& ss) noexcept - { - std::printf("Content-Type: %s\r\n", mime.c_str()); - std::printf("Server: %s\r\n", "socl-cgi-system"); - std::printf("Content-Length: %ld\r\n\r\n", ss.str().size()); - std::printf("%s", ss.str().c_str()); - - return *this; - } - - public: - explicit basic_writer() = default; - ~basic_writer() = default; - - basic_writer& operator=(const basic_writer&) = default; - basic_writer(const basic_writer&) = default; - - public: - basic_writer& binary(const std::basic_stringstream<char_type>& ss_in) - { - return this->eval_("application/octet-stream", ss_in); - } - - basic_writer& html(const std::basic_stringstream<char_type>& ss_in) - { - return this->eval_("text/html", ss_in); - } - - basic_writer& xml(const std::basic_stringstream<char_type>& ss_in) - { - return this->eval_("application/xml", ss_in); - } - - basic_writer& json(const std::basic_stringstream<char_type>& ss_in) - { - return this->eval_("application/json", ss_in); - } - - basic_writer& js(const std::basic_stringstream<char_type>& ss_in) - { - return this->eval_("text/javascript", ss_in); - } - }; - } // namespace cgi -} // namespace snu - -#endif // ifndef _SNU_CGI_HPP
\ No newline at end of file diff --git a/dev/lib/utility/cgi_writer.hpp b/dev/lib/utility/cgi_writer.hpp new file mode 100644 index 0000000..126b299 --- /dev/null +++ b/dev/lib/utility/cgi_writer.hpp @@ -0,0 +1,79 @@ +/* + * File: cgi_writer.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss. + */ + +#ifndef _OCL_CGI_WRITER_HPP +#define _OCL_CGI_WRITER_HPP + +#include <lib/io/print.hpp> +#include <lib/utility/chunk_string.hpp> +#include <sstream> +#include <format> + +namespace ocl +{ + namespace cgi + { + /// @brief CGI Writer class, writes to stdout; as CGI expects. + template <typename char_type = char> + class basic_writer + { + private: + basic_writer& eval_(const ocl::basic_chunk_string<char_type>& mime, const ocl::basic_chunk_string<char_type>& ss) noexcept + { + std::basic_stringstream<char_type> ss_out; + + ss_out << std::format("Content-Type: {}\r\n", mime.str()); + ss_out << std::format("Server: {}\r\n", "OCL-CGI/1.0"); + ss_out << std::format("Content-Length: {}\r\n\r\n", ss.str().size()); + ss_out << ss.str(); + + ocl::io::print(ss_out.str()); + + return *this; + } + + public: + explicit basic_writer() = default; + ~basic_writer() = default; + + basic_writer& operator=(const basic_writer&) = default; + basic_writer(const basic_writer&) = default; + + public: + friend void operator<<(basic_writer& self, const ocl::basic_chunk_string<char_type>& ss_in) + { + self = self.eval_("text/plain", ss_in); + } + + basic_writer& binary(const ocl::basic_chunk_string<char_type>& ss_in) + { + return this->eval_("application/octet-stream", ss_in); + } + + basic_writer& html(const ocl::basic_chunk_string<char_type>& ss_in) + { + return this->eval_("text/html", ss_in); + } + + basic_writer& xml(const ocl::basic_chunk_string<char_type>& ss_in) + { + return this->eval_("application/xml", ss_in); + } + + basic_writer& json(const ocl::basic_chunk_string<char_type>& ss_in) + { + return this->eval_("application/json", ss_in); + } + + basic_writer& js(const ocl::basic_chunk_string<char_type>& ss_in) + { + return this->eval_("text/javascript", ss_in); + } + }; + } // namespace cgi +} // namespace ocl + +#endif // ifndef _OCL_CGI_WRITER_HPP diff --git a/dev/lib/utility/chunk_string.hpp b/dev/lib/utility/chunk_string.hpp new file mode 100644 index 0000000..4fe5cc2 --- /dev/null +++ b/dev/lib/utility/chunk_string.hpp @@ -0,0 +1,102 @@ +/* +* 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 + */ + +#ifndef OCL_UTILITY_CHUNK_STRING_HPP +#define OCL_UTILITY_CHUNK_STRING_HPP + +#include <lib/core/includes.hpp> + +namespace ocl +{ + template <typename char_type, std::size_t max_chunk_size = 8196> + class basic_chunk_string; + + template <typename char_type, std::size_t max_chunk_size> + class basic_chunk_string final + { + private: + char_type packed_chunks_[max_chunk_size] = {0}; + std::size_t chunk_total_{}; + + bool bad_{false}; + + public: + const bool& bad{bad_}; + + basic_chunk_string() = default; + + basic_chunk_string(const char_type* in) + { + this->operator+=(in); + } + + basic_chunk_string(const std::basic_string<char_type>& in) + { + this->operator+=(in); + } + + ~basic_chunk_string() = default; + + basic_chunk_string& operator=(const basic_chunk_string&) = delete; + basic_chunk_string(const basic_chunk_string&) = delete; + + public: + basic_chunk_string& operator+=(const std::basic_string<char_type>& in) + { + if (in.empty() || bad_) + return *this; + + if (in.size() > max_chunk_size) + { + bad_ = true; + return *this; + } + + if (chunk_total_ > max_chunk_size) + { + bad_ = true; + return *this; + } + + const auto& sz = in.size(); + const static auto size_max_chunk = max_chunk_size; + const auto& ptr = in.data(); + + if (chunk_total_ < size_max_chunk) + { + std::memcpy(packed_chunks_ + chunk_total_, ptr, sz); + chunk_total_ += sz; + } + + return *this; + } + + std::basic_string<char_type> str() const noexcept + { + static std::basic_string<char_type> ret; + + if (ret.size() > 0) + ret.clear(); + + ret += packed_chunks_; + + return ret; + } + + void print() noexcept + { + ocl::io::print(packed_chunks_); + } + }; + + template <typename char_type> + inline void print(basic_chunk_string<char_type>& fmt) noexcept + { + fmt.print(); + } +} // namespace ocl +#endif // ifndef OCL_UTILITY_CHUNK_STRING_HPP diff --git a/dev/lib/utility/crc32.hpp b/dev/lib/utility/crc32.hpp index f7e5fc9..ea09b94 100644 --- a/dev/lib/utility/crc32.hpp +++ b/dev/lib/utility/crc32.hpp @@ -5,17 +5,17 @@ * Copyright 2025, Amlal El Mahrouss. */ -#ifndef _SNU_CRC32_HPP -#define _SNU_CRC32_HPP +#ifndef _OCL_CRC32_HPP +#define _OCL_CRC32_HPP #include <cstdint> #include <string> #include <cstddef> /// @brief Crc32 implementation in C++ -/// @author Amlal EL Mahrouss (founder@snu.systems) +/// @author Amlal EL Mahrouss (amlal@nekernel.org) -namespace snu::crc32 +namespace ocl::crc32 { namespace detail { @@ -76,6 +76,6 @@ namespace snu::crc32 { return detail::crc32(in.c_str(), in.size()); } -} // namespace snu::crc32 +} // namespace ocl::crc32 -#endif // !_SNU_CRC32_HPP
\ No newline at end of file +#endif // !_OCL_CRC32_HPP
\ No newline at end of file diff --git a/dev/lib/utility/embfs.hpp b/dev/lib/utility/embfs.hpp index 3acc867..0f20596 100644 --- a/dev/lib/utility/embfs.hpp +++ b/dev/lib/utility/embfs.hpp @@ -1,20 +1,20 @@ /* * File: embfs.hpp * Purpose: Embedded File System. - * Author: Amlal El Mahrouss (founder@snu.systems) + * Author: Amlal El Mahrouss (amlal@nekernel.org) * Copyright 2025, Amlal El Mahrouss. */ -#ifndef _SNU_EMBFS_HPP -#define _SNU_EMBFS_HPP +#ifndef _OCL_EMBFS_HPP +#define _OCL_EMBFS_HPP #include <cstdint> #include <cstddef> /// @brief A filesystem designed for tiny storage medias. -/// @author Amlal EL Mahrouss (founder@snu.systems) +/// @author Amlal EL Mahrouss (amlal@nekernel.org) -namespace snu::embfs +namespace ocl::embfs { namespace traits { @@ -75,6 +75,6 @@ namespace snu::embfs /// @brief Indexed node linear array. typedef embfs_inode embfs_inode_arr_t[_inode_arr_len]; } // namespace traits -} // namespace snu::embfs +} // namespace ocl::embfs -#endif // ifndef _SNU_EMBFS_HPP
\ No newline at end of file +#endif // ifndef _OCL_EMBFS_HPP
\ No newline at end of file diff --git a/dev/tests/chunk_string/CMakeLists.txt b/dev/tests/chunk_string/CMakeLists.txt new file mode 100644 index 0000000..5a4a27c --- /dev/null +++ b/dev/tests/chunk_string/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.27) +project(BasicChunkUsage LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(BasicChunkUsage chunk_test.cc) +target_link_libraries(BasicChunkUsage PRIVATE gtest_main Boost::container) + +set_property(TARGET BasicChunkUsage PROPERTY CXX_STANDARD 20) +target_include_directories(BasicChunkUsage PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(BasicChunkUsage) diff --git a/dev/tests/chunk_string/chunk_test.cc b/dev/tests/chunk_string/chunk_test.cc new file mode 100644 index 0000000..ad3d31b --- /dev/null +++ b/dev/tests/chunk_string/chunk_test.cc @@ -0,0 +1,30 @@ +/* + * File: tests/chunk_test.cc + * Purpose: Chunk unit tests in C++ + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss + */ + +#include <lib/io/print.hpp> +#include <lib/tests/gtest.hpp> +#include <lib/utility/chunk_string.hpp> + +TEST(ChunkTest, BasicChunkUsage) +{ + const std::string test_string = "HELLO, WORLD!"; + const unsigned iterations = 1024000; + + auto start = std::chrono::high_resolution_clock::now(); + + ocl::basic_chunk_string<char, 1000000> optimized; + + for (unsigned i = 0; i < iterations; ++i) + { + optimized += test_string; + } + + auto end = std::chrono::high_resolution_clock::now(); + auto optimized_time = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); + + EXPECT_TRUE(optimized_time.count() < 30U); +} diff --git a/dev/tests/fix_basic/CMakeLists.txt b/dev/tests/fix_basic/CMakeLists.txt index f792277..7b06112 100644 --- a/dev/tests/fix_basic/CMakeLists.txt +++ b/dev/tests/fix_basic/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(SOCLTests) +project(FIXTestBasic) include(FetchContent) FetchContent_Declare( diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc index bd04d07..bdde392 100644 --- a/dev/tests/fix_basic/fix_test.cc +++ b/dev/tests/fix_basic/fix_test.cc @@ -1,8 +1,8 @@ /* * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #include <lib/fix/parser.hpp> @@ -10,9 +10,9 @@ TEST(FIXTest, BasicFIXUsage) { - snu::fix::basic_visitor<char> basic_visitor; - snu::fix::basic_range_data<char> fix = basic_visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + ocl::fix::basic_visitor<char> basic_visitor; + ocl::fix::basic_range_data<char> fix = basic_visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); - EXPECT_EQ(fix.magic_, snu::fix::detail::begin_fix()); + EXPECT_EQ(fix.magic_, ocl::fix::detail::begin_fix()); EXPECT_TRUE(fix.is_valid()); }
\ No newline at end of file diff --git a/dev/tests/network_basic/CMakeLists.txt b/dev/tests/network_basic/CMakeLists.txt index a5704fc..4cfe0d1 100644 --- a/dev/tests/network_basic/CMakeLists.txt +++ b/dev/tests/network_basic/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.28) -project(SOCLTests LANGUAGES CXX) +cmake_minimum_required(VERSION 3.27) +project(NetworkTestBasic LANGUAGES CXX) include(FetchContent) FetchContent_Declare( diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc index 634048e..61d0b28 100644 --- a/dev/tests/network_basic/net_test.cc +++ b/dev/tests/network_basic/net_test.cc @@ -1,36 +1,22 @@ /* * File: tests/net_test.cc * Purpose: Network unit tests in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ -#include <lib/net/network.hpp> +#include <lib/net/modem.hpp> #include <lib/io/print.hpp> #include <lib/tests/gtest.hpp> #include <cstring> TEST(NetworkTest, BasicNetworkUsage) { - snu::net::basic_modem<char> modem; - modem.construct<AF_INET, SOCK_STREAM, IPPROTO_IP, 80>(snu::net::basic_modem<char>::local_address_ip4, true); + ocl::net::basic_modem modem; + modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::basic_modem::local_address_ip4, true); - snu::net::basic_modem<char> modem_cl; - modem_cl.construct<AF_INET, SOCK_STREAM, IPPROTO_IP, 80>(snu::net::basic_modem<char>::local_address_ip4, false); - - EXPECT_TRUE(modem_cl.is_valid()); EXPECT_TRUE(modem.is_valid()); std::basic_string<char> buf_dst = "HELLO, NET!"; - char* buf = new char[buf_dst.size()]; - - modem_cl.transmit(buf_dst); - modem.receive<char*>(buf, buf_dst.size()); - - snu::io::print(buf_dst); - snu::io::print(buf); - snu::io::print(); - - delete[] buf; - buf = nullptr; + EXPECT_TRUE(modem.transmit(buf_dst)); } diff --git a/dev/tests/tracked_ptr_basic/CMakeLists.txt b/dev/tests/tracked_ptr_basic/CMakeLists.txt index 9100e9a..1dd5095 100644 --- a/dev/tests/tracked_ptr_basic/CMakeLists.txt +++ b/dev/tests/tracked_ptr_basic/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(SOCLTests) +project(TrackedPtrTestBasic) include(FetchContent) FetchContent_Declare( diff --git a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc index 0e72e77..1e97188 100644 --- a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc @@ -1,8 +1,8 @@ /* * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #include <lib/memory/tracked_ptr.hpp> @@ -10,16 +10,16 @@ TEST(TrackedPtrTest, BasicTrackedPtrUsage) { - snu::memory::tracked_ptr<int> ptr = snu::memory::make_tracked<int>(42); + ocl::memory::tracked_ptr<int> ptr = ocl::memory::make_tracked<int>(42); ASSERT_TRUE(ptr); EXPECT_EQ(*ptr, 42); - snu::memory::tracked_ptr<int> ptr2; + ocl::memory::tracked_ptr<int> ptr2; - snu::memory::swap(ptr, ptr2); + ocl::memory::swap(ptr, ptr2); ptr2.reset(); - EXPECT_EQ(snu::memory::tracked_ptr<int>::manager().allocator().allocated_count_, 1); + EXPECT_EQ(ocl::memory::tracked_ptr<int>::manager().allocator().allocated_count_, 1); }
\ No newline at end of file diff --git a/dev/tests/tracked_ptr_leak/CMakeLists.txt b/dev/tests/tracked_ptr_leak/CMakeLists.txt index 625a1dc..30c91a1 100644 --- a/dev/tests/tracked_ptr_leak/CMakeLists.txt +++ b/dev/tests/tracked_ptr_leak/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(SOCLTests) +project(TrackedPtrTestLeak) include(FetchContent) FetchContent_Declare( diff --git a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc index 6818b7c..f349f47 100644 --- a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc +++ b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc @@ -1,8 +1,8 @@ /* * File: tests/tracked_ptr_test.cc * Purpose: Custom smart pointer unit tests in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #include <lib/memory/tracked_ptr.hpp> @@ -10,10 +10,10 @@ TEST(TrackedPtrTest, LeakTrackedPtrUsage) { - snu::memory::tracked_ptr<int>* ptr = new snu::memory::tracked_ptr<int>(42); - snu::memory::tracked_ptr<int>* ptr2 = new snu::memory::tracked_ptr<int>(42); - snu::memory::tracked_ptr<int>* ptr3 = new snu::memory::tracked_ptr<int>(42); + ocl::memory::tracked_ptr<int>* ptr = new ocl::memory::tracked_ptr<int>(42); + ocl::memory::tracked_ptr<int>* ptr2 = new ocl::memory::tracked_ptr<int>(42); + ocl::memory::tracked_ptr<int>* ptr3 = new ocl::memory::tracked_ptr<int>(42); - EXPECT_EQ(snu::memory::tracked_ptr<int>::manager().allocator().allocated_count_, 3); - ASSERT_TRUE(snu::memory::tracked_ptr<int>::manager().allocator().deallocated_count_ == 0); + EXPECT_EQ(ocl::memory::tracked_ptr<int>::manager().allocator().allocated_count_, 3); + ASSERT_TRUE(ocl::memory::tracked_ptr<int>::manager().allocator().deallocated_count_ == 0); }
\ No newline at end of file diff --git a/meta/tex/embfs.tex b/meta/tex/embfs.tex index e72d4b4..2d5c60e 100644 --- a/meta/tex/embfs.tex +++ b/meta/tex/embfs.tex @@ -25,7 +25,7 @@ \title{Embedded File System (EMBFS) Specification} \author{Amlal El Mahrouss} -\date{2025} +\date{\today} \begin{document} @@ -37,7 +37,7 @@ The \textbf{Embedded File System (EMBFS)} is a compact and minimal filesystem de \section{Namespace} The EMBFS implementation resides under: \begin{lstlisting} -namespace snu::embfs +namespace ocl::embfs \end{lstlisting} \section{Supported Logical Block Addressing (LBA) Modes} @@ -135,7 +135,7 @@ Represents a fixed-size array of 12 inodes within a given partition. \begin{itemize} \item Copyright © 2025 Amlal El Mahrouss \item All rights reserved. - \item For questions or licensing requests, contact: \texttt{founder@snu.systems} + \item For questions or licensing requests, contact: \texttt{amlal@nekernel.org} \end{itemize} \end{document}
\ No newline at end of file diff --git a/tools/hpptest.py b/tools/hpptest.py index f9fcd1c..dbed143 100755 --- a/tools/hpptest.py +++ b/tools/hpptest.py @@ -4,7 +4,8 @@ import sys, os if __name__ == '__main__': - if len(sys.argv) == 2: - os.system(f"clang++ -std=c++20 -DSOCL_HPPTEST '-DSOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}") - print("[TEST] HEADER COMPILATION PASSES") + if len(sys.argv) == 3: + ret = os.system(f"clang++ -I./dev/ -I{sys.argv[2]} -std=c++20 -DOCL_HPPTEST '-DOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}") + if ret == 0: + print("[TEST] HEADER COMPILATION PASSES") |
