multistreambuf3bobcat
Selectively writes multiple streams
Usage
#include <bobcat/multistreambuf>
Linking option: -lbobcat
Overview
The FBB::MultiStreambuf class is a specialization of std::streambuf. It can be used to write selectively to multiple std::ostreams. Each std::ostream that is associated with a MultiStreambuf is given a mode-tag indicating whether the stream should always be used when information is inserted into the MultiStreambuf, just once, or not at all. Each of the stream’s mode-tags may be set to any of the defined tag-values.
When the address of a MultiStreambuf is used to initialize a std::ostream the constructed std::ostream becomes an output-multiplexer: by inserting information into the std::ostream object, all std::ostream objects added to its MultiStreambuf buffer which have an active mode receive that information.
An MultiStreambuf object should be outlived by all active streams that are associated with it.
MultiStreambuf objects refer to std::ostreams which are passed to it, and not to their std::streambufs. So it is possible to change these std::ostream’s std::streambufs without reinstalling the std::ostreams themselves.
No assumptions should be made about the order in which the std::ostream objects that are associated with the MultiStreambuf objects are visited when information is inserted.
Namespace
FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.
Inherits from
std::streambuf
Enumeration
In the Mode enumeration the following values are defined:
- o
-
OFF:
A std::ostream having this mode will not be used when information is inserted into aMultiStreambuf
- o
-
ON:
A std::ostream having this mode will be used when information is inserted into aMultiStreambuf
- o
-
ONCE:
A std::ostream having this mode will be used once, until the next flushing operation, when information is inserted into anMultiStreambuf
- o
-
RESET:
A std::ostream having this mode will not be used when information is inserted into aMultiStreambuf. At a flush operation all ONCE modes will be set to RESET
- o
-
ALL:
This mode is used in combination with the member remove to remove all std::ostream elements matching a specified std::ostream argument.
Types
The following subtypes are defined in the class FBB:MultiStreambuf:
o
|
|
|---|---|
o
|
|
Nested class
The class MultiStreambuf::stream is defined as a nested class of MultiStreambuf. It offers the following constructor and public members:
- o
-
stream(std::ostream &os, Mode mode = ON):
The constructor stores a std::ostream object, and associates aModevalue with it.
- o
-
void setMode(Mode mode):
This member is used to redefine thestream’sModevalue.
- o
-
void mode() const:
This member returns thestream’sModevalue.
- o
-
operator std::ostream &():
This member returns thestream’s std::ostream.
Constructors
- o
-
MultiStreambuf():
The default constructor creates aMultiStreambufobject which contains no associated std::ostream objects.
- o
-
MultiStreambuf(std::ostream &os, Mode mode = ON):
This constructor creates aMultiStreambufobject which is immediately associated with the std::ostream specified as its first argument.
- o
-
MultiStreambuf(std::vector<MultiStreambuf::stream> const &osvector):
This constructor creates aMultiStreambufobject which is immediately associated with all std::ostream objects that are stored in theMultiStreambuf::streamelements of the specified vector. The copy constructor is available.
Member functions
All members of std::ostringstream and std::exception are available, as MultiStreambuf inherits from these classes.
- o
-
iterator begin():
This member returns an iterator to the firststreamelement that is stored in aMultiStreambufobject.
- o
-
const_iterator begin():
This member returns an iterator to the first (unmodifiable)streamelement that is stored in aMultiStreambufobject.
- o
-
iterator end():
This member returns an iterator pointing beyond the laststreamelement that is stored in aMultiStreambufobject.
- o
-
const_iterator end():
This member returns an iterator pointing beyond the last (unmodifiable)streamelement that is stored in aMultiStreambufobject.
- o
-
void insert(std::ostream &os, Mode mode = ON):
This member adds the specified std::ostream using the specifiedModeto the current set ofstreamobjects. Note that if called multiple times for identical std::ostreams these objects are inserted multiple times as well.
- o
-
void insert(std::vector<stream> const &os):
This member adds allstreamobjects stored in theosvector to the current set ofstreamobjects.
- o
-
bool remove(std::ostream &os, Mode mode = ONCE):
If os is stored in theMultiStreambufit is removed, and true is returned. If mode ALL is specified all os objects that were stored in theMultiStreambufobject are removed (and true is returned). If the os object was not stored false is returned. To determine whether os has been stored in theMultiStreambufobject its address is compared to the addresses of the std::ostream objects that are stored inside theMultiStreambufobject: the object(s) having addresses &os is (are) removed.
- o
-
void void setOnce():
This member will reset all the RESETModevalues of the storedstreamobjects to ONCE.
- o
-
size_t size() const:
The number of streams currently serviced by theMultiStreambufobject is returned.
Protected member function
The member listed in this section implements the tasks of the comparably named virtual function in the class’s private interface. This separates the redefinable interface from the user-interface. The class MultiStreamBuf can, in accordance with Liskov’s Substitution Principle, be used as a std:streambuf; but it also offers a facility for classes deriving from MultiStreamBuf. This facility is listed here.
- o
-
int pSync():
The contents of theMultiStreamBuf’s internal buffer is written to each of the std::ostream objects to which theMultiStreamBufobject has access.
Examples
#include <iostream>
#include <fstream>
#include <bobcat/multistreambuf>
using namespace std;
using namespace FBB;
int main()
{
MultiStreambuf msb(cout);
ostream os(&msb);
ofstream out("out");
msb.insert(out, MultiStreambuf::ONCE);
os << "This is on cout and out\n"
"This is on cout only\n";
msb.setOnce();
os << "This is on cout and out\n"
"This is on cout only\n";
}
Files
bobcat/multistreambuf - defines the class interface
Distribution files
- o
-
bobcat_4.08.06-x.dsc: detached signature;
- o
-
bobcat_4.08.06-x.tar.gz: source archive;
- o
-
bobcat_4.08.06-x_i386.changes: change log;
- o
-
libbobcat1_4.08.06-x_*.deb: debian package holding the libraries;
- o
-
libbobcat1-dev_4.08.06-x_*.deb: debian package holding the libraries, headers and manual pages;
- o
-
http://sourceforge.net/projects/bobcat: public archive location;
Bobcat
Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.
Releases
7 releases since Debian 4.0 (Etch); the text changed 6 times.