From a786997f304745ce3766a82be06dc6a5d0c2f02c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 14 Oct 2025 04:35:26 +0200 Subject: feat: scl: major refactors and new version of SCL. Signed-off-by: Amlal El Mahrouss --- dev/examples/allocator_system/allocator_system.cc | 13 ++++++++----- dev/examples/cgi/cgi.cc | 4 ++-- dev/examples/equiv/equiv.cc | 6 +++--- dev/examples/fix/fix.cc | 6 +++--- dev/examples/opt/opt.cc | 4 ++-- dev/examples/tracked_ptr/tracked_ptr.cc | 8 ++++---- 6 files changed, 22 insertions(+), 19 deletions(-) (limited to 'dev/examples') diff --git a/dev/examples/allocator_system/allocator_system.cc b/dev/examples/allocator_system/allocator_system.cc index c3cd689..169cd97 100644 --- a/dev/examples/allocator_system/allocator_system.cc +++ b/dev/examples/allocator_system/allocator_system.cc @@ -8,10 +8,11 @@ #include #include -struct MyClass +class MyClass final { - int a; - std::string b; +public: + int a{}; + std::string b{}; MyClass() : a(0), b("default") { @@ -31,17 +32,19 @@ struct MyClass int main() { - using Alloc = ocl::standard_allocator_type; - Alloc allocator; + scl::standard_allocator_type 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(42, "hello"); std::cout << "ptr->a = " << ptr->a << ", ptr->b = " << ptr->b << "\n"; diff --git a/dev/examples/cgi/cgi.cc b/dev/examples/cgi/cgi.cc index 692f90c..6f73eff 100644 --- a/dev/examples/cgi/cgi.cc +++ b/dev/examples/cgi/cgi.cc @@ -6,7 +6,7 @@ #include -static ocl::basic_chunk_string text_sample = R"( +static scl::basic_chunk_string text_sample = R"( @@ -68,7 +68,7 @@ static ocl::basic_chunk_string text_sample = R"( /* @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; + scl::cgi::basic_writer<> writer; writer << text_sample; return 0; diff --git a/dev/examples/equiv/equiv.cc b/dev/examples/equiv/equiv.cc index 12207f4..9d41afb 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 << ocl::equiv::is_same::value << std::endl; - std::cout << ocl::equiv::is_same::value << std::endl; - std::cout << ocl::equiv::is_same::value << std::endl; + std::cout << scl::equiv::is_same::value << std::endl; + std::cout << scl::equiv::is_same::value << std::endl; + std::cout << scl::equiv::is_same::value << std::endl; return 0; } diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc index ec6668a..aaac979 100644 --- a/dev/examples/fix/fix.cc +++ b/dev/examples/fix/fix.cc @@ -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|"; - ocl::fix::basic_visitor basic_visitor; - ocl::fix::basic_range_data fix = basic_visitor.visit(default_fix); + scl::fix::basic_visitor basic_visitor; + scl::fix::basic_range_data 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::fix::must_pass(fix); + scl::fix::must_pass(fix); for (auto fields : fix.body_) { diff --git a/dev/examples/opt/opt.cc b/dev/examples/opt/opt.cc index 8a74fa2..eb725c4 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 = ocl::opt(ocl::eval_eq(hash_to_check, opt_hash)); /* do the compute */ + auto opt = scl::opt(scl::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... - ocl::io::println("Testing data..."); + scl::io::println("Testing data..."); auto opt = do_some("Ohio", "Ohio"); opt.try_or_throw("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 6e3f4a2..6b8a859 100644 --- a/dev/examples/tracked_ptr/tracked_ptr.cc +++ b/dev/examples/tracked_ptr/tracked_ptr.cc @@ -9,13 +9,13 @@ static void summon_tracked_ptr() { - ocl::memory::tracked_ptr ptr = ocl::memory::make_tracked(42); + scl::memory::tracked_ptr ptr = scl::memory::make_tracked(42); std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; } static void summon_leak_tracked_ptr() { - ocl::memory::tracked_ptr* ptr = new ocl::memory::tracked_ptr(42); + scl::memory::tracked_ptr* ptr = new scl::memory::tracked_ptr(42); std::cout << ptr->data() << "=" << ptr->manager().allocator().allocated_count_ << std::endl; } @@ -27,7 +27,7 @@ int main(int argc, char** argv) summon_tracked_ptr(); summon_tracked_ptr(); - ocl::memory::tracked_ptr ptr; + scl::memory::tracked_ptr ptr; std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; @@ -46,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; - ocl::memory::must_pass(ptr); + scl::memory::must_pass(ptr); return EXIT_SUCCESS; } -- cgit v1.2.3