FBB::OFilterStreambuf(3bobcat)

ostream filtering
(libbobcat-dev_4.08.03-x.tar.gz)

2005-2018

NAME

FBB::OFilterStreambuf - Base class for std::ostream filtering

SYNOPSIS

#include <bobcat/ofilterstreambuf>
Linking option: -lbobcat

DESCRIPTION

The FBB::OFilterStreambuf class is a specialization of the std::streambuf class and can be used as a base class for classes implementing ostream-filtering.

Ostream filtering is defined here as the process by which inserted characters are subject to processing before they are passed on to another (filtered) ostream object (or they may be rejected). The filtering may also result in inserting additional information into the filtered ostream.

Chaining of filters is also possible: the filtered ostream may itself use an OFilterStreambuf to filter its received information before passing it on to yet another ostream.

As OFilterStreambuf inherits from std::streambuf an OFilterStreambuf object can be used to provide an ostream object with a std::streambuf. Information inserted into such a stream travels the following route:

To implement a simple copy-filter (i.e., all characters are accepted as-is) a class must be derived from OFilterStreambuf providing an overriding implementation of overflow(), e.g., as follows:

    int DerivedClass::overflow(int ch)
    {
        out().put(ch);
    }
        
Next this std::streambuf specialization can be associated with an ostream into which information to be `copy filtered' can be inserted (cf. the EXAMPLE section below).

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

std::streambuf

CONSTRUCTORS

The class's destructor closes the destination (filtered) stream (cf. the description of close() below).

MEMBER FUNCTIONS

All members of std::ostreambuf are available, as FBB::OFilterStreambuf inherits from that class. In particular, derived classes should provide their own implementation of int underflow(int ch) to implement any non-trivial filtering.

PROTECTED MEMBER FUNCTION

EXAMPLE


    #include <iostream>
    #include <cctype>
    #include <bobcat/ofilterstreambuf>
    
    class NoDigits: public FBB::OFilterStreambuf
    {
        private:
            int overflow(int ch) override
            {
                if (not isdigit(ch))
                    out().put(ch);
                return ch;
            }
            int sync() override
            {
                out() << flush;
                return 0;
            }
    };
    
    using namespace FBB;
    using namespace std;
    
    int main()
    {
        NoDigits nod(cout);     // no digits to cout
        ostream out(&nod);
    
        out << in.rdbuf();      // rm digits from cin
        return 0;
    }
        

FILES

bobcat/ofilterstreambuf - defines the class interface

SEE ALSO

bobcat(7), ifilterstreambuf(3bobcat)

BUGS

None Reported.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).