Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / poly_collection / detail / segment_backend.hpp
1 /* Copyright 2016-2019 Joaquin M Lopez Munoz.
2  * Distributed under the Boost Software License, Version 1.0.
3  * (See accompanying file LICENSE_1_0.txt or copy at
4  * http://www.boost.org/LICENSE_1_0.txt)
5  *
6  * See http://www.boost.org/libs/poly_collection for library home page.
7  */
8
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_SEGMENT_BACKEND_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_SEGMENT_BACKEND_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <cstddef>
17 #include <memory>
18 #include <utility>
19
20 namespace boost{
21
22 namespace poly_collection{
23
24 namespace detail{
25
26 /* Internal *virtual* interface of segment<Model,Allocator> (please note that
27  * a non-virtual interface exists accessible through downcasting). Member
28  * functions have been defined to minimize virtual function calls according to
29  * usage patterns by poly_collection. For instance, ranges are returned rather
30  * than iterators to allow for caching of and end sentinel at a higher level.
31  * Passed elements are type erased with [const_]value_pointer.
32  */
33
34 template<typename Model,typename Allocator>
35 struct segment_backend
36 {
37   using segment_backend_unique_ptr=
38     std::unique_ptr<segment_backend,void(*)(segment_backend*)>;
39   using value_pointer=void*;
40   using const_value_pointer=const void*;
41   using base_iterator=typename Model::base_iterator;
42   using const_base_iterator=typename Model::const_base_iterator;
43   template<typename T>
44   using const_iterator=typename Model::template const_iterator<T>;
45   using base_sentinel=typename Model::base_sentinel;
46   using range=std::pair<base_iterator,base_sentinel>;
47
48   segment_backend()=default;
49   segment_backend(const segment_backend&)=delete;
50   segment_backend& operator=(const segment_backend&)=delete;
51
52   virtual                            ~segment_backend()=default;
53   virtual segment_backend_unique_ptr copy()const=0;
54   virtual segment_backend_unique_ptr copy(const Allocator&)const=0;
55   virtual segment_backend_unique_ptr empty_copy(const Allocator&)const=0;
56   virtual segment_backend_unique_ptr move(const Allocator&)const=0;
57   virtual bool                       equal(const segment_backend&)const=0;
58
59   virtual Allocator     get_allocator()const noexcept=0;
60   virtual base_iterator begin()const noexcept=0;
61   virtual base_iterator end()const noexcept=0;
62   virtual bool          empty()const noexcept=0;
63   virtual std::size_t   size()const noexcept=0;
64   virtual std::size_t   max_size()const noexcept=0;
65   virtual std::size_t   capacity()const noexcept=0;
66   virtual base_sentinel reserve(std::size_t)=0;
67   virtual base_sentinel shrink_to_fit()=0;
68   virtual range         push_back(const_value_pointer)=0;
69   virtual range         push_back_move(value_pointer)=0;
70   virtual range         insert(const_base_iterator,const_value_pointer)=0;
71   virtual range         insert_move(const_base_iterator,value_pointer)=0;
72   virtual range         erase(const_base_iterator)=0;
73   virtual range         erase(const_base_iterator,const_base_iterator)=0;
74   virtual range         erase_till_end(const_base_iterator)=0;
75   virtual range         erase_from_begin(const_base_iterator)=0;
76   virtual base_sentinel clear()noexcept=0;
77 };
78
79 } /* namespace poly_collection::detail */
80
81 } /* namespace poly_collection */
82
83 } /* namespace boost */
84
85 #endif