dummy_test_allocator.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP
  11. #define BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP
  12. #if defined (_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #include <boost/interprocess/detail/workaround.hpp>
  17. #include <boost/interprocess/interprocess_fwd.hpp>
  18. #include <boost/interprocess/containers/allocation_type.hpp>
  19. #include <boost/interprocess/detail/utilities.hpp>
  20. #include <boost/interprocess/containers/version_type.hpp>
  21. #include <boost/interprocess/exceptions.hpp>
  22. #include <cstddef>
  23. //!\file
  24. //!Describes an allocator to test expand capabilities
  25. namespace boost {
  26. namespace interprocess {
  27. namespace test {
  28. //This allocator just allows two allocations. The first one will return
  29. //mp_buffer + m_offset configured in the constructor. The second one
  30. //will return mp_buffer.
  31. template<class T>
  32. class dummy_test_allocator
  33. {
  34. private:
  35. typedef dummy_test_allocator<T> self_t;
  36. typedef void * aux_pointer_t;
  37. typedef const void * cvoid_ptr;
  38. template<class T2>
  39. dummy_test_allocator& operator=(const dummy_test_allocator<T2>&);
  40. dummy_test_allocator& operator=(const dummy_test_allocator&);
  41. public:
  42. typedef T value_type;
  43. typedef T * pointer;
  44. typedef const T * const_pointer;
  45. typedef typename ipcdetail::add_reference
  46. <value_type>::type reference;
  47. typedef typename ipcdetail::add_reference
  48. <const value_type>::type const_reference;
  49. typedef std::size_t size_type;
  50. typedef std::ptrdiff_t difference_type;
  51. // typedef boost::interprocess::version_type<dummy_test_allocator, 2> version;
  52. template<class T2>
  53. struct rebind
  54. { typedef dummy_test_allocator<T2> other; };
  55. //!Default constructor. Never throws
  56. dummy_test_allocator()
  57. {}
  58. //!Constructor from other dummy_test_allocator. Never throws
  59. dummy_test_allocator(const dummy_test_allocator &)
  60. {}
  61. //!Constructor from related dummy_test_allocator. Never throws
  62. template<class T2>
  63. dummy_test_allocator(const dummy_test_allocator<T2> &)
  64. {}
  65. pointer address(reference value)
  66. { return pointer(addressof(value)); }
  67. const_pointer address(const_reference value) const
  68. { return const_pointer(addressof(value)); }
  69. pointer allocate(size_type, cvoid_ptr = 0)
  70. { return 0; }
  71. void deallocate(const pointer &, size_type)
  72. { }
  73. template<class Convertible>
  74. void construct(pointer, const Convertible &)
  75. {}
  76. void destroy(pointer)
  77. {}
  78. size_type max_size() const
  79. { return 0; }
  80. friend void swap(self_t &, self_t &)
  81. {}
  82. //Experimental version 2 dummy_test_allocator functions
  83. pointer allocation_command(boost::interprocess::allocation_type,
  84. size_type, size_type &, pointer &)
  85. { return pointer(); }
  86. //!Returns maximum the number of objects the previously allocated memory
  87. //!pointed by p can hold.
  88. size_type size(const pointer &) const
  89. { return 0; }
  90. //!Allocates just one object. Memory allocated with this function
  91. //!must be deallocated only with deallocate_one().
  92. //!Throws boost::interprocess::bad_alloc if there is no enough memory
  93. pointer allocate_one()
  94. { return pointer(); }
  95. //!Deallocates memory previously allocated with allocate_one().
  96. //!You should never use deallocate_one to deallocate memory allocated
  97. //!with other functions different from allocate_one(). Never throws
  98. void deallocate_one(const pointer &)
  99. {}
  100. };
  101. //!Equality test for same type of dummy_test_allocator
  102. template<class T> inline
  103. bool operator==(const dummy_test_allocator<T> &,
  104. const dummy_test_allocator<T> &)
  105. { return false; }
  106. //!Inequality test for same type of dummy_test_allocator
  107. template<class T> inline
  108. bool operator!=(const dummy_test_allocator<T> &,
  109. const dummy_test_allocator<T> &)
  110. { return true; }
  111. } //namespace test {
  112. } //namespace interprocess {
  113. } //namespace boost {
  114. #include <boost/interprocess/detail/config_end.hpp>
  115. #endif //BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP