device_adapter.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Defines the class template boost::iostreams::detail::device_adapter,
  3. * a convenience base class for device adapters.
  4. *
  5. * File: boost/iostreams/detail/adapter/filter_adapter.hpp
  6. * Date: Mon Nov 26 14:35:48 MST 2007
  7. *
  8. * Copyright: 2007-2008 CodeRage, LLC
  9. * Author: Jonathan Turkanis
  10. * Contact: turkanis at coderage dot com
  11. *
  12. * Distributed under the Boost Software License, Version 1.0.(See accompanying
  13. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  14. *
  15. * See http://www.boost.org/libs/iostreams for documentation.
  16. */
  17. #ifndef BOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
  18. #define BOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
  19. #include <boost/iostreams/categories.hpp>
  20. #include <boost/iostreams/detail/call_traits.hpp>
  21. #include <boost/iostreams/detail/ios.hpp>
  22. #include <boost/iostreams/operations.hpp>
  23. #include <boost/iostreams/traits.hpp>
  24. #include <boost/static_assert.hpp>
  25. namespace boost { namespace iostreams { namespace detail {
  26. template<typename T>
  27. class device_adapter {
  28. private:
  29. typedef typename detail::value_type<T>::type value_type;
  30. typedef typename detail::param_type<T>::type param_type;
  31. public:
  32. explicit device_adapter(param_type t) : t_(t) { }
  33. T& component() { return t_; }
  34. void close()
  35. {
  36. detail::close_all(t_);
  37. }
  38. void close(BOOST_IOS::openmode which)
  39. {
  40. iostreams::close(t_, which);
  41. }
  42. bool flush()
  43. {
  44. return iostreams::flush(t_);
  45. }
  46. template<typename Locale> // Avoid dependency on <locale>
  47. void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
  48. std::streamsize optimal_buffer_size() const
  49. { return iostreams::optimal_buffer_size(t_); }
  50. public:
  51. value_type t_;
  52. };
  53. //----------------------------------------------------------------------------//
  54. } } } // End namespaces detail, iostreams, boost.
  55. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED