/Src/Dependencies/Boost/boost/iostreams/filtering_stream.hpp

http://hadesmem.googlecode.com/ · C++ Header · 166 lines · 125 code · 17 blank · 24 comment · 2 complexity · 17a07d5ef6395dc1f1ee4a93fbd7c7eb MD5 · raw file

  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2004-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_FILTER_STREAM_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
  8. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  9. # pragma once
  10. #endif
  11. #include <memory> // allocator.
  12. #include <boost/iostreams/detail/access_control.hpp>
  13. #include <boost/iostreams/detail/char_traits.hpp>
  14. #include <boost/iostreams/detail/iostream.hpp> // standard streams.
  15. #include <boost/iostreams/detail/push.hpp>
  16. #include <boost/iostreams/detail/select.hpp>
  17. #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
  18. #include <boost/iostreams/filtering_streambuf.hpp>
  19. #include <boost/mpl/and.hpp>
  20. #include <boost/mpl/bool.hpp>
  21. #include <boost/static_assert.hpp>
  22. #include <boost/type_traits/is_convertible.hpp>
  23. // Must come last.
  24. #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
  25. namespace boost { namespace iostreams {
  26. //--------------Definition of filtered_istream--------------------------------//
  27. namespace detail {
  28. template<typename Mode, typename Ch, typename Tr>
  29. struct filtering_stream_traits {
  30. typedef typename
  31. iostreams::select< // Disambiguation for Tru64
  32. mpl::and_<
  33. is_convertible<Mode, input>,
  34. is_convertible<Mode, output>
  35. >,
  36. BOOST_IOSTREAMS_BASIC_IOSTREAM(Ch, Tr),
  37. is_convertible<Mode, input>,
  38. BOOST_IOSTREAMS_BASIC_ISTREAM(Ch, Tr),
  39. else_,
  40. BOOST_IOSTREAMS_BASIC_OSTREAM(Ch, Tr)
  41. >::type stream_type;
  42. typedef typename
  43. iostreams::select< // Dismbiguation required for Tru64.
  44. mpl::and_<
  45. is_convertible<Mode, input>,
  46. is_convertible<Mode, output>
  47. >,
  48. iostream_tag,
  49. is_convertible<Mode, input>,
  50. istream_tag,
  51. else_,
  52. ostream_tag
  53. >::type stream_tag;
  54. };
  55. template<typename Chain, typename Access>
  56. class filtering_stream_base
  57. : public access_control<
  58. boost::iostreams::detail::chain_client<Chain>,
  59. Access
  60. >,
  61. public filtering_stream_traits<
  62. typename Chain::mode,
  63. typename Chain::char_type,
  64. typename Chain::traits_type
  65. >::stream_type
  66. {
  67. public:
  68. typedef Chain chain_type;
  69. typedef access_control<
  70. boost::iostreams::detail::chain_client<Chain>,
  71. Access
  72. > client_type;
  73. protected:
  74. typedef typename
  75. filtering_stream_traits<
  76. typename Chain::mode,
  77. typename Chain::char_type,
  78. typename Chain::traits_type
  79. >::stream_type stream_type;
  80. filtering_stream_base() : stream_type(0) { this->set_chain(&chain_); }
  81. private:
  82. void notify() { this->rdbuf(chain_.empty() ? 0 : &chain_.front()); }
  83. Chain chain_;
  84. };
  85. } // End namespace detail.
  86. //
  87. // Macro: BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_)
  88. // Description: Defines a template derived from std::basic_streambuf which uses
  89. // a chain to perform i/o. The template has the following parameters:
  90. // Mode - the i/o mode.
  91. // Ch - The character type.
  92. // Tr - The character traits type.
  93. // Alloc - The allocator type.
  94. // Access - Indicates accessibility of the chain interface; must be either
  95. // public_ or protected_; defaults to public_.
  96. // Macro parameters:
  97. // name_ - The name of the template to be defined.
  98. // chain_type_ - The name of the chain template.
  99. // default_char_ - The default value for the char template parameter.
  100. //
  101. #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_) \
  102. template< typename Mode, \
  103. typename Ch = default_char_, \
  104. typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
  105. typename Alloc = std::allocator<Ch>, \
  106. typename Access = public_ > \
  107. class name_ \
  108. : public boost::iostreams::detail::filtering_stream_base< \
  109. chain_type_<Mode, Ch, Tr, Alloc>, Access \
  110. > \
  111. { \
  112. public: \
  113. typedef Ch char_type; \
  114. struct category \
  115. : Mode, \
  116. closable_tag, \
  117. detail::filtering_stream_traits<Mode, Ch, Tr>::stream_tag \
  118. { }; \
  119. BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
  120. typedef Mode mode; \
  121. typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \
  122. name_() { } \
  123. BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
  124. ~name_() { \
  125. if (this->is_complete()) \
  126. this->rdbuf()->BOOST_IOSTREAMS_PUBSYNC(); \
  127. } \
  128. private: \
  129. typedef access_control< \
  130. boost::iostreams::detail::chain_client< \
  131. chain_type_<Mode, Ch, Tr, Alloc> \
  132. >, \
  133. Access \
  134. > client_type; \
  135. template<typename T> \
  136. void push_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
  137. { client_type::push(t BOOST_IOSTREAMS_PUSH_ARGS()); } \
  138. }; \
  139. /**/
  140. BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(filtering_stream, boost::iostreams::chain, char)
  141. BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(wfiltering_stream, boost::iostreams::chain, wchar_t)
  142. typedef filtering_stream<input> filtering_istream;
  143. typedef filtering_stream<output> filtering_ostream;
  144. typedef wfiltering_stream<input> filtering_wistream;
  145. typedef wfiltering_stream<output> filtering_wostream;
  146. //----------------------------------------------------------------------------//
  147. } } // End namespace iostreams, boost
  148. #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
  149. #endif // #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED