Boost logo

Boost Users :

Subject: [Boost-users] boost::iostreams filter question
From: plarroy (plarroy_at_[hidden])
Date: 2009-05-21 02:34:29


Hello, I have implemented a test SymmetricFilter and works ok.

Although to my suprise I had to declare two different methods of filter
differing only in the signature by the const char*& src_end.

If I supress either of those i get a compile time error.

Perhaps it is because it's being used as a bidirectional filter? as the
two signatures might be the ones in boost/iostreams/filter/symmetric.hpp
read and write?

Pedro.
Regards.

My code:

class smashing_filter_impl {
public:
    typedef char char_type;
    smashing_filter_impl() { }
    bool filter(const char*& src_begin, char*& src_end, char*&
dst_begin, char*& dst_end, bool flush)
    {
        bool eof = false;
        ptrdiff_t src_sz = src_end - src_begin;
        if( src_sz <= 0 )
            return false;
        while(src_begin < src_end && dst_begin < dst_end)
            *dst_begin++ = tolower(*src_begin++);
        return true;
    }
    bool filter(const char*& src_begin, const char*& src_end, char*&
dst_begin, char*& dst_end, bool flush)
    {
        bool eof = false;
        ptrdiff_t src_sz = src_end - src_begin;
        if( src_sz <= 0 )
            return false;
        while(src_begin < src_end && dst_begin < dst_end)
            *dst_begin++ = tolower(*src_begin++);
        return true;
    }

    void close() {}
private:

};

struct smashing_filter : symmetric_filter<smashing_filter_impl>
{
public:
    typedef symmetric_filter<smashing_filter_impl> base_type;
    smashing_filter() : base_type(default_device_buffer_size) {
    }

};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net