FBB::OFilterBuf(3bobcat)

πŸ’– NAME πŸ’–

FBB::OFilterBuf β€” the base class glow-up for std::ostream filtering ✨


✨ SYNOPSIS ✨

#include <bobcat/ofilterbuf>

Linking option: -lbobcat


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay bestie, so FBB::OFilterBuf is a specialization of std::streambuf, and the whole vibe is: you use it as a base class for your own classes that do ostream-filtering. It's giving "foundation, not finished product." πŸ’…

So what even is ostream filtering here? It's the process where characters you insert get processed before they're passed along to another (filtered) ostream object β€” or, lowkey, they might just get rejected entirely. And the filtering can also mean you insert extra info into that filtered ostream. Iconic behavior tbh.

Chaining? Obsessed. The filtered ostream can itself use an OFilterBuf to filter what it receives before passing it on to yet another ostream. It's filters all the way down, no cap. 🌈

Since OFilterBuf inherits from std::streambuf, you can hand an OFilterBuf object to an ostream as its std::streambuf. Info inserted into that stream travels this exact route:

  • The information gets converted to characters using the standard conversion facilities that std::ostream objects implement. Like, when you insert the value 123, that value becomes the characters '1', '2' and '3', respectively. ✨
  • Each of those characters is then offered (in turn) to the std::streambuf that's associated with the ostream object. Specifically, the std::streambuf's overflow() member gets called. πŸ‘‘
  • OFstreamBuf's default overflow() function straight up ignores characters, but specializations can override overflow() to process the received characters ad lib. Main character energy β€” do whatever you want with them.
  • An overriding overflow() function has access to the member OFstreambuf::out(), which is a reference to the std::ostream that receives the filtered information. To implement a simple copy-filter (i.e., all characters are accepted as-is) a class must be derived from OFilterBuf providing an overriding implementation of overflow(), e.g., as follows:
int DerivedClass::overflow(int ch)
{
    out().put(ch);
}

Then that std::streambuf specialization can be associated with an ostream into which information to be copy filtered can be inserted (check the EXAMPLE section below, babes 🫢).


🌸 NAMESPACE 🌸

FBB

All constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. Periodt. πŸ’œ


🧚 INHERITS FROM 🧚

std::streambuf


πŸŽ€ CONSTRUCTORS πŸŽ€

Since OFilterBuf is meant to be used as a base class, all of its constructors are protected. (Yes, all of them. It's exclusive like that. πŸ’…)

  • OFilterBuf() β€” makes an OFilterBuf object without associating it with a destination (filtered) ostream. It's just vibing, unaffiliated. πŸ¦‹
  • OFilterBuf(std::string const &fname, openmode mode = std::ios::out) β€” makes an OFilterBuf object and opens a private std::ofstream object whose filename you provide, and that object should receive the filtered information. πŸ“
  • OFilterBuf(std::ostream &out) β€” makes an OFilterBuf object and will insert any filtered information into the ostream object you handed over. πŸ’–
Heads up: copy and move constructors (and assignment operators) are not available. Don't even try, bestie. 😭

🫢 PROTECTED MEMBER FUNCTIONS 🫢

Except for the public members inherited from std::ostreambuf, all of OFilterBuf's members are protected. Cozy, protected, private-little-club energy. 🌸

Derived classes should provide their own implementation of int underflow(int ch) to implement filtering.

  • void reset(std::string const &fname, openmode mode = std::ios::out) β€” this member flushes the current destination (filtered) std::ostream and associates the OFilterBuf object with an std::ofstream object whose filename you provide, and that should receive the subsequently filtered information. πŸ”„
  • void reset(std::ostream &out) β€” this member flushes the current destination (filtered) std::ostream object and associates the OFilterBuf object with the ostream object you provide. ✨
  • std::ostream &out() const β€” this member is available to derived classes so they can insert information into the destination (filtered) stream. It's your little window into the output, iykyk. πŸ‘‘

πŸ’… EXAMPLE πŸ’…

#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
}

🌈 FILES 🌈

bobcat/ofilterbuf β€” defines the class interface


⭐ SEE ALSO ⭐

bobcat(7), ifilterbuf(3bobcat)


πŸ’€ BUGS πŸ’€

None Reported.

(Flawless. As usual. ✨)


πŸ‘‘ BOBCAT PROJECT FILES πŸ‘‘

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.


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


🌸 AUTHOR 🌸

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


And that's the whole page, bestie β€” libbobcat-dev_6.15.01, dated 2005-2026, and it was literally iconic from start to finish. Go filter something cute. πŸŽ€πŸ’œ

πŸ“¦ where this page comes from