FBB::Mstream(3bobcat)

Message handler
(libbobcat-dev_4.08.03-x.tar.gz)

2005-2018

NAME

FBB::Mstream - Generic message handling stream

SYNOPSIS

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

DESCRIPTION

Objects of this class are used for handling messages in a standardized way. Messages may be prefixed with order (line) numbers an/or, labels. Messages generated by Mstream objects may optionally end by throwing an FBB::Exception (which is an std::exception), allowing simple implementation of, e.g., fatal error messages.

Four message streams are provided by the BOBCAT library and may be used after including the mstream header file. They are all defined in the FBB namespace:

By default all messages are inserted into the standard output stream, but other destinations (standard error, a named file, etc.) can easily be configured.

Mstream objects themselves are std::ostream objects, so they can be used as objects passed to functions expecting ostream arguments. Messages inserted into Mstream objects are buffered until the buffer is flushed by their std::ostream parts or when either the FBB::endl or FBB::flush is inserted into the message stream. Since these manipulators act like std::endl and std::flush when inserted into another kind of std::ostream object, using FBB::endl and using FBB::flush might be worth considering. Also, when using namespace std and using namespace FBB is specified the FBB::endl and FBB::flush manipulator will automatically be used with Mstream objects.

Messages inserted into Mstream objects are considered completed at the insertion of the FBB::endl or FBB::flush manipulators. Message labels, line number labels and line numbers will only be shown for the next line after these manipulators have been inserted and exceptions are, if needed, thrown from these manipulators.

NAMESPACE

FBB
All elements mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

std::ostream

CONSTRUCTORS

As Mstream inherits from std::ostream the copy constructor is not available. Neither is the move constructor.

MEMBER FUNCTIONS

MANIPULATORS

Note that the following two manipulators are not members of the class Mstream, but are free functions defined in the namespace FBB.

As the manipulators FBB::endl and FBB::flush act like, respectively, std::endl and std::flush when inserted into another kind of std::ostream object, using the declarations `using FBB::endl' and `using FBB::flush' might be worth considering. Also, when using namespace std and using namespace FBB is specified the FBB::endl and FBB::flush manipulator will automatically be called when inserting endl or flush into Mstream objects.

EXAMPLE

#include <iostream>
#include <algorithm>
#include <iterator>

#include <bobcat/mstream>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
try
{
    cout << sizeof(Mstream) << ' ' << sizeof(Mbuf) << '\n';

    imsg << "Informational: " << endl;
    imsg.off();
    cout << "The i-msg stream is now off. This message should appear once" <<
                                                                        endl;
    imsg << "The i-msg stream is now off. This message should appear once" <<
                                                                        endl;
    imsg << "The i-msg stream is now off. This message should appear once" <<
                                                                        endl;
    cout << "But this message is shown" << endl;

    wmsg << "Warning message" << endl;
    emsg << "Oops, this this is an error (not really)" << endl;
    emsg << "Oops, this goes wrong, too" << noid;

    imsg.on();
    imsg << "And another informational msg: " << emsg.count() << 
            " error messages\n" << flush;

    emsg << "Third error" << endl;
    emsg.setMaxCount(3);

    imsg << "Msg in between" << endl;

    imsg.setTag("tag");
    imsg << "tagged message" << endl;

    imsg.setTag("label");
    imsg << "labeled message" << endl;

    cerr << "(cerr) LineExcess: " << emsg.lineExcess() << ", count = " <<
            emsg.count() << endl;

    emsg << "Fourth error\n" << noid;       // no id is shown
    emsg << "Fourth error\n" << flush;      // shows id (remove the previous
                                            // statement)

    cerr << "(cerr) LineExcess: " << emsg.lineExcess() << ", count = " <<
            emsg.count() << endl;

    cerr << "Beyond\n";
}            
catch(exception const &e)
{
    std::cerr << "Got a std::exception: " << e.what() << '\n';
}
catch(...)
{
    std::cerr << "Got an exception\n";
}






FILES

bobcat/mstream - defines the class interface

SEE ALSO

bobcat(7), exception(3bobcat), mbuf(3bobcat)

BUGS

None Reported.

DISTRIBUTION FILES

BOBCAT

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

COPYRIGHT

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

AUTHOR

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