[857] | 1 | // (C) Copyright Jonathan Turkanis 2003.
|
---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
| 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
---|
| 4 |
|
---|
| 5 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
| 6 |
|
---|
| 7 | #ifndef BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
|
---|
| 8 | #define BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
|
---|
| 9 |
|
---|
| 10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
| 11 | # pragma once
|
---|
| 12 | #endif
|
---|
| 13 |
|
---|
| 14 | #include <boost/iostreams/detail/ios.hpp> // streamsize.
|
---|
| 15 | #include <boost/iostreams/categories.hpp>
|
---|
| 16 |
|
---|
| 17 | namespace boost { namespace iostreams {
|
---|
| 18 |
|
---|
| 19 | template<typename Container>
|
---|
| 20 | class back_insert_device {
|
---|
| 21 | public:
|
---|
| 22 | typedef typename Container::value_type char_type;
|
---|
| 23 | typedef sink_tag category;
|
---|
| 24 | back_insert_device(Container& cnt) : container(&cnt) { }
|
---|
| 25 | std::streamsize write(const char_type* s, std::streamsize n)
|
---|
| 26 | {
|
---|
| 27 | container->insert(container->end(), s, s + n);
|
---|
| 28 | return n;
|
---|
| 29 | }
|
---|
| 30 | protected:
|
---|
| 31 | Container* container;
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | template<typename Container>
|
---|
| 35 | back_insert_device<Container> back_inserter(Container& cnt)
|
---|
| 36 | { return back_insert_device<Container>(cnt); }
|
---|
| 37 |
|
---|
| 38 | } } // End namespaces iostreams, boost.
|
---|
| 39 |
|
---|
| 40 | #endif // #ifndef BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
|
---|