imbue.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_IMBUE_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_IMBUE_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/detail/dispatch.hpp>
  14. #include <boost/iostreams/detail/streambuf.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. // Implementation templates for simulated tag dispatch.
  23. template<typename T>
  24. struct imbue_impl;
  25. } // End namespace detail.
  26. template<typename T, typename Locale>
  27. void imbue(T& t, const Locale& loc)
  28. { detail::imbue_impl<T>::imbue(detail::unwrap(t), loc); }
  29. namespace detail {
  30. //------------------Definition of imbue_impl----------------------------------//
  31. template<typename T>
  32. struct imbue_impl
  33. : mpl::if_<
  34. is_custom<T>,
  35. operations<T>,
  36. imbue_impl<
  37. BOOST_DEDUCED_TYPENAME
  38. dispatch<
  39. T, streambuf_tag, localizable_tag, any_tag
  40. >::type
  41. >
  42. >::type
  43. { };
  44. template<>
  45. struct imbue_impl<any_tag> {
  46. template<typename T, typename Locale>
  47. static void imbue(T&, const Locale&) { }
  48. };
  49. template<>
  50. struct imbue_impl<streambuf_tag> {
  51. template<typename T, typename Locale>
  52. static void imbue(T& t, const Locale& loc) { t.pubimbue(loc); }
  53. };
  54. template<>
  55. struct imbue_impl<localizable_tag> {
  56. template<typename T, typename Locale>
  57. static void imbue(T& t, const Locale& loc) { t.imbue(loc); }
  58. };
  59. } // End namespace detail.
  60. } } // End namespaces iostreams, boost.
  61. #include <boost/iostreams/detail/config/enable_warnings.hpp>
  62. #endif // #ifndef BOOST_IOSTREAMS_IMBUE_HPP_INCLUDED