FBB::IFdBuf - Input stream buffer initialized by a file descriptor
Contents
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
The member xsgetn(char*dest,std::streamsizen) sets istream::good() to false when fewer bytes than n
were read using istream::read(). Also see xsgetn’s description.
Note that by default the provided file descriptors remain open. The complementary class ofdbuf(3bobcat)
by default closes the file descriptor.
Constructors
o IFdBuf():
This constructor initializes the streambuf, without associating it to a file descriptor, and
without using buffering. The member reset can be used subsequently to associate the object 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 not closed.
o IFdBuf(Modemode):
This constructor initializes the streambuf, without associating it to a file descriptor, and
without using buffering. The member reset can be used subsequently to associate the object 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 IFdBuf(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 is not closed.
o IFdBuf(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 reset member is called, the Mode argument determines whether the file
descriptor will be closed or will remain open.
o IFdBufSconstructors:
Use IFdBufS constructors corresponding to IFdBuf constructors to construct the corresponding
IFdBufS objects.
Copy and move constructors (and assignment operators) are not available.
Copyright
This is free software, distributed under the terms of the GNU General Public License (GPL).
Description
FBB::IFdBuf objects may be used as a std::streambuf of std::istream objects to allow extractions from a
file descriptor.
FBB::IFdBufS objects operate like FBB::IFdBuf objects but use FBB::Selector objects to check whether
information on the object’s file descriptor is available before reading information from the 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::IFdStreamBuf 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 <istream>
#include <iostream>
#include <bobcat/ifdbuf>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
{
// define a streambuf of 20 or argv[1] characters
IFdBuf buf{ STDIN_FILENO, argc == 1 ? 20 : stoul(argv[1]) };
istream in{ &buf };
cout << in.rdbuf();
}
Files
bobcat/ifdbuf - defines the FBB::IFdBuf class interface
bobcat/ifdbufs - defines the FBB::IFdBufS class interface
Inherits From
std::streambuf
Member Functions
All members of std::streambuf are available, as FBB::IFdBuf(S) inherits from this class.
o voidclose():
The file descriptor used by the IFdBuf(S) is closed, irrespective of the Mode that was specified
when the IFdBuf(S) object was constructed. Following close the IFdBuf(S) object can no longer be
used until one of its reset members has been called.
o intfd()const:
The file descriptor used by the IFdBuf(S) object is returned. If the OFdBuf is not associated
with a file descriptor -1 is returned.
o voidreset(intfd,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(intfd,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(S)
object is destroyed.
Name
FBB::IFdBuf - Input 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), ifdstream(3bobcat), ofdbuf(3bobcat), std::streambuf
Synopsis
#include<bobcat/ifdbuf> (when using FBB::IFdBuf#include<bobcat/ifdbufs> (when using FBB::IFdBufS
Linking option: -lbobcat