basic_line_filter
The class template basic_line_filter
is a DualUseFilter for use as a base class by Filters which filter a character sequence one line at a time. Derived classes override the private
virtual
function do_filter
, which takes a line of unfiltered text as argument returns the result of filtering the line.
<boost/iostreams/filter/line.hpp>
namespace boost { namespace iostreams { template<typename Ch, typename Alloc = std::allocator<Ch> > class basic_line_filter { public: typedef Ch char_type; typedef std::basic_string< Ch, std::char_traits<char_type>, Alloc > string_type; typedef [implementation-defined] category; protected: basic_line_filter(); public: virtual ~basic_line_filter(); private: virtual string_type do_filter(const string_type& line) = 0; }; typedef basic_line_filter<char> line_filter; typedef basic_line_filter<wchar_t> wline_filter; } } // End namespace boost::io
Ch | - | The character type |
Alloc | - | A standard library allocator type ([ISO], 20.1.5), used to allocate a character buffer |
line_filter::do_filter
virtual string_type do_filter(const string_type& line) = 0;
The argument line
represents a single line of unfiltered text, not including any terminal newline character. Returns the result of filtering line
.
The following example shows a line_filter
which counts the number of lines which exceed a given length.
#include <boost/iostreams/filter/line.hpp> namespace io = boost::iostreams; class long_line_counter : public io::line_filter { public explicit long_line_counter(int max_length = 80) : max_(max_length), count_(0) { } int count() const { return count_; } private: std::string do_filter(const std::string& line) { if (line.size() > max_) ++count_; } int max_; int count_; };
© Copyright 2008 CodeRage, LLC
© Copyright 2004-2007 Jonathan Turkanis
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)