/Src/Dependencies/Boost/boost/iostreams/detail/adapter/mode_adapter.hpp

http://hadesmem.googlecode.com/ · C++ Header · 123 lines · 87 code · 25 blank · 11 comment · 1 complexity · 25eb392b8f1bacf5fe741ba585c13d40 MD5 · raw file

  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_DETAIL_MODE_ADAPTER_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
  8. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  9. # pragma once
  10. #endif
  11. // Contains the definition of the class template mode_adapter, which allows
  12. // a filter or device to function as if it has a different i/o mode than that
  13. // deduced by the metafunction mode_of.
  14. #include <boost/config.hpp> // BOOST_MSVC.
  15. #include <boost/detail/workaround.hpp>
  16. #include <boost/iostreams/categories.hpp>
  17. #include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
  18. #include <boost/iostreams/traits.hpp>
  19. #include <boost/iostreams/operations.hpp>
  20. #include <boost/mpl/if.hpp>
  21. namespace boost { namespace iostreams { namespace detail {
  22. template<typename Mode, typename T>
  23. class mode_adapter {
  24. private:
  25. struct empty_base { };
  26. public:
  27. typedef typename wrapped_type<T>::type component_type;
  28. typedef typename char_type_of<T>::type char_type;
  29. struct category
  30. : Mode,
  31. device_tag,
  32. mpl::if_<is_filter<T>, filter_tag, device_tag>,
  33. mpl::if_<is_filter<T>, multichar_tag, empty_base>,
  34. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  35. closable_tag, // VC6 can't see member close()!
  36. #endif
  37. localizable_tag
  38. { };
  39. explicit mode_adapter(const component_type& t) : t_(t) { }
  40. // Device member functions.
  41. std::streamsize read(char_type* s, std::streamsize n);
  42. std::streamsize write(const char_type* s, std::streamsize n);
  43. std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
  44. BOOST_IOS::openmode which =
  45. BOOST_IOS::in | BOOST_IOS::out );
  46. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  47. void close();
  48. void close(BOOST_IOS::openmode which);
  49. #endif
  50. // Filter member functions.
  51. template<typename Source>
  52. std::streamsize read(Source& src, char_type* s, std::streamsize n)
  53. { return iostreams::read(t_, src, s, n); }
  54. template<typename Sink>
  55. std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
  56. { return iostreams::write(t_, snk, s, n); }
  57. template<typename Device>
  58. std::streampos seek(Device& dev, stream_offset off, BOOST_IOS::seekdir way)
  59. { return iostreams::seek(t_, dev, off, way); }
  60. template<typename Device>
  61. std::streampos seek( Device& dev, stream_offset off,
  62. BOOST_IOS::seekdir way, BOOST_IOS::openmode which )
  63. { return iostreams::seek(t_, dev, off, way, which); }
  64. template<typename Device>
  65. void close(Device& dev)
  66. { detail::close_all(t_, dev); }
  67. template<typename Device>
  68. void close(Device& dev, BOOST_IOS::openmode which)
  69. { iostreams::close(t_, dev, which); }
  70. template<typename Locale>
  71. void imbue(const Locale& loc)
  72. { iostreams::imbue(t_, loc); }
  73. private:
  74. component_type t_;
  75. };
  76. //------------------Implementation of mode_adapter----------------------------//
  77. template<typename Mode, typename T>
  78. std::streamsize mode_adapter<Mode, T>::read
  79. (char_type* s, std::streamsize n)
  80. { return boost::iostreams::read(t_, s, n); }
  81. template<typename Mode, typename T>
  82. std::streamsize mode_adapter<Mode, T>::write
  83. (const char_type* s, std::streamsize n)
  84. { return boost::iostreams::write(t_, s, n); }
  85. template<typename Mode, typename T>
  86. std::streampos mode_adapter<Mode, T>::seek
  87. (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
  88. { return boost::iostreams::seek(t_, off, way, which); }
  89. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  90. template<typename Mode, typename T>
  91. void mode_adapter<Mode, T>::close()
  92. { detail::close_all(t_); }
  93. template<typename Mode, typename T>
  94. void mode_adapter<Mode, T>::close(BOOST_IOS::openmode which)
  95. { iostreams::close(t_, which); }
  96. #endif
  97. } } } // End namespaces detail, iostreams, boost.
  98. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//