I've written a really simple aggregate_filter that runs the world
famous and highly secret ROT13 encryption. This filter works fine when
I use a file_sink and file_source. But I really just want to run this
on a bunch of string buffers. Unfortunately it does not work, the
destination string is always empty. Does anyone understand why?
Here's the code, tested against Boost 1.34.1 on OS X 10.5.1:
#include <iostream>
#include <memory>
#include <string>
#include
#include
#include
#include
template< typename Ch, typename Alloc = std::allocator<Ch> >
class basic_rot13_filter : public boost::iostreams::aggregate_filter
{
private:
typedef boost::iostreams::aggregate_filter
base_type;
public:
typedef typename base_type::char_type char_type;
typedef typename base_type::category category;
typedef std::basic_string<Ch> string_type;
public:
basic_rot13_filter()
{
}
private:
typedef typename base_type::vector_type vector_type;
void do_filter(const vector_type& src, vector_type& dest)
{
for (size_t i = 0; i < src.size(); ++i) {
dest.push_back(src[i] + 13);
}
}
};
typedef basic_rot13_filter<char> rot13_filter;
typedef basic_rot13_filter wrot13_filter;
int main()
{
std::string src = "SourceText";
boost::iostreams::filtering_istream in;
in.push(boost::make_iterator_range(src));
std::string dst;
boost::iostreams::filtering_ostream out;
out.push(rot13_filter());
out.push(boost::iostreams::back_inserter(dst));
boost::iostreams::copy(in, out);
std::cout << dst << std::endl;
return 0;
}