FBB::OFoldStream(3bobcat)

πŸ’– FBB::OFoldStream β€” the fold-long-lines queen πŸ’–

okay bestie, welcome to the bobcat manual page for FBB::OFoldStream(3bobcat) β€” she folds long lines and she does it beautifully. Let's get into it ✨


🌸 NAME 🌸

FBB::OFoldStream β€” Folds long lines. that's it, that's the job, and she eats every time πŸ’…


✨ SYNOPSIS ✨

#include <bobcat/ofoldstream>

Linking option: -lbobcat


πŸ¦‹ DESCRIPTION πŸ¦‹

FBB::OFoldStream folds long lines written to it. She writes the (folded) lines to a second ostream β€” one that's either already used by the OFoldStream object, or opened by it. no cap 🫢

OFoldStream objects never fold lines in the middle of a series of non-blank characters. She will always break a line at white space characters. the resulting lines always show up to the right of a configurable left margin and to the left of a configurable right margin. there is a somewhat pathological exception to this: if a word is too long to fit between the margins, then the word will exceed the right hand margin. she said "not my problem" 😭

The indentation used for the left margins is configurable to either blanks (the default) or tabs. when tabs are used, the width of a tab character is configurable, using a default of 8 positions in the destination stream.

OFoldStream is implemented as a wrapper class around std::ostream and FBB::OFoldBuf. a fuller description of the folding process lives over in the ofoldbuf(3bobcat) man page β€” go read her too, she's iconic πŸ’œ


πŸ‘‘ NAMESPACE πŸ‘‘

FBB

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


🌈 INHERITS FROM 🌈

std::ostream, (and privately from FBB::OFoldBuf)


πŸŽ€ ENUMERATION πŸŽ€

The enumeration TabsOrBlanks is used to select tabs or blanks when writing the indentation. the default is blanks. when tabs are selected, the display width of tab characters can be configured as well (using the default of 8 positions for each tab-character). this enum has two values:

  • BLANKS: the default, indicating that the left margin is specified and written as a number of blanks;
  • TABS: indicating that the left margin is specified and written as a number of tab-characters.

The enumeration TrailingBlanks is used to configure the OFoldStream object with respect to any trailing blanks that may appear on the final line. it's the same enumeration type as used with OFoldBuf (cf. ofoldbuf(3bobcat)), and it has two values:

  • IGNORE_TRAILING_BLANKS: this indicates that trailing blanks appearing at the final line, if it is not terminated by a newline, should not be written to the destination std::ostream. this is the default used by OFoldStream objects.
  • KEEP_TRAILING_BLANKS: this indicates that trailing blanks at the final line, if it is not terminated by a newline, should be written to the destination std::ostream.

πŸ’… CONSTRUCTORS πŸ’…

  • OFoldStream() β€” this constructor initializes an OFoldStream object but does not associate it with a destination stream. it uses the values 0, 80, BLANKS, and IGNORE_TRAILING_BLANKS for, resp., its left margin, right margin, left-margin characters and TrailingBlanks handling mode.
  • OFoldStream(char const *fname, size_t leftIndent = 0, size_t rightMargin = 80, TabsOrBlanks tob = BLANKS, TrailingBlanks tb = IGNORE_TRAILING_BLANKS) β€” this constructor initializes an OFoldStream object and opens (using std::ios::out) the destination stream using the name specified as its fname argument.
  • OFoldStream(std::ostream &stream, size_t leftIndent = 0, size_t rightMargin = 80, TabsOrBlanks tob = BLANKS, TrailingBlanks tb = IGNORE_TRAILING_BLANKS) β€” this constructor initializes an OFoldStream object and uses the std::ostream stream as its destination stream.

the destructor writes any buffered information to the destination stream and will then flush the destination stream. she cleans up after herself, always 🧚

copy and move constructors (and assignment operators) are NOT available. don't even try it bestie πŸ™ˆ

πŸ“ MEMBER FUNCTIONS πŸ“

All members of std::ostream are available, since FBB::OFoldStream inherits from this class.

  • void close() β€” this member flushes any pending information to the destination stream and then closes the destination stream.
  • void open(char const *fname, openmode mode = std::ios::out) β€” this member associates the OFilterStream object with an std::ofstream object whose filename is provided, and that should receive the folded information.
  • void open(std::ostream &out) β€” this member associates the OFilterStream object with the provided out ostream object.
  • void setMargins(size_t leftMargin, size_t rightMargin) β€” this member can be used to modify the left- and right folding margins. note that the left margin may also be modified using the FBB::lm and FBB::mlm manipulators πŸ‘€
  • void setTrailingBlanks(TrailingBlanks tb) β€” this member can be used to modify the currently used TrailingBlanks parameter.
  • void useBlanks() β€” this member can be used to select blanks to be used when inserting left margins.
  • void useTabs(size_t tabWidth = 8) β€” this member can be used to select tab-characters to be used when inserting left margins. the second parameter is used to specify the display width of a tab-character.

⭐ STATIC MEMBER FUNCTIONS ⭐

  • size_t leftMargin(std::ostream const &os) β€” this member returns the current left margin setting of the OFoldStream object passed to it as its argument. the member defines a std::ostream parameter since in many cases the OFoldStream object will be used in functions that themselves define std::ostream parameters. internally, the std::ostream's std::streambuf is down cast to an OFoldBuf and an FBB::Exception exception is thrown if that cast fails. rude, but fair.
  • size_t rightMargin(std::ostream const &os) β€” this member returns the current right margin setting of the OFoldStream object passed to it as its argument. the member's parameter is down cast in the same way as leftMargin()'s argument: an FBB::Exception exception is thrown if that cast fails.

πŸ”₯ EXAMPLE πŸ”₯

#include <iostream>
#include <string>
#include <bobcat/ofoldstream>

using namespace std;
using namespace FBB;

void margins(ostream &out)
{
    cout << OFoldStream::leftMargin(out) << ", " <<
            OFoldStream::rightMargin(out) << endl;
}

int main()
{
    OFoldStream out(cout, 4, 40);

    out << lm(4);

    string line;
    while (getline(cin, line))
        out << line << ’\n’;

    margins(out);
}

πŸŽ€ FILES πŸŽ€

bobcat/ofoldstream β€” defines the class interface


🌸 SEE ALSO 🌸

bobcat(7), lm(3bobcat), mlm(3bobcat), ofoldbuf(3bobcat)


πŸ’€ BUGS πŸ’€

None Reported. she's flawless, your honor ✨


🫢 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’. iykyk πŸ’œ


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


πŸ¦‹ AUTHOR πŸ¦‹

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


<div align="center">and that's the whole page bestie!! πŸ’– this gem shipped as libbobcat-dev_6.15.01, dated 2005-2026, and she is β€” and always will be β€” FBB::OFoldStream(3bobcat). now go fold some lines, you absolute main character πŸ«Άβœ¨πŸŽ€</div>

πŸ“¦ where this page comes from