summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/tproc/detail/rope_fwd.hpp
blob: 0ce0457040d1f42df4572a9f304289ebc060b4aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2025, Amlal El Mahrouss (amlal@nekernel.org)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Official repository: https://github.com/ocl-org/tproc

#ifndef __OCL_TPROC_ROPE_FWD_HPP
#define __OCL_TPROC_ROPE_FWD_HPP

#include <ocl/tproc/detail/config.hpp>

/// \file rope_fwd.hpp
/// \brief Basic forward definitions of the `rope` type.

namespace ocl::tproc
{

	/// \brief This class implements a rope type for any **CharT** type.
	/// \note Specializations are available as `crope` and `wrope`.
	/// \author Amlal El Mahrouss
	template <class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>>
	class basic_rope final
	{
	public:
		using traits_type	  = Traits;
		using value_type	  = CharT;
		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	  = std::allocator_traits<Allocator>::pointer;
		using iterator_type	  = basic_rope<CharT, Traits, Allocator>*;

		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 iterator_type 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);

		/// \brief Rope's version of the find method.
		size_type at(const boost::core::basic_string_view<CharT>& needle);

		bool starts_with(const basic_rope<CharT>&);
		bool ends_with(const basic_rope<CharT>&);

		bool starts_with(const boost::core::basic_string_view<CharT>&);
		bool ends_with(const boost::core::basic_string_view<CharT>&);

		size_type size();
		bool	  empty() const;

		boost::core::basic_string_view<value_type>		 data();
		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& operator=(const basic_rope& rope) = delete;
		basic_rope(const basic_rope& rope)			  = delete;

		basic_rope& operator=(basic_rope&& rope);
		basic_rope(basic_rope&& rope);

		bool operator!=(const basic_rope& rope);
		bool operator==(const basic_rope& rope);

		bool operator!=(const boost::core::basic_string_view<CharT>&);
		bool operator==(const boost::core::basic_string_view<CharT>&);

	public:
		static constexpr size_type npos = (size_type)(-1);

	private:
		struct tree_impl;
		tree_impl* impl_{};
	};

#if __cplusplus >= 201811L
	using u8rope  = basic_rope<char8_t>;
	using u16rope = basic_rope<char16_t>;
#endif

	using crope = basic_rope<char>;
	using wrope = basic_rope<wchar_t>;

} // namespace ocl::tproc

#include "rope_fwd.inl"

#endif