summaryrefslogtreecommitdiffhomepage
path: root/dev/examples
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-09-04 11:25:04 +0200
committerGitHub <noreply@github.com>2025-09-04 11:25:04 +0200
commit6789dd7d88a192e3f55b95798cb393e7d12f368a (patch)
tree7f04815ad5214f97d0fb2becceceed7ce8089b3d /dev/examples
parent443588a42fe9cf48b5f63184b94afe483cb0e761 (diff)
parentfda7082c54ad46a56ac885d4686b82bad8dbc7c9 (diff)
Merge pull request #4 from amlel-el-mahrouss/devv1.0.43
OCL — v1.0.43
Diffstat (limited to 'dev/examples')
-rw-r--r--dev/examples/allocator_system/CMakeLists.txt16
-rw-r--r--dev/examples/allocator_system/allocator_system.cc50
-rw-r--r--dev/examples/cgi/CMakeLists.txt4
-rw-r--r--dev/examples/cgi/cgi.cc19
-rw-r--r--dev/examples/equiv/equiv.cc6
-rw-r--r--dev/examples/fix/fix.cc8
-rw-r--r--dev/examples/opt/opt.cc4
-rw-r--r--dev/examples/tracked_ptr/tracked_ptr.cc15
8 files changed, 92 insertions, 30 deletions
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;
}