filtering_streambuf.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_FILTERING_STREAMBUF_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED
  8. #if defined(_MSC_VER)
  9. # pragma once
  10. #endif
  11. #include <exception>
  12. #include <memory> // allocator.
  13. #include <boost/iostreams/chain.hpp>
  14. #include <boost/iostreams/detail/access_control.hpp>
  15. #include <boost/iostreams/detail/char_traits.hpp>
  16. #include <boost/iostreams/detail/push.hpp>
  17. #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
  18. #include <boost/iostreams/detail/streambuf/chainbuf.hpp>
  19. #include <boost/mpl/if.hpp>
  20. namespace boost { namespace iostreams {
  21. //
  22. // Macro: BOOST_IOSTREAMS_DEFINE_FILTERBUF(name_, chain_type_, default_char_)
  23. // Description: Defines a template derived from std::basic_streambuf which uses
  24. // a chain to perform i/o. The template has the following parameters:
  25. // Ch - The character type.
  26. // Tr - The character traits type.
  27. // Alloc - The allocator type.
  28. // Access - Indicates accessibility of the chain interface; must be either
  29. // public_ or protected_; defaults to public_.
  30. //
  31. #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(name_, chain_type_, default_char_) \
  32. template< typename Mode, \
  33. typename Ch = default_char_, \
  34. typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
  35. typename Alloc = std::allocator<Ch>, \
  36. typename Access = public_ > \
  37. class name_ : public boost::iostreams::detail::chainbuf< \
  38. chain_type_<Mode, Ch, Tr, Alloc>, Mode, Access \
  39. > \
  40. { \
  41. public: \
  42. typedef Ch char_type; \
  43. struct category \
  44. : Mode, closable_tag, streambuf_tag \
  45. { }; \
  46. BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
  47. typedef Mode mode; \
  48. typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \
  49. name_() { } \
  50. BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
  51. ~name_() { if (this->is_complete()) this->BOOST_IOSTREAMS_PUBSYNC(); } \
  52. }; \
  53. /**/
  54. BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_streambuf, boost::iostreams::chain, char)
  55. BOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_wstreambuf, boost::iostreams::chain, wchar_t)
  56. typedef filtering_streambuf<input> filtering_istreambuf;
  57. typedef filtering_streambuf<output> filtering_ostreambuf;
  58. typedef filtering_wstreambuf<input> filtering_wistreambuf;
  59. typedef filtering_wstreambuf<output> filtering_wostreambuf;
  60. } } // End namespaces iostreams, boost.
  61. #endif // #ifndef BOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED