diff options
| -rw-r--r-- | example/simple_example/example.cpp | 7 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 8 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 10 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 26 | ||||
| -rw-r--r-- | test/rope_test/crope.pred.test.cpp | 22 |
5 files changed, 44 insertions, 29 deletions
diff --git a/example/simple_example/example.cpp b/example/simple_example/example.cpp index da543a9..3feb686 100644 --- a/example/simple_example/example.cpp +++ b/example/simple_example/example.cpp @@ -7,6 +7,7 @@ #include <ocl/tproc/rope.hpp> #include <iostream> +#include <memory> #ifndef STANDALONE using namespace ocl; @@ -18,9 +19,9 @@ int main() { auto rope = tproc::crope("The Quick Brown Fox Jumps Over The Lazy Dog"); - std::unique_ptr<tproc::crope> new_elem(new tproc::crope(", and Jumps again.")); + std::unique_ptr<tproc::crope> new_elem = std::make_unique<tproc::crope>(", and Jumps again."); std::unique_ptr<tproc::crope> res(rope.concat(new_elem.get())); - std::cout << ++rope; - std::cout << rope; + std::cout << *++rope << std::endl; + std::cout << rope << std::endl; } diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index 9fe6212..0aabf86 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -42,8 +42,8 @@ namespace ocl::tproc rope_ptr operator++(); rope_ptr operator++(int); - const rope_ptr cbegin(); - const rope_ptr cend(); + const rope_ptr cbegin() const; + const rope_ptr cend() const; rope_ptr concat(rope_ptr right); @@ -56,7 +56,7 @@ namespace ocl::tproc bool starts_with(const boost::core::basic_string_view<CharT>&); bool ends_with(const boost::core::basic_string_view<CharT>&); - size_type size(); + size_type size() const; bool empty() const; rope_ptr insert(size_type pos, @@ -64,7 +64,7 @@ namespace ocl::tproc rope_ptr) const; boost::core::basic_string_view<value_type> data(); - const boost::core::basic_string_view<value_type> c_str(); + const boost::core::basic_string_view<value_type> c_str() const; public: basic_rope(const boost::core::basic_string_view<CharT>& in = {}); diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index 5ce38f8..4fd6e9a 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -396,7 +396,7 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - const basic_rope<CharT, Traits, Allocator>::rope_ptr basic_rope<CharT, Traits, Allocator>::cbegin() + const basic_rope<CharT, Traits, Allocator>::rope_ptr basic_rope<CharT, Traits, Allocator>::cbegin() const { if (impl_->is_leaf()) return this; @@ -405,14 +405,14 @@ namespace ocl::tproc } template <class CharT, class Traits, class Allocator> - const basic_rope<CharT, Traits, Allocator>::rope_ptr basic_rope<CharT, Traits, Allocator>::cend() + const basic_rope<CharT, Traits, Allocator>::rope_ptr basic_rope<CharT, Traits, Allocator>::cend() const { return nullptr; } template <class CharT, class Traits, class Allocator> basic_rope<CharT, Traits, Allocator>::size_type - basic_rope<CharT, Traits, Allocator>::size() + basic_rope<CharT, Traits, Allocator>::size() const { return impl_->size(); } @@ -567,7 +567,7 @@ namespace ocl::tproc 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() + basic_rope<CharT, Traits, Allocator>::c_str() const { return {impl_->blob_, impl_->capacity_}; } @@ -603,7 +603,7 @@ namespace ocl::tproc { return data(); } - + template <class CharT, class Traits, class Allocator> basic_rope<CharT, Traits, Allocator>::rope_ptr basic_rope<CharT, Traits, Allocator>::operator++() { diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 05e5399..fba755a 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -194,14 +194,28 @@ namespace ocl::tproc } // namespace ocl::tproc -inline std::ostream & operator<<(std::ostream& os, ocl::tproc::crope& r){ - os << r.data(); - return os; +inline std::ostream& operator<<(std::ostream& os, ocl::tproc::crope& r) +{ + os << r.data(); + return os; +} + +inline std::wostream& operator<<(std::wostream& os, ocl::tproc::wrope& r) +{ + os << r.data(); + return os; } -inline std::wostream & operator<<(std::wostream& os, ocl::tproc::wrope& r){ - os << r.data(); - return os; +inline std::ostream& operator<<(std::ostream& os, const ocl::tproc::crope& r) +{ + os << r.c_str(); + return os; +} + +inline std::wostream& operator<<(std::wostream& os, const ocl::tproc::wrope& r) +{ + os << r.c_str(); + return os; } #include "rope.inl" diff --git a/test/rope_test/crope.pred.test.cpp b/test/rope_test/crope.pred.test.cpp index afbc9c5..a967adb 100644 --- a/test/rope_test/crope.pred.test.cpp +++ b/test/rope_test/crope.pred.test.cpp @@ -7,6 +7,7 @@ #include <ocl/tproc/rope.hpp> #include <memory> +#include <iostream> #define BOOST_TEST_MODULE crope_pred #include <boost/test/included/unit_test.hpp> @@ -20,11 +21,11 @@ using namespace boost; BOOST_AUTO_TEST_CASE(rope_should_succeed_in_find_pred) { auto rope = tproc::crope("Exact Sentence"); - auto it = tproc::rope::exact_pred<tproc::crope>{"Exact Sentence"}(rope.cbegin(), rope.cend()); + auto it = tproc::rope::exact_pred<tproc::crope>{"Exact Sentence"}(rope.begin(), rope.end()); BOOST_TEST(it != rope.cend()); - ocl::io::println(it->data()); + std::cout << rope << std::endl; } BOOST_AUTO_TEST_CASE(rope_should_succeed_in_at) @@ -32,27 +33,26 @@ BOOST_AUTO_TEST_CASE(rope_should_succeed_in_at) auto rope = tproc::crope("Exact Sentence"); auto it = std::move(rope.substr(rope.at("Exact"), rope.size())); - ocl::io::println(it.data()); + BOOST_ASSERT(it == "Exact Sentence"); } BOOST_AUTO_TEST_CASE(rope_should_succeed_in_starts_with) { auto rope = tproc::crope("The Quick Brown Fox Jumps Over The Lazy Dog"); - + // find the leaf with the starting value 'foo' - auto it = tproc::rope::starts_with_pred<tproc::crope>{"The Quick"}(rope.cbegin(), rope.cend()); + auto it = tproc::rope::starts_with_pred<tproc::crope>{"The Quick"}(rope.begin(), rope.end()); BOOST_TEST(it != rope.cend()); - auto it_end = tproc::rope::ends_with_pred<tproc::crope>{"Lazy Dog"}(rope.cbegin(), rope.cend()); + auto it_end = tproc::rope::ends_with_pred<tproc::crope>{"Lazy Dog"}(rope.begin(), rope.end()); BOOST_TEST(it_end != rope.cend()); - io::println(it_end->data()); - io::println(it->data()); - - std::unique_ptr<tproc::crope> new_elem(new tproc::crope(", and Jumps again.")); + std::unique_ptr<tproc::crope> new_elem = std::make_unique<tproc::crope>(", and Jumps again."); std::unique_ptr<tproc::crope> ret_elem(rope.concat(new_elem.get())); - io::println(ret_elem->data()); + BOOST_TEST((*ret_elem == "The Quick Brown Fox Jumps Over The Lazy Dog, and Jumps again.")); + + std::cout << *ret_elem; } |
