optimal_buffer_size.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #ifndef BOOST_IOSTREAMS_OPTIMAL_BUFFER_SIZE_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_OPTIMAL_BUFFER_SIZE_HPP_INCLUDED
  8. #if defined(_MSC_VER)
  9. # pragma once
  10. #endif
  11. #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
  12. #include <boost/detail/workaround.hpp>
  13. #include <boost/iostreams/constants.hpp> // constants.
  14. #include <boost/iostreams/detail/dispatch.hpp>
  15. #include <boost/iostreams/detail/wrap_unwrap.hpp>
  16. #include <boost/iostreams/operations_fwd.hpp>
  17. #include <boost/mpl/if.hpp>
  18. // Must come last.
  19. #include <boost/iostreams/detail/config/disable_warnings.hpp>
  20. namespace boost { namespace iostreams {
  21. namespace detail {
  22. template<typename T>
  23. struct optimal_buffer_size_impl;
  24. } // End namespace detail.
  25. template<typename T>
  26. std::streamsize optimal_buffer_size(const T& t)
  27. {
  28. typedef detail::optimal_buffer_size_impl<T> impl;
  29. return impl::optimal_buffer_size(detail::unwrap(t));
  30. }
  31. namespace detail {
  32. //------------------Definition of optimal_buffer_size_impl--------------------//
  33. template<typename T>
  34. struct optimal_buffer_size_impl
  35. : mpl::if_<
  36. is_custom<T>,
  37. operations<T>,
  38. optimal_buffer_size_impl<
  39. BOOST_DEDUCED_TYPENAME
  40. dispatch<
  41. T, optimally_buffered_tag, device_tag, filter_tag
  42. >::type
  43. >
  44. >::type
  45. { };
  46. template<>
  47. struct optimal_buffer_size_impl<optimally_buffered_tag> {
  48. template<typename T>
  49. static std::streamsize optimal_buffer_size(const T& t)
  50. { return t.optimal_buffer_size(); }
  51. };
  52. template<>
  53. struct optimal_buffer_size_impl<device_tag> {
  54. template<typename T>
  55. static std::streamsize optimal_buffer_size(const T&)
  56. { return default_device_buffer_size; }
  57. };
  58. template<>
  59. struct optimal_buffer_size_impl<filter_tag> {
  60. template<typename T>
  61. static std::streamsize optimal_buffer_size(const T&)
  62. { return default_filter_buffer_size; }
  63. };
  64. } // End namespace detail.
  65. } } // End namespaces iostreams, boost.
  66. #include <boost/iostreams/detail/config/enable_warnings.hpp>
  67. #endif // #ifndef BOOST_IOSTREAMS_OPTIMAL_BUFFER_SIZE_HPP_INCLUDED