back_inserter.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_BACK_INSERTER_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED
  8. #if defined(_MSC_VER)
  9. # pragma once
  10. #endif
  11. #include <boost/iostreams/detail/ios.hpp> // streamsize.
  12. #include <boost/iostreams/categories.hpp>
  13. namespace boost { namespace iostreams {
  14. template<typename Container>
  15. class back_insert_device {
  16. public:
  17. typedef typename Container::value_type char_type;
  18. typedef sink_tag category;
  19. back_insert_device(Container& cnt) : container(&cnt) { }
  20. std::streamsize write(const char_type* s, std::streamsize n)
  21. {
  22. container->insert(container->end(), s, s + n);
  23. return n;
  24. }
  25. protected:
  26. Container* container;
  27. };
  28. template<typename Container>
  29. back_insert_device<Container> back_inserter(Container& cnt)
  30. { return back_insert_device<Container>(cnt); }
  31. } } // End namespaces iostreams, boost.
  32. #endif // #ifndef BOOST_IOSTREAMS_BACK_INSERTER_HPP_INCLUDED