Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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 | |
| 6 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | #ifndef NDNBOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED |
| 9 | #define NDNBOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED |
| 10 | |
| 11 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 12 | # pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <exception> |
| 16 | #include <memory> // allocator. |
| 17 | #include <ndnboost/iostreams/chain.hpp> |
| 18 | #include <ndnboost/iostreams/detail/access_control.hpp> |
| 19 | #include <ndnboost/iostreams/detail/char_traits.hpp> |
| 20 | #include <ndnboost/iostreams/detail/push.hpp> |
| 21 | #include <ndnboost/iostreams/detail/streambuf.hpp> // pubsync. |
| 22 | #include <ndnboost/iostreams/detail/streambuf/chainbuf.hpp> |
| 23 | #include <ndnboost/mpl/if.hpp> |
| 24 | |
| 25 | namespace ndnboost { namespace iostreams { |
| 26 | |
| 27 | // |
| 28 | // Macro: NDNBOOST_IOSTREAMS_DEFINE_FILTERBUF(name_, chain_type_, default_char_) |
| 29 | // Description: Defines a template derived from std::basic_streambuf which uses |
| 30 | // a chain to perform i/o. The template has the following parameters: |
| 31 | // Ch - The character type. |
| 32 | // Tr - The character traits type. |
| 33 | // Alloc - The allocator type. |
| 34 | // Access - Indicates accessibility of the chain interface; must be either |
| 35 | // public_ or protected_; defaults to public_. |
| 36 | // |
| 37 | #define NDNBOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(name_, chain_type_, default_char_) \ |
| 38 | template< typename Mode, \ |
| 39 | typename Ch = default_char_, \ |
| 40 | typename Tr = NDNBOOST_IOSTREAMS_CHAR_TRAITS(Ch), \ |
| 41 | typename Alloc = std::allocator<Ch>, \ |
| 42 | typename Access = public_ > \ |
| 43 | class name_ : public ndnboost::iostreams::detail::chainbuf< \ |
| 44 | chain_type_<Mode, Ch, Tr, Alloc>, Mode, Access \ |
| 45 | > \ |
| 46 | { \ |
| 47 | public: \ |
| 48 | typedef Ch char_type; \ |
| 49 | struct category \ |
| 50 | : Mode, closable_tag, streambuf_tag \ |
| 51 | { }; \ |
| 52 | NDNBOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \ |
| 53 | typedef Mode mode; \ |
| 54 | typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \ |
| 55 | name_() { } \ |
| 56 | NDNBOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \ |
| 57 | ~name_() { if (this->is_complete()) this->NDNBOOST_IOSTREAMS_PUBSYNC(); } \ |
| 58 | }; \ |
| 59 | /**/ |
| 60 | NDNBOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_streambuf, ndnboost::iostreams::chain, char) |
| 61 | NDNBOOST_IOSTREAMS_DEFINE_FILTER_STREAMBUF(filtering_wstreambuf, ndnboost::iostreams::chain, wchar_t) |
| 62 | |
| 63 | typedef filtering_streambuf<input> filtering_istreambuf; |
| 64 | typedef filtering_streambuf<output> filtering_ostreambuf; |
| 65 | typedef filtering_wstreambuf<input> filtering_wistreambuf; |
| 66 | typedef filtering_wstreambuf<output> filtering_wostreambuf; |
| 67 | |
| 68 | } } // End namespaces iostreams, boost. |
| 69 | |
| 70 | #endif // #ifndef NDNBOOST_IOSTREAMS_FILTERING_STREAMBUF_HPP_INCLUDED |