From 7d48d4819c6726c70515ec4af0ca73f7dc2e36e6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 29 Dec 2025 08:08:10 +0100 Subject: feat: tproc: complete implementation of pred algorithms and free functions. Signed-off-by: Amlal El Mahrouss --- include/ocl/tproc.hpp | 2 +- include/ocl/tproc/detail/rope_fwd.hpp | 17 ++++-- include/ocl/tproc/detail/rope_fwd.inl | 9 ++- include/ocl/tproc/rope.hpp | 65 ++++++++++++++++---- include/ocl/tproc/rope.inl | 110 +++++++++++++++++----------------- 5 files changed, 129 insertions(+), 74 deletions(-) diff --git a/include/ocl/tproc.hpp b/include/ocl/tproc.hpp index b4c4778..c2f9d65 100644 --- a/include/ocl/tproc.hpp +++ b/include/ocl/tproc.hpp @@ -8,6 +8,6 @@ #include #include -//#include +// #include #endif // __OCL_TPROC_HPP diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index a172f90..5362f9b 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -29,12 +29,17 @@ namespace ocl::tproc using const_reference = const CharT&; using pointer = std::allocator_traits::pointer; using const_pointer = std::allocator_traits::pointer; - - basic_rope& begin(); - basic_rope& end(); - - const basic_rope& cbegin() const; - const basic_rope& cend() const; + using iterator_type = basic_rope&; + + iterator_type rbegin(); + iterator_type rend(); + + iterator_type begin(); + iterator_type end(); + + /// \todo do we need const_iterator_type now? + const iterator_type cbegin() const; + const iterator_type cend() const; /// \brief Extarcts a needle from a position of n length. basic_rope& substr(size_type pos, const size_type n = 0); diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index e5d959e..43dfc1b 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -6,15 +6,20 @@ #ifndef OCL_TPROC_ROPE_FWD_INL #define OCL_TPROC_ROPE_FWD_INL +#include + namespace ocl::tproc { template struct basic_rope::tree_impl { + using char_type = CharT; + private: std::allocator_traits::size_type size_; - CharT *head_, *tail_{}; + char_type * head_, *tail_{}; + boost::system::error_code ec_{}; public: std::allocator_traits::size_type size() @@ -57,7 +62,7 @@ namespace ocl::tproc } template - basic_rope& + basic_rope& basic_rope::operator=(basic_rope&& other) { impl_ = std::exchange(other.impl_, nullptr); diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 9d9356a..9ad5e93 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -12,7 +12,8 @@ namespace ocl::tproc::rope { - class reverse_pred + /// \brief rbegin exact pred type. + class reverse_pred final { std::string cond_; @@ -23,10 +24,19 @@ namespace ocl::tproc::rope } template - It operator()(It begin, It end); + It operator()(It rbegin, It rend) + { + for (auto rbeg{rbegin}; rbegin != rend; ++rbeg) + { + if (*rbeg == cond_) + return rbeg; + } + + return rend; + } }; - class uppercase_pred + class uppercase_pred final { std::string cond_; @@ -37,10 +47,23 @@ namespace ocl::tproc::rope } template - It operator()(It begin, It end); + It operator()(It begin, It end) + { + auto cmp = std::transform(cond_.begin(), cond_.end(), [](std::string::char_type& ch) { + return std::toupper(ch); + }); + + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class lowercase_pred + class lowercase_pred final { std::string cond_; @@ -51,10 +74,23 @@ namespace ocl::tproc::rope } template - It operator()(It begin, It end); + It operator()(It begin, It end) + { + auto cmp = std::transform(cond_.begin(), cond_.end(), [](std::string::char_type& ch) { + return std::tolower(ch); + }); + + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class exact_pred + class exact_pred final { std::string cond_; @@ -65,10 +101,19 @@ namespace ocl::tproc::rope } template - It operator()(It begin, It end); + It operator()(It begin, It end) + { + for (auto beg{begin}; begin != end; ++beg) + { + if (*beg == cond_) + return beg; + } + + return end; + } }; - class starts_with_pred + class starts_with_pred final { std::string cond_; @@ -79,7 +124,7 @@ namespace ocl::tproc::rope } template - It operator()(It begin, It end); + It operator()(It begin, It end) { return end; } }; } // namespace ocl::tproc::rope diff --git a/include/ocl/tproc/rope.inl b/include/ocl/tproc/rope.inl index fe4218e..4158e16 100644 --- a/include/ocl/tproc/rope.inl +++ b/include/ocl/tproc/rope.inl @@ -8,78 +8,78 @@ namespace ocl::tproc::rope { - + template It find(It begin, It end, Pred pred) - { - for (auto it = begin; it != end; ++it) - { - if (*it == pred) - { - return it; - } - } + { + for (auto it = begin; it != end; ++it) + { + if (*it == pred) + { + return it; + } + } - return end; - } + return end; + } template It find_if(It begin, It end, Pred pred) - { - for (auto it = begin; it != end; ++it) - { - if (pred(it, pred)) - { - return it; - } - } + { + for (auto it = begin; it != end; ++it) + { + if (pred(it, pred)) + { + return it; + } + } - return end; - } + return end; + } template It::typename size_type erase(It begin, It end, Pred) - { - It original_begin = begin; - size_t count = 0; + { + It original_begin = begin; + size_t count = 0; - for (auto it = begin; it != end; ) - { - if (*it == pred) - { - it = begin.erase(it); - ++count; - } - else - { - ++it; - } - } + for (auto it = begin; it != end;) + { + if (*it == pred) + { + it = begin.erase(it); + ++count; + } + else + { + ++it; + } + } - return count; - } + return count; + } template It::typename size_type erase_if(It begin, It end, Pred) - { - It original_begin = begin; - size_t count = 0; + { + It original_begin = begin; + size_t count = 0; - for (auto it = begin; it != end; ) - { - if (pred(it, end) != end) - { - it = begin.erase(it); - ++count; - } - else - { - ++it; - } - } + for (auto it = begin; it != end;) + { + if (pred(it, end) != end) + { + it = begin.erase(it); + ++count; + } + else + { + ++it; + } + } - return count; - } + return count; + } } // namespace ocl::tproc::rope -- cgit v1.2.3