|
Boost : |
From: Ed Brey (brey_at_[hidden])
Date: 2001-01-23 14:45:57
From: "Jens Maurer" <Jens.Maurer_at_[hidden]>
>
> > In that case, the results at stdout are perfectly informative; I don't
> > really need an .html result. Could we just skip it?
>
> Difficult. All of regression.cpp depends on having a valid ostream,
> and there is no "nullstream" or similar. And ofstream("/dev/null") is
> not portable.
Sounds like a call for a boost library (or library portion). Seems like
an easy one, since the base stream buffer class does nothing by default.
The simple version of a nullstream is just this:
class nullstreambuf: public std::streambuf {};
nullstreambuf nullbuf;
std::iostream nullstream(&nullbuf);
In more detail, we would really need to cater to istream/ostream specifics
and templated types, and to separate interface from implementation, so the
boost library would look more like this:
// nullstream.hpp
template<typename E>
class basic_nullstreambuf: public std::basic_streambuf<E> {};
typedef basic_nullstreambuf<char> nullstreambuf;
typedef basic_nullstreambuf<wchar_t> wnullstreambuf;
extern nullstreambuf nullbuf;
extern std::iostream nullstream;
extern std::istream nullistream;
extern std::ostream nullostream;
extern wnullstreambuf wnullbuf;
extern std::wiostream wnullstream;
extern std::wistream wnullistream;
extern std::wostream wnullostream;
// nullstream.cpp
nullstreambuf nullbuf;
std::iostream nullstream(&nullbuf);
std::istream nullistream(&nullbuf);
std::ostream nullostream(&nullbuf);
wnullstreambuf wnullbuf;
std::wiostream wnullstream(&wnullbuf);
std::wistream wnullistream(&wnullbuf);
std::wostream wnullostream(&wnullbuf);
An example usage would be like this:
if (filename) { // if output file specified:
ifstream filestream(filename);
do_work(filestream);
} else // No output file:
do_work(boost::nullstream);
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk