FBB::OFilterBuf(3bobcat) | ostream filtering | FBB::OFilterBuf(3bobcat) |
FBB::OFilterBuf - Base class for std::ostream filtering
#include <bobcat/ofilterbuf>
Linking option: -lbobcat
The FBB::OFilterBuf 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 OFilterBuf to filter its received information before passing it on to yet another ostream.
As OFilterBuf inherits from std::streambuf an OFilterBuf object can be used to provide an ostream object with a std::streambuf. Information inserted into such a stream travels the following route:
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).
int DerivedClass::overflow(int ch)
{
out().put(ch);
}
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
std::streambuf
As OFilterBuf should be used as a base class all its constructors are protected.
Copy and move constructors (and assignment operators) are not available.
Except for the public members inherited from std::ostreambuf all of OFilterBuf’s members are protected.
Derived classes should provide their own implementation of int underflow(int ch) to implement filtering.
#include <iostream>
#include <cctype>
#include <bobcat/ofilterbuf>
struct NoDigits: public FBB::OFilterBuf
{
NoDigits(std::ostream &out)
:
OFilterBuf(out)
{}
private:
int overflow(int ch) override
{
if (not isdigit(ch))
out().put(ch);
return ch;
}
};
using namespace FBB;
using namespace std;
int main()
{
NoDigits nod(cout); // no digits to cout
ostream out(&nod);
out << cin.rdbuf(); // rm digits from cin
}
bobcat/ofilterbuf - defines the class interface
None Reported.
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
This is free software, distributed under the terms of the GNU General Public License (GPL).
Frank B. Brokken (f.b.brokken@rug.nl).
2005-2020 | libbobcat-dev_5.07.00 |