segment_backend.hpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright 2016-2020 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. #ifndef BOOST_POLY_COLLECTION_DETAIL_SEGMENT_BACKEND_HPP
  9. #define BOOST_POLY_COLLECTION_DETAIL_SEGMENT_BACKEND_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <cstddef>
  14. #include <memory>
  15. #include <utility>
  16. namespace boost{
  17. namespace poly_collection{
  18. namespace detail{
  19. /* Internal *virtual* interface of segment<Model,Allocator> (please note that
  20. * a non-virtual interface exists accessible through downcasting). Member
  21. * functions have been defined to minimize virtual function calls according to
  22. * usage patterns by poly_collection. For instance, ranges are returned rather
  23. * than iterators to allow for caching of and end sentinel at a higher level.
  24. * Passed elements are type erased with [const_]value_pointer.
  25. */
  26. template<typename Model,typename Allocator>
  27. struct segment_backend
  28. {
  29. using segment_backend_unique_ptr=
  30. std::unique_ptr<segment_backend,void(*)(segment_backend*)>;
  31. using value_pointer=void*;
  32. using const_value_pointer=const void*;
  33. using base_iterator=typename Model::base_iterator;
  34. using const_base_iterator=typename Model::const_base_iterator;
  35. template<typename T>
  36. using const_iterator=typename Model::template const_iterator<T>;
  37. using base_sentinel=typename Model::base_sentinel;
  38. using range=std::pair<base_iterator,base_sentinel>;
  39. segment_backend()=default;
  40. segment_backend(const segment_backend&)=delete;
  41. segment_backend& operator=(const segment_backend&)=delete;
  42. virtual ~segment_backend()=default;
  43. virtual segment_backend_unique_ptr copy()const=0;
  44. virtual segment_backend_unique_ptr copy(const Allocator&)const=0;
  45. virtual segment_backend_unique_ptr empty_copy(const Allocator&)const=0;
  46. virtual segment_backend_unique_ptr move(const Allocator&)=0;
  47. virtual bool equal(const segment_backend&)const=0;
  48. virtual Allocator get_allocator()const noexcept=0;
  49. virtual base_iterator begin()const noexcept=0;
  50. virtual base_iterator end()const noexcept=0;
  51. virtual bool empty()const noexcept=0;
  52. virtual std::size_t size()const noexcept=0;
  53. virtual std::size_t max_size()const noexcept=0;
  54. virtual std::size_t capacity()const noexcept=0;
  55. virtual base_sentinel reserve(std::size_t)=0;
  56. virtual base_sentinel shrink_to_fit()=0;
  57. virtual range push_back(const_value_pointer)=0;
  58. virtual range push_back_move(value_pointer)=0;
  59. virtual range insert(const_base_iterator,const_value_pointer)=0;
  60. virtual range insert_move(const_base_iterator,value_pointer)=0;
  61. virtual range erase(const_base_iterator)=0;
  62. virtual range erase(const_base_iterator,const_base_iterator)=0;
  63. virtual range erase_till_end(const_base_iterator)=0;
  64. virtual range erase_from_begin(const_base_iterator)=0;
  65. virtual base_sentinel clear()noexcept=0;
  66. };
  67. } /* namespace poly_collection::detail */
  68. } /* namespace poly_collection */
  69. } /* namespace boost */
  70. #endif