From 4d82c27728d92ebcf51e20ae444967b407931445 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 4 Jan 2026 07:53:50 +0100 Subject: feat: API: preping terrain for iterator_ptr. API improvements. Signed-off-by: Amlal El Mahrouss --- CMakeLists.txt | 2 +- README.md | 23 ++++++++++++ example/simple_example/Jamfile.v2 | 14 +++++++ example/simple_example/example.cpp | 14 +++++++ include/ocl/tproc.hpp | 5 ++- include/ocl/tproc/detail/config.hpp | 14 ++++++- include/ocl/tproc/detail/rope_fwd.hpp | 17 ++++----- include/ocl/tproc/detail/rope_fwd.inl | 69 +++++++++++++++++++---------------- include/ocl/tproc/rope.hpp | 22 ++++++++--- install_tproc.cmake | 2 +- 10 files changed, 131 insertions(+), 51 deletions(-) create mode 100644 README.md create mode 100644 example/simple_example/Jamfile.v2 create mode 100644 example/simple_example/example.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5218c38..a7d0dc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # // ============================================================= // # // Open C++ Libraries. -# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under BSD-3 license. +# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under BSL license. # // ============================================================= // cmake_minimum_required(VERSION 3.30) diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e63bd8 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# OCL.TProc + +[![License: BSL](https://img.shields.io/badge/license-BSL-blue.svg)](LICENSE) + +Text Processing set of containers from the OCL. + +## Requirements: + +The OCL requires the following: + +- [Boost](https://www.boost.org/) +- [Clang](https://clang.llvm.org/) +- [CMake](https://cmake.org/) +- [Git](https://git-scm.com/) +- OCL.Core + +## Freestanding Status + +The Freestanding Status is a concept where a module is evaluated on whether it has or is fully freestanding or not. + +- Unverified + +##### (c) 2025 Amlal El Mahrouss and OCL Authors, licensed under the Boost Software License. diff --git a/example/simple_example/Jamfile.v2 b/example/simple_example/Jamfile.v2 new file mode 100644 index 0000000..a152044 --- /dev/null +++ b/example/simple_example/Jamfile.v2 @@ -0,0 +1,14 @@ +# +# File: Jamfile.v2 +# Author: Amlal El Mahrouss, +# Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License +# + +project tests +: default-build debug +; + +exe example.o + : example.cpp + : 20 ; + diff --git a/example/simple_example/example.cpp b/example/simple_example/example.cpp new file mode 100644 index 0000000..a60dcad --- /dev/null +++ b/example/simple_example/example.cpp @@ -0,0 +1,14 @@ +/* + * File: example.cpp + * Purpose: Rope example. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. + */ + +#include + +int main() +{ + auto rope = ocl::tproc::crope("The Quick Brown Fox Jumps Over The Lazy Dog"); + ocl::io::println(rope.data()); +} diff --git a/include/ocl/tproc.hpp b/include/ocl/tproc.hpp index c2f9d65..3bd0e67 100644 --- a/include/ocl/tproc.hpp +++ b/include/ocl/tproc.hpp @@ -8,6 +8,9 @@ #include #include -// #include + +#ifdef __OCL_TPROC_REGEX +// #include +#endif #endif // __OCL_TPROC_HPP diff --git a/include/ocl/tproc/detail/config.hpp b/include/ocl/tproc/detail/config.hpp index 873cced..455a5d3 100644 --- a/include/ocl/tproc/detail/config.hpp +++ b/include/ocl/tproc/detail/config.hpp @@ -8,16 +8,26 @@ #ifndef __OCL_TPROC_CONFIG #define __OCL_TPROC_CONFIG +#include #include #include #include #include #include -#include namespace ocl::tproc { -} + namespace detail + { + + inline void throw_invalid_range(const auto sc = BOOST_CURRENT_LOCATION) + { + throw std::out_of_range(sc.to_string()); + } + + } // namespace detail + +} // namespace ocl::tproc #endif // ifndef __OCL_TPROC_CONFIG diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index 51754d7..f627a34 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -23,28 +23,27 @@ namespace ocl::tproc public: using traits_type = Traits; using value_type = CharT; + using char_type = value_type; using allocator_type = Allocator; using size_type = std::allocator_traits::size_type; using reference = CharT&; using const_reference = const CharT&; using pointer = std::allocator_traits::pointer; using const_pointer = const std::allocator_traits::pointer; - using iterator_ptr = basic_rope*; + using iterator_ptr = pointer; - iterator_ptr rbegin(); - iterator_ptr rend(); + iterator_ptr rbegin(); + iterator_ptr rend(); iterator_ptr begin(); iterator_ptr end(); - /// \todo do we need const_iterator_ptr now? const iterator_ptr cbegin(); const iterator_ptr cend(); - /// \brief Extarcts a needle from a position of n length. - basic_rope& substr(size_type pos, const size_type n = 0); + iterator_ptr concat(iterator_ptr right); - /// \brief Rope's version of the find method. + basic_rope& substr(size_type pos, const size_type n = 0); size_type at(const boost::core::basic_string_view& needle); bool starts_with(const basic_rope&); @@ -64,8 +63,8 @@ namespace ocl::tproc const boost::core::basic_string_view c_str(); public: - ~basic_rope(); basic_rope(const boost::core::basic_string_view& in = {}); + ~basic_rope(); basic_rope& operator=(const basic_rope& rope) = delete; basic_rope(const basic_rope& rope) = delete; @@ -79,8 +78,6 @@ namespace ocl::tproc bool operator!=(const boost::core::basic_string_view&); bool operator==(const boost::core::basic_string_view&); - iterator_ptr concat(iterator_ptr right); - public: static constexpr size_type npos = (size_type)(-1); diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index 1ef44bf..427bc2e 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -17,13 +17,13 @@ namespace ocl::tproc using char_type = CharT; using value_type = char_type; using size_type = typename std::allocator_traits::size_type; - using rope_ptr = basic_rope*; using error_type = boost::system::error_code; using allocator_type = Allocator; + using iterator_ptr = basic_rope::iterator_ptr; // B-Tree fields. - rope_ptr left_{nullptr}; // Left child (internal node only) - rope_ptr right_{nullptr}; // Right child (internal node only) + iterator_ptr left_{nullptr}; // Left child (internal node only) + iterator_ptr right_{nullptr}; // Right child (internal node only) size_type weight_{0}; // Size of left subtree (internal) OR data size (leaf) value_type* blob_{nullptr}; // Character data (leaf node only) size_type capacity_{0}; // Allocated blob capacity @@ -39,7 +39,8 @@ namespace ocl::tproc return blob_ != nullptr; } - tree_impl(const boost::core::basic_string_view& str, Allocator alloc = Allocator()) : weight_(str.size()), alloc_(alloc), capacity_(str.size()) + tree_impl(const boost::core::basic_string_view& str, + Allocator alloc = Allocator()) : weight_(str.size()), alloc_(alloc), capacity_(str.size()) { if (weight_ > 0) { @@ -49,7 +50,9 @@ namespace ocl::tproc } } - tree_impl(rope_ptr left, rope_ptr right, Allocator alloc = Allocator()) : left_(left), right_(right), alloc_(alloc) + tree_impl(iterator_ptr left, + iterator_ptr right, + Allocator alloc = Allocator()) : left_(left), right_(right), alloc_(alloc) { weight_ = left ? left->impl_->total_size() : 0; } @@ -111,7 +114,9 @@ namespace ocl::tproc } public: - static rope_ptr concat(rope_ptr left, rope_ptr right, Allocator alloc = Allocator()) + iterator_ptr concat(iterator_ptr left, + iterator_ptr right, + Allocator alloc = Allocator()) { if (!left) return right; @@ -129,7 +134,7 @@ namespace ocl::tproc return new_rope; } - std::pair split(size_type pos, rope_ptr this_rope, Allocator alloc = Allocator()) + std::pair split(size_type pos, iterator_ptr this_rope, Allocator alloc = Allocator()) { if (is_leaf()) { @@ -166,14 +171,14 @@ namespace ocl::tproc } } - rope_ptr insert(size_type pos, const boost::core::basic_string_view& str, rope_ptr this_rope, Allocator alloc = Allocator()) + iterator_ptr insert(size_type pos, const boost::core::basic_string_view& str, iterator_ptr this_rope, Allocator alloc = Allocator()) { auto [left, right] = split(pos, this_rope, alloc); auto* middle = new basic_rope(str); return concat(concat(left, middle, alloc), right, alloc); } - rope_ptr substr(size_type pos, size_type len, rope_ptr this_rope, Allocator alloc = Allocator()) + iterator_ptr substr(size_type pos, size_type len, iterator_ptr this_rope, Allocator alloc = Allocator()) { auto [_, right] = split(pos, this_rope, alloc); @@ -349,6 +354,18 @@ namespace ocl::tproc return nullptr; } + template + basic_rope::iterator_ptr basic_rope::rbegin() + { + return nullptr; + } + + template + basic_rope::iterator_ptr basic_rope::rend() + { + return nullptr; + } + template const basic_rope::iterator_ptr basic_rope::cbegin() { @@ -374,18 +391,6 @@ namespace ocl::tproc return impl_->size() < 1UL; } - template - basic_rope::iterator_ptr basic_rope::rbegin() - { - return this->begin(); - } - - template - basic_rope::iterator_ptr basic_rope::rend() - { - return this->end(); - } - template basic_rope& basic_rope::substr(size_type pos, const size_type n) @@ -415,11 +420,11 @@ namespace ocl::tproc if (needle.size() > rope_size) return npos; - for (size_type i = 0; i <= rope_size - needle.size(); ++i) + for (size_type i{}; i <= (rope_size - needle.size()); ++i) { bool match = true; - for (size_type j = 0; j < needle.size(); ++j) + for (size_type j{}; j < needle.size(); ++j) { if (impl_->at(i + j) != needle[j]) { @@ -518,19 +523,21 @@ namespace ocl::tproc bool basic_rope::operator==(const boost::core::basic_string_view& str) { if (!impl_) - return str.empty(); + return false; return impl_->equals(str); } template - boost::core::basic_string_view::value_type> basic_rope::data() + boost::core::basic_string_view::value_type> + basic_rope::data() { return {impl_->blob_, impl_->capacity_}; } template - const boost::core::basic_string_view::value_type> basic_rope::c_str() + const boost::core::basic_string_view::value_type> + basic_rope::c_str() { return {impl_->blob_, impl_->capacity_}; } @@ -542,17 +549,17 @@ namespace ocl::tproc } template - basic_rope* basic_rope::concat(basic_rope* right) + basic_rope::iterator_ptr basic_rope::concat(iterator_ptr right) { return impl_->concat(this, right); } template - basic_rope* basic_rope::insert(size_type pos, - const boost::core::basic_string_view& text, - iterator_ptr l) const + basic_rope::iterator_ptr basic_rope::insert(size_type pos, + const boost::core::basic_string_view& text, + iterator_ptr left) const { - return impl_->insert(pos, text, l); + return impl_->insert(pos, text, left); } } // namespace ocl::tproc diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index f36eb18..9573734 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -23,6 +23,8 @@ namespace ocl::tproc::rope { } + using iterator_ptr = It*; + It* operator()(It* rbegin, It* rend) { for (auto rbeg{rbegin}; rbeg != rend; ++rbeg) @@ -47,7 +49,9 @@ namespace ocl::tproc::rope { } - It* operator()(It* begin, It* end) + using iterator_ptr = It*; + + iterator_ptr operator()(iterator_ptr begin, iterator_ptr end) { for (auto beg{begin}; beg != end; ++beg) { @@ -70,7 +74,9 @@ namespace ocl::tproc::rope { } - It* operator()(It* begin, It* end) + using iterator_ptr = It*; + + iterator_ptr operator()(iterator_ptr begin, iterator_ptr end) { std::transform(cond_.begin(), cond_.end(), @@ -99,7 +105,9 @@ namespace ocl::tproc::rope { } - It* operator()(It* begin, It* end) + using iterator_ptr = It*; + + iterator_ptr operator()(iterator_ptr begin, iterator_ptr end) { std::transform(cond_.begin(), cond_.end(), @@ -128,7 +136,9 @@ namespace ocl::tproc::rope { } - It* operator()(It* begin, It* end) + using iterator_ptr = It*; + + iterator_ptr operator()(iterator_ptr begin, iterator_ptr end) { for (auto beg{begin}; beg != end; ++beg) { @@ -151,7 +161,9 @@ namespace ocl::tproc::rope { } - It* operator()(It* begin, It* end) + using iterator_ptr = It*; + + iterator_ptr operator()(iterator_ptr begin, iterator_ptr end) { for (auto beg{begin}; beg != end; ++beg) { diff --git a/install_tproc.cmake b/install_tproc.cmake index 2c7a604..58355c5 100644 --- a/install_tproc.cmake +++ b/install_tproc.cmake @@ -1,6 +1,6 @@ # // ============================================================= // # // Open C++ Libraries. -# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under BSD-3 license. +# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under the BSL license. # // ============================================================= // cmake_minimum_required(VERSION 3.30) -- cgit v1.2.3