diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-29 14:53:01 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-29 14:54:13 -0500 |
| commit | a8e99f3a783069cf85b626c6cfb2fbe83ae4fd44 (patch) | |
| tree | 8322b0d20dd02660c3f26fcfd37c2cc4dcd33cda /examples | |
| parent | 463a0c01f96d86c9c91f02903bc1d194c5e55b15 (diff) | |
chore: new version of OCL and codebase cleanup.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/.keep | 0 | ||||
| -rw-r--r-- | examples/allocator_system/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | examples/allocator_system/allocator_system.cc | 53 | ||||
| -rw-r--r-- | examples/cgi/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | examples/cgi/cgi.cc | 75 | ||||
| -rw-r--r-- | examples/equiv/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | examples/equiv/equiv.cc | 19 | ||||
| -rw-r--r-- | examples/fix/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | examples/fix/fix.cc | 47 | ||||
| -rw-r--r-- | examples/fix_tag_example/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | examples/fix_tag_example/example.cc | 30 | ||||
| -rw-r--r-- | examples/opt/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | examples/opt/opt.cc | 45 | ||||
| -rw-r--r-- | examples/tracked_ptr/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | examples/tracked_ptr/tracked_ptr.cc | 53 | ||||
| -rw-r--r-- | examples/url/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | examples/url/url.cc | 24 |
17 files changed, 45 insertions, 414 deletions
diff --git a/examples/.keep b/examples/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/examples/.keep diff --git a/examples/allocator_system/CMakeLists.txt b/examples/allocator_system/CMakeLists.txt deleted file mode 100644 index a4bb69d..0000000 --- a/examples/allocator_system/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ - -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 ../../include/ocl) diff --git a/examples/allocator_system/allocator_system.cc b/examples/allocator_system/allocator_system.cc deleted file mode 100644 index fd7ae56..0000000 --- a/examples/allocator_system/allocator_system.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * File: allocator_system.cc - * Purpose: Allocator System container. - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License. Licensed under the BSL 1.0 license - */ - -#include <memory/allocator_system.hpp> -#include <iostream> - -class MyClass final -{ -public: - 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() -{ - ocl::standard_allocator_type<MyClass> 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/examples/cgi/CMakeLists.txt b/examples/cgi/CMakeLists.txt deleted file mode 100644 index e30707c..0000000 --- a/examples/cgi/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - CGI - 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 ../../include/ocl) diff --git a/examples/cgi/cgi.cc b/examples/cgi/cgi.cc deleted file mode 100644 index b837433..0000000 --- a/examples/cgi/cgi.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - cgi example - written by Amlal El Mahrouss. - licensed under the Boost Software License - */ - -#include <utility/cgi.hpp> - -static ocl::basic_chunk_string<char> text_sample = R"( -<!DOCTYPE html> -<html> -<head> - <meta charset="UTF-8"> - <title>Error | OCL</title> - <style> - body { - font-family: monospace; - background: white; - color: black; - margin: 2em; - } - h1 { - font-size: 1.5em; - } - hr { - border: none; - border-top: 1px solid #ccc; - } - table { - width: 100%; - border-collapse: collapse; - } - td { - padding: 0.2em 0.5em; - } - td:first-child { - white-space: nowrap; - } - a { - color: blue; - text-decoration: none; - } - a:hover { - text-decoration: underline; - } - </style> -</head> -<body> - <h1>Uh Oh!</h1> - <address>No index file was found in this directory.</address> - <hr> - <table> - <tr><th>Name</th></tr> - <tr><td colspan="3"><hr></td></tr> - - <tr> - <td><a href="javascript:window.location.reload();">Refresh</a></td> - </tr> - - <tr><td colspan="3"><hr></td></tr> - </table> - <address>OCL's Common Gateway Server.</address> -</body> -</html> -)"; - -/* finally test it */ -/* @brief this stub loads a 'index.html' or returns an error message if not found. */ -int main(int argc, char** argv) -{ - ocl::cgi::basic_writer<> writer; - writer << text_sample; - - return 0; -} diff --git a/examples/equiv/CMakeLists.txt b/examples/equiv/CMakeLists.txt deleted file mode 100644 index 4a374ce..0000000 --- a/examples/equiv/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Equiv - VERSION 1.0 - LANGUAGES CXX) - -add_executable(Equiv equiv.cc) - -set_property(TARGET Equiv PROPERTY CXX_STANDARD 20) -target_include_directories(Equiv PUBLIC ../../include/ocl) diff --git a/examples/equiv/equiv.cc b/examples/equiv/equiv.cc deleted file mode 100644 index 0c68e21..0000000 --- a/examples/equiv/equiv.cc +++ /dev/null @@ -1,19 +0,0 @@ -/* - string checksum example - written by Amlal El Mahrouss. - licensed under the Boost Software License - */ - -#include <logic/equiv.hpp> -#include <iostream> - -/* finally test it */ -int main(int argc, char** argv) -{ - std::cout << std::boolalpha; - 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/examples/fix/CMakeLists.txt b/examples/fix/CMakeLists.txt deleted file mode 100644 index 143b1c4..0000000 --- a/examples/fix/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Fix - VERSION 1.0 - LANGUAGES CXX) - -find_package(Boost REQUIRED COMPONENTS container) - -add_executable(Fix fix.cc) - -set_property(TARGET Fix PROPERTY CXX_STANDARD 20) -target_include_directories(Fix PUBLIC ../../include/ocl) -target_link_libraries(Fix PRIVATE Boost::container) diff --git a/examples/fix/fix.cc b/examples/fix/fix.cc deleted file mode 100644 index f52246f..0000000 --- a/examples/fix/fix.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - fix example - Written by Amlal El Mahrouss. - Licensed under the Boost Software License - */ - -#include <core/error_handler.hpp> -#include <fix/parser.hpp> -#include <iostream> -#include <unistd.h> -#include <io/print.hpp> -#include <sys/socket.h> - -/* finally test it */ -int main(int argc, char** argv) -{ - constexpr const char default_fix[] = { - '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01, - '9', '=', '6', '3', 0x01, // BodyLength = 63 - '3', '5', '=', 'A', 0x01, - '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01, - '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01, - '3', '4', '=', '1', '7', '7', 0x01, - '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01, - '9', '8', '=', '0', 0x01, - '1', '0', '8', '=', '3', '0', 0x01, - '1', '0', '=', '1', '4', '3', 0x01, 0x00 // CheckSum = 143 - }; - - 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; - - ocl::basic_error_handler handler; - ocl::fix::must_pass<char, ocl::basic_error_handler>(fix, handler); - - ocl::io::print(":key=35\n"); - ocl::io::print(":value=", fix["35"], "\n"); - - ocl::io::print(":key=49\n"); - ocl::io::print(":value=", fix["49"], "\n"); - - return 0; -} diff --git a/examples/fix_tag_example/CMakeLists.txt b/examples/fix_tag_example/CMakeLists.txt new file mode 100644 index 0000000..e3b9cca --- /dev/null +++ b/examples/fix_tag_example/CMakeLists.txt @@ -0,0 +1,15 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + FixExample + VERSION 1.0 + LANGUAGES CXX) + +find_package(Boost REQUIRED COMPONENTS container) + +add_executable(FixExample fix.cc) + +set_property(TARGET FixExample PROPERTY CXX_STANDARD 20) +target_include_directories(FixExample PUBLIC ../../include/ocl) +target_link_libraries(FixExample PRIVATE Boost::container) diff --git a/examples/fix_tag_example/example.cc b/examples/fix_tag_example/example.cc new file mode 100644 index 0000000..ce1f6c8 --- /dev/null +++ b/examples/fix_tag_example/example.cc @@ -0,0 +1,30 @@ +#include <core/error_handler.hpp> +#include <fix/parser.hpp> +#include <io/print.hpp> + +constexpr const char default_fix[] = { + '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01, + '9', '=', '6', '3', 0x01, // BodyLength = 63 + '3', '5', '=', 'A', 0x01, + '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01, + '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01, + '3', '4', '=', '1', '7', '7', 0x01, + '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01, + '9', '8', '=', '0', 0x01, + '1', '0', '8', '=', '3', '0', 0x01, + '1', '0', '=', '1', '4', '3', 0x01, 0x00 // CheckSum = 143 +}; + +int main(int argc, char** argv) +{ + ocl::fix::visitor basic_visitor; + ocl::fix::range_data fix = basic_visitor.visit(default_fix); + + ocl::io::print(":key=35\n"); + ocl::io::print(":value=", fix["35"], "\n"); + + ocl::io::print(":key=49\n"); + ocl::io::print(":value=", fix["49"], "\n"); + + return 0; +} diff --git a/examples/opt/CMakeLists.txt b/examples/opt/CMakeLists.txt deleted file mode 100644 index e537cec..0000000 --- a/examples/opt/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Opt - VERSION 1.0 - LANGUAGES CXX) - -add_executable(Opt opt.cc) - -set_property(TARGET Opt PROPERTY CXX_STANDARD 20) -target_include_directories(Opt PUBLIC ../../include/ocl) diff --git a/examples/opt/opt.cc b/examples/opt/opt.cc deleted file mode 100644 index dbeab2f..0000000 --- a/examples/opt/opt.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - String checksum example - Written by Amlal El Mahrouss. - Licensed under the Boost Software License - */ - -#include <logic/opt.hpp> -#include <io/print.hpp> -#include <utility/crc32.hpp> -#include <string> - -static const char do_hash(const std::string& in) -{ - int hash = 0; - - for (long index = 0; index < in.size(); ++index) - { - hash += in[index]; - } - - return hash; -} - -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 = ocl::opt(ocl::eval_eq(hash_to_check, opt_hash)); /* do the compute */ - return opt; -} - -/* finally test it */ -int main(int argc, char** argv) -{ - // ... let's assume we fetch data from network... - - ocl::io::println("Testing data..."); - - auto opt = do_some("Foo", "Foo"); - opt.expect("Checksum failed, Foo isn't Foo!"); - - - return 0; -} diff --git a/examples/tracked_ptr/CMakeLists.txt b/examples/tracked_ptr/CMakeLists.txt deleted file mode 100644 index ea1312a..0000000 --- a/examples/tracked_ptr/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Fix - VERSION 1.0 - LANGUAGES CXX) - -add_executable(TrackedPtr tracked_ptr.cc) - -set_property(TARGET TrackedPtr PROPERTY CXX_STANDARD 20) -target_include_directories(TrackedPtr PUBLIC ../../include/ocl) diff --git a/examples/tracked_ptr/tracked_ptr.cc b/examples/tracked_ptr/tracked_ptr.cc deleted file mode 100644 index 3f1a4ec..0000000 --- a/examples/tracked_ptr/tracked_ptr.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - tracked_ptr example - written by Amlal El Mahrouss. - licensed under the Boost Software License - */ - -#include <memory/tracked_ptr.hpp> -#include <io/print.hpp> - -static void summon_tracked_ptr() -{ - ocl::memory::tracked_ptr<int> ptr = ocl::memory::make_tracked<int>(42); - std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; -} - -static void summon_leak_tracked_ptr() -{ - ocl::memory::tracked_ptr<int>* ptr = new ocl::memory::tracked_ptr<int>(42); - std::cout << ptr->data() << "=" << ptr->manager().allocator().allocated_count_ << std::endl; -} - -/* finally test it */ -int main(int argc, char** argv) -{ - summon_tracked_ptr(); - summon_tracked_ptr(); - summon_tracked_ptr(); - summon_tracked_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(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - - 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; - - ocl::standard_error_handler err; - ocl::memory::must_pass(ptr, err); - - return EXIT_SUCCESS; -} diff --git a/examples/url/CMakeLists.txt b/examples/url/CMakeLists.txt deleted file mode 100644 index 7195d6c..0000000 --- a/examples/url/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ - -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 deleted file mode 100644 index b4cc924..0000000 --- a/examples/url/url.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - 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; -} |
