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::MultiBuf - Selectively writes multiple streams

Author

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

libbobcat-dev_6.07.01                               2005-2025                             FBB::MultiBuf(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      MultiBuf():
              The default constructor creates a  MultiBuf  object  which  contains  no  associated  std::ostream
              objects.

       o      MultiBuf(std::ostream&os,Modemode=ON):
              This  constructor  creates a MultiBuf object which is immediately associated with the std::ostream
              specified as its first argument.

       o      MultiBuf(std::vector<MultiBuf::stream>const&osvector):
              This constructor creates a MultiBuf object which is immediately associated with  all  std::ostream
              objects that are stored in the MultiBuf::stream elements of the specified vector.

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

Description

       The  FBB::MultiBuf  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  MultiBuf  is  given  a  mode-tag
       indicating  whether the stream should always be used when information is inserted into the MultiBuf, 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 MultiBuf 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 MultiBuf buffer which have an active mode receive that information.

       An MultiBuf object should be outlived by all active streams that are associated with it.

       MultiBuf 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’sstd::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 MultiBuf objects are visited when information is inserted.

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 a MultiBuf

       o      ON:
              A std::ostream having this mode will be used when information is inserted into a MultiBuf

       o      ONCE:
              A std::ostream having this mode will be  used  once,  until  the  next  flushing  operation,  when
              information is inserted into an MultiBuf

       o      RESET:
              A  std::ostream having this mode will not be used when information is inserted into a MultiBuf. 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.

Example

       #include <iostream>
       #include <fstream>
       #include <bobcat/multibuf>

       using namespace std;
       using namespace FBB;

       int main()
       {
           MultiBuf  msb(cout);
           ostream         os(&msb);
           ofstream        out("out");

           msb.insert(out, MultiBuf::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/multibuf - defines the class interface

Inherits From

std::streambuf

Member Functions

       All  members  of  std::ostringstream  and  std::exception  are available, as MultiBuf inherits from these
       classes.

       o      iteratorbegin():
              This member returns an iterator to the first stream element that is stored in a MultiBuf object.

       o      const_iteratorbegin():
              This member returns an iterator to the first (unmodifiable) stream element that  is  stored  in  a
              MultiBuf object.

       o      iteratorend():
              This  member  returns  an  iterator  pointing  beyond  the last stream element that is stored in a
              MultiBuf object.

       o      const_iteratorend():
              This member returns an iterator pointing beyond the last (unmodifiable)  stream  element  that  is
              stored in a MultiBuf object.

       o      voidinsert(std::ostream&os,Modemode=ON):
              This  member adds the specified std::ostream using the specified Mode to the current set of stream
              objects. Note that if called multiple times for identical std::ostreams these objects are inserted
              multiple times as well.

       o      voidinsert(std::vector<stream>const&os):
              This member adds all stream objects stored in the os vector to the current set of stream objects.

       o      boolremove(std::ostream&os,Modemode=ONCE):
              If os is stored in the MultiBuf it is removed, and true is returned. If mode ALL is specified  all
              os  objects  that were stored in the MultiBuf object are removed (and true is returned). If the os
              object was not stored false is returned. To determine whether os has been stored in  the  MultiBuf
              object its address is compared to the addresses of the std::ostream objects that are stored inside
              the MultiBuf object: the object(s) having addresses &os is (are) removed.

       o      voidvoidsetOnce():
              This member will reset all the RESETMode values of the stored stream objects to ONCE.

       o      size_tsize()const:
              The number of streams currently serviced by the MultiBuf object is returned.

Name

       FBB::MultiBuf - Selectively writes multiple streams

Namespace

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

Nested Class

       The  class MultiBuf::stream is defined as a nested class of MultiBuf. It offers the following constructor
       and public members:

       o      stream(std::ostream&os,Modemode=ON):
              The constructor stores a std::ostream object, and associates a Mode value with it.

       o      voidsetMode(Modemode):
              This member is used to redefine the stream’s  Mode value.

       o      voidmode()const:
              This member returns the  stream’s  Mode value.

       o      operatorstd::ostream&():
              This member returns the  stream’s  std::ostream.

See Also

bobcat(7)

Synopsis

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

Types

       The following subtypes are defined in the class FBB:MultiBuf:

       o      iterator:
              This is a synonym of std::vector<stream>::iterator

       o      const_iterator:
              This is a synonym of std::vector<stream>::const_iterator

See Also