FBB::IFilterBuf(3bobcat)
β¨ FBB::IFilterBuf π
okay bestie, buckle up, because we're diving into FBB::IFilterBuf β a filtering input stream buffer, and it lives in the bobcat manual (section 3, if you're keeping score π).
πΈ NAME πΈ
FBB::IFilterBuf β a filtering stream buffer that gets initialized by a std::istream object. it's giving "middleware for your streams," no cap β¨
π¦ SYNOPSIS π¦
#include <bobcat/ifilterbuf>
Linking option: -lbobcat
π DESCRIPTION π
so here's the vibe: FBB::IFilterBuf objects can be used as a std::streambuf for std::istream objects, and what they do is filter the information that those objects produce. literally the bouncer at the club door of your stream π
because IFilterBuf is a streambuf, its member underflow gets automatically called whenever reading operations are requested from the stream object that's using IFilterBuf as its streambuf. and if there are no chars currently available β like, srcBegin == srcEnd, check the description of the filter member below for the deets β then filter gets called, and it may store characters in a (local) buffer of at most maxSize characters (that's the IFilterBuf constructor, described below, iykyk). once this buffer has been filled, filter updates the *srcBegin and *srcEnd pointers so they point to, respectively, the location of the first character in the local buffer and beyond the location of the last character in the local buffer. slay π
fun fact: the class IFilterBuf was designed with the openSSL BIO in mind (cf. bio(3ssl)). and the way that the BIO concept was developed in the context of the C programming language means BIOs do not support C++ streams. BUT β and this is the iconic part β the concept of a filtering device is an attractive one, and it's offered by the FBB::IFilterBuf class. periodt β¨
on top of filtering, IFilterBuf offers flexible internal buffer management: derived classes can put characters back on the internal buffer until the beginning of the buffer has been reached, but they may then continue pushing characters onto the buffer until the buffer has reached its maximum size. this maximum size is defined by the constructor's maxSize parameter (see below).
and listen β IFilterBuf is an abstract base class. it's used via classes derived from IFilterBuf that implement its pure virtual load member (see below at PRIVATE VIRTUAL MEMBER FUNCTIONS). not me making you read the whole page π it's worth it tho.
π NAMESPACE π
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. π«Ά
π INHERITS FROM π
std::streambuf
β MEMBER FUNCTIONS β
all members of std::streambuf are available, because IFilterBuf inherits from this class. the whole inheritance tree ate and left no crumbs π
π PROTECTED CONSTRUCTOR π
IFilterBuf(size_t maxSize = 1000)β this constructor initializes the streambuf. while the streambuf is being used, its internally used buffer is gradually filled. it may be filled with up tomaxSizecharacters, but the actual number of characters stored in the buffer is determined by the memberfilter(see below) and by using the memberstreambuf::sputbackc.
copy and move constructors (and assignment operators) are not available. they said nope, not today π«
π§ PROTECTED MEMBER FUNCTION π§
void setBuffer()β this member initializes the base class's buffer pointers (i.e.,eback,gptr, andegptr) with the initial range of characters retrieved byfilter(see below).
derived classes do not have to call this member, but if they do, they should only call setBuffer once, from their constructors. once setBuffer has been called, the peek member of the std::istream that's available to IFilterBuf objects can be called to inspect the next available character, even if no other stream operation has as yet been performed. if it is not called by the derived class's constructor, then peek returns 0 until at least one character has been retrieved from the istream object.
π PRIVATE VIRTUAL MEMBER FUNCTIONS π
virtual bool filter(char const **srcBegin, char const **srcEnd) = 0β thefiltermember is declared as a pure virtual member: derived classes must overridefilterwith their own implementation.
derived class objects are responsible for obtaining information (in any amount) from the device with which they interact. this information is then passed on to the IFilterBuf via two pointers, pointing, respectively, to the first available character and beyond the last available character. the characters indicated by this range are subsequently transferred by the IFilterBuf object to its own buffer, from where they're then retrieved (or to where they can be pushed back) by the application. it's giving relay race πβοΈβ¨
the filter member allows implementations to filter and/or modify the information obtained by this member. the EXAMPLE section below provides an example filtering out a configurable set of characters from a provided std::istream. bobcat's classes ISymCryptStreambuf(3bobcat) and IBase64Buf(3bobcat) provide additional examples of classes derived from IFilterBuf.
the filter member should return false if no (more) information is available. it should return true if information is available, in which case *srcBegin and *srcEnd should be pointing to, respectively, the first character and beyond the last character made available by filter;
int pbackfail(int ch) overrideβ ifIFilterBuf's internally used buffer has reached its maximmum size thenEOFis returned. otherwise,chis inserted at the beginning of the internally used buffer, becoming the next character that's retrieved from the object's buffer;std::streamsize showmanyc() overrideβ the sum of the number of not yet processed characters in the internally used buffer and the number of not yet processed characters returned by the latestfiltercall is returned;int underflow() overrideβ once the internally used buffer is empty,filteris called to obtain a new series of filtered characters. iffilterreturnsfalse,underflowreturnsEOF. otherwise the series of characters returned byfilterare transferred to theIFilterBuf's internal buffer to be processed by thestd::istreamthat's initialized with theIFilterBufobject.
π₯ EXAMPLE π₯
here's a class, derived from IFilterBuf, filtering out a predefined set of characters. it's used twice to filter digits and vowels, illustrating chaining of IFilterBuf objects. chaining?? we love to see it π
#include <iostream>
#include <fstream>
#include <istream>
#include <string>
#include <bobcat/ifilterbuf>
using namespace std;
using namespace FBB;
class CharFilterStreambuf: public IFilterBuf
{
istream &d_in; // stream to read from
string d_rmChars; // chars to rm
string d_buffer; // locally buffered chars
size_t const d_maxSize = 100;
public:
CharFilterStreambuf(istream &in, string const &rmChars);
private:
bool filter(char const **srcBegin,
char const **srcEnd) override;
};
CharFilterStreambuf::CharFilterStreambuf(istream &in,
string const &rmChars)
:
d_in(in),
d_rmChars(rmChars)
{
setBuffer(); // required if peek() must return the 1st
} // available character right from the start
bool CharFilterStreambuf::filter(char const **srcBegin,
char const **srcEnd)
{
d_buffer.clear();
while (d_buffer.size() != d_maxSize)
{
char ch;
if (not d_in.get(ch))
break;
if (d_rmChars.find(ch) != string::npos) // found char to rm
continue;
d_buffer.push_back(ch);
}
if (d_buffer.empty())
return false;
*srcBegin = d_buffer.data();
*srcEnd = d_buffer.data() + d_buffer.size();
return true;
}
int main(int argc, char **argv)
{
if (argc == 1)
{
cout << "arg[1]: file to process, arg[2]: processed file\n";
return 0;
}
ifstream in{ argv[1] };
CharFilterStreambuf buf1(in, "1234567890");
istream in1(&buf1);
CharFilterStreambuf buf2(in1, "AEIOUaeiou");
istream in2(&buf2);
ofstream out{ argv[2] };
out << in2.rdbuf();
}
π FILES π
bobcat/ifdbuf β defines the class interface
π SEE ALSO π
bobcat(7), isymcryptstreambuf(3bobcat), ibase64buf(3bobcat), ofilterbuf(3bobcat). std::streambuf
π BUGS π
None reported. (a clean page?? we love a bug-free era π«Ά)
π BOBCAT PROJECT FILES π
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ. iconic naming tbh π
π 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).
okay that's the whole page bestie, you're officially a IFilterBuf girlie now π
β¨
this was libbobcat-dev_6.15.01, dated 2005-2026, and yes it's still FBB::IFilterBuf(3bobcat) β go filter something, ily π«Άπ
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms