size_holder.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/intrusive/detail/workaround.hpp>
  21. namespace boost {
  22. namespace intrusive {
  23. namespace detail {
  24. template<bool ConstantSize, class SizeType, class Tag = void>
  25. struct size_holder
  26. {
  27. static const bool constant_time_size = ConstantSize;
  28. typedef SizeType size_type;
  29. BOOST_INTRUSIVE_FORCEINLINE SizeType get_size() const
  30. { return size_; }
  31. BOOST_INTRUSIVE_FORCEINLINE void set_size(SizeType size)
  32. { size_ = size; }
  33. BOOST_INTRUSIVE_FORCEINLINE void decrement()
  34. { --size_; }
  35. BOOST_INTRUSIVE_FORCEINLINE void increment()
  36. { ++size_; }
  37. BOOST_INTRUSIVE_FORCEINLINE void increase(SizeType n)
  38. { size_ += n; }
  39. BOOST_INTRUSIVE_FORCEINLINE void decrease(SizeType n)
  40. { size_ -= n; }
  41. BOOST_INTRUSIVE_FORCEINLINE void swap(size_holder &other)
  42. { SizeType tmp(size_); size_ = other.size_; other.size_ = tmp; }
  43. SizeType size_;
  44. };
  45. template<class SizeType, class Tag>
  46. struct size_holder<false, SizeType, Tag>
  47. {
  48. static const bool constant_time_size = false;
  49. typedef SizeType size_type;
  50. BOOST_INTRUSIVE_FORCEINLINE size_type get_size() const
  51. { return 0; }
  52. BOOST_INTRUSIVE_FORCEINLINE void set_size(size_type)
  53. {}
  54. BOOST_INTRUSIVE_FORCEINLINE void decrement()
  55. {}
  56. BOOST_INTRUSIVE_FORCEINLINE void increment()
  57. {}
  58. BOOST_INTRUSIVE_FORCEINLINE void increase(SizeType)
  59. {}
  60. BOOST_INTRUSIVE_FORCEINLINE void decrease(SizeType)
  61. {}
  62. BOOST_INTRUSIVE_FORCEINLINE void swap(size_holder){}
  63. };
  64. } //namespace detail{
  65. } //namespace intrusive{
  66. } //namespace boost{
  67. #endif //BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP