diff options
Diffstat (limited to 'include/ocl')
| -rw-r--r-- | include/ocl/tproc.hpp | 5 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/config.hpp | 14 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 17 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 69 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 22 |
5 files changed, 78 insertions, 49 deletions
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 <ocl/tproc/detail/config.hpp> #include <ocl/tproc/rope.hpp> -// #include <ocl/tproc/regex.hpp> + +#ifdef __OCL_TPROC_REGEX +// #include <ocl/tproc/linter.hpp> +#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 <boost/assert/source_location.hpp> #include <ocl/detail/config.hpp> #include <ocl/equiv.hpp> #include <ocl/option.hpp> #include <ocl/smart_ptr.hpp> #include <boost/core/detail/string_view.hpp> -#include <iterator> 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<Allocator>::size_type; using reference = CharT&; using const_reference = const CharT&; using pointer = std::allocator_traits<Allocator>::pointer; using const_pointer = const std::allocator_traits<Allocator>::pointer; - using iterator_ptr = basic_rope<CharT, Traits, Allocator>*; + 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<CharT, Traits, Allocator>& 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<CharT, Traits, Allocator>& substr(size_type pos, const size_type n = 0); size_type at(const boost::core::basic_string_view<CharT>& needle); bool starts_with(const basic_rope<CharT>&); @@ -64,8 +63,8 @@ namespace ocl::tproc const boost::core::basic_string_view<value_type> c_str(); public: - ~basic_rope(); basic_rope(const boost::core::basic_string_view<CharT>& 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<CharT>&); bool operator==(const boost::core::basic_string_view<CharT>&); - 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<Allocator>::size_type; - using rope_ptr = basic_rope<CharT, Traits, Allocator>*; using error_type = boost::system::error_code; using allocator_type = Allocator; + using iterator_ptr = basic_rope<CharT, Traits, Allocator>::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<CharT>& str, Allocator alloc = Allocator()) : weight_(str.size()), alloc_(alloc), capacity_(str.size()) + tree_impl(const boost::core::basic_string_view<CharT>& 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<rope_ptr, rope_ptr> split(size_type pos, rope_ptr this_rope, Allocator alloc = Allocator()) + std::pair<iterator_ptr, iterator_ptr> 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<CharT>& str, rope_ptr this_rope, Allocator alloc = Allocator()) + iterator_ptr insert(size_type pos, const boost::core::basic_string_view<CharT>& str, iterator_ptr this_rope, Allocator alloc = Allocator()) { auto [left, right] = split(pos, this_rope, alloc); auto* middle = new basic_rope<CharT, Traits, Allocator>(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); @@ -350,6 +355,18 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::rbegin() + { + return nullptr; + } + + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::rend() + { + return nullptr; + } + + template <class CharT, class Traits, class Allocator> const basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::cbegin() { return this->begin(); @@ -375,18 +392,6 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::rbegin() - { - return this->begin(); - } - - template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::rend() - { - return this->end(); - } - - template <class CharT, class Traits, class Allocator> basic_rope<CharT, Traits, Allocator>& basic_rope<CharT, Traits, Allocator>::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<CharT, Traits, Allocator>::operator==(const boost::core::basic_string_view<CharT>& str) { if (!impl_) - return str.empty(); + return false; return impl_->equals(str); } template <class CharT, class Traits, class Allocator> - boost::core::basic_string_view<typename basic_rope<CharT, Traits, Allocator>::value_type> basic_rope<CharT, Traits, Allocator>::data() + boost::core::basic_string_view<typename basic_rope<CharT, Traits, Allocator>::value_type> + basic_rope<CharT, Traits, Allocator>::data() { return {impl_->blob_, impl_->capacity_}; } template <class CharT, class Traits, class Allocator> - const boost::core::basic_string_view<typename basic_rope<CharT, Traits, Allocator>::value_type> basic_rope<CharT, Traits, Allocator>::c_str() + const boost::core::basic_string_view<typename basic_rope<CharT, Traits, Allocator>::value_type> + basic_rope<CharT, Traits, Allocator>::c_str() { return {impl_->blob_, impl_->capacity_}; } @@ -542,17 +549,17 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>* basic_rope<CharT, Traits, Allocator>::concat(basic_rope<CharT, Traits, Allocator>* right) + basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::concat(iterator_ptr right) { return impl_->concat(this, right); } template <class CharT, class Traits, class Allocator> - basic_rope<CharT, Traits, Allocator>* basic_rope<CharT, Traits, Allocator>::insert(size_type pos, - const boost::core::basic_string_view<CharT>& text, - iterator_ptr l) const + basic_rope<CharT, Traits, Allocator>::iterator_ptr basic_rope<CharT, Traits, Allocator>::insert(size_type pos, + const boost::core::basic_string_view<CharT>& 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) { |
