logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FBB::OFdBuf - Output stream buffer initialized by a file descriptor

Author

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

libbobcat-dev_6.07.01                               2005-2025                               FBB::OFdBuf(3bobcat)

Bobcat

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

Bobcat Project Files

       o      https://fbb-git.gitlab.io/bobcat/: gitlab project page;

       Debian Bobcat project files:

       o      libbobcat6: debian package containing the shared library, changelog and copyright note;

       o      libbobcat-dev:  debian package containing the static library, headers, manual pages, and developer
              info;

Bugs

       None reported

Constructors

       o      OFdBuf():
              This constructor initializes the streambuf, without associating  it  to  a  file  descriptor,  and
              without using buffering. The member reset can be used to associate the object later on with a file
              descriptor  and  optionally  a  buffer  size.   When  the  object is destroyed or if the mode-less
              overloaded version of the reset member is called, the file descriptor is closed.

       o      OFdBuf(Modemode):
              This constructor initializes the streambuf, without associating  it  to  a  file  descriptor,  and
              without using buffering. The member reset can be used to associate the object later on with a file
              descriptor  and  optionally  a  buffer  size.   When  the  object is destroyed or if the mode-less
              overloaded version of the member reset is called, the Mode argument determines  whether  the  file
              descriptor will be closed or will remain open.

       o      OFdBuf(intfd,size_tn=1):
              This  constructor initializes the streambuf, associating it to file descriptor fd, and an optional
              unget buffer size (by default having size 1).  When reset is called subsequently, or if the object
              is destroyed the provided file descriptor will be closed.

       o      OFdBuf(intfd,size_tn=1):
              This constructor initializes the streambuf, associating it to file descriptor fd, and an  optional
              unget  buffer  size  (by default having size 1).  When the object is destroyed or if the mode-less
              overloaded version of the member reset is called, the file descriptor will be closed.

       o      OFdBuf(intfd,Modemode,size_tn=1):
              This constructor initializes the streambuf, associating it to file descriptor fd, and an  optional
              unget  buffer  size  (by default having size 1).  When the object is destroyed or if the mode-less
              overloaded version of the member reset is called, the Mode argument determines  whether  the  file
              descriptor will be closed or will remain open.

       Copy and move constructors (and assignment operators) are not available.

Description

FBB::OFdBuf  objects  may  be used as a std::streambuf of std::ostream objects to allow insertions into a
       file descriptor.

       File descriptors are not defined within the context of C++, but they can be  used  on  operating  systems
       that support the concept. Realize that using file descriptors introduces operating system dependencies.

Enumeration

       The public enumeration Mode defined in the class FBB::OFdStreamBuf has the following values:

       o      CLOSE_FD, indicating that the file descriptor used by the object must be closed;

       o      KEEP_FD (the default) indicating that the file descriptor used by the object must not be closed.

Example

       #include <unistd.h>

       #include <ostream>
       #include <string>

       #include <bobcat/ofdbuf>

       using namespace std;
       using namespace FBB;

       int main(int argc, char **argv)
       {
                                  // define a streambuf of 20 or argv[1] characters
           OFdBuf buf{ STDOUT_FILENO, argc == 1 ? 20 : stoul(argv[1]) };

           ostream out{ &buf };

           out << "First line, just to start the insertions\n" <<
                   argv[0] << endl <<          // using an explicit flush
                   argc << "\n"
                   "a long line to end this multiple-insertions statement\n";
       }

Files

bobcat/ofdbuf - defines the class interface

Inherits From

std::streambuf

Manipulator

       o      FBB::eoi:
              The eoi manipulator can be inserted into the ostream instead of calling the OFdBuf::end member. It
              performs the same actions as the eoi member.   If  inserted  into  a  plain  std::ostream  nothing
              happens.

Member Functions

       All members of std::streambuf are available, as FBB::OFdBuf inherits from this class.

       o      voideoi():
              The file descriptor used by the OFdBuf is closed, irrespective of the Mode that was specified when
              the OFdBuf object was constructed. Following eoi the OFdBuf object can no longer be used until one
              of its reset members has been called. Instead of using this member the eoi manipulator can also be
              used.

       o      intfd()const:
              The file descriptor used by the OFdBuf object is returned.  If the OFdBuf is not associated with a
              file descriptor -1 is returned.

       o      voidreset(intxfd,size_tn=1):
              The  streambuf is (re)initialized, using file descriptor fd, and an optional unget buffer size (by
              default having size 1). When called repeatedly, the Mode specification used whem  the  object  was
              constructed determines whether the file descriptor will be closed or will remain open.

       o      voidreset(intxfd,Modemode,size_tn=1):
              The  streambuf  is  (re)initialized, using file descriptor fd, a file descriptor closing parameter
              and an optional unget buffer size (by default having size 1). Depending on the Mode  argument  the
              object’s  currently used file descriptor will be closed or will remain open when the IFdBuf object
              is destroyed.

       o      voidwarn(boolon):
              When on==true a warning is written to the standard error stream when its sync member returns -1.
              If warn is not explicitly called on==true is used.

Name

       FBB::OFdBuf - Output stream buffer initialized by a file descriptor

Namespace

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

See Also

bobcat(7), ifdbuf(3bobcat), ofdstream(3bobcat), std::streambuf

Synopsis

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

See Also