/usr/include/bobcat/multistreambuf is in libbobcat-dev 4.01.03-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #ifndef INCLUDED_BOBCAT_MULTISTREAMBUF_
#define INCLUDED_BOBCAT_MULTISTREAMBUF_
#include <cstdio>
#include <streambuf>
#include <vector>
#include <ostream>
#include <string>
namespace FBB
{
struct MultiStreambuf: public std::streambuf
{
enum Mode
{
OFF, // stream not used
ON, // stream always used
ONCE, // stream used until flushed
RESET, // stream once used. Set to ONCE to re-use
ALL, // with remove: remove all ostreams matching os
};
class stream // holds a pointer to a stream and a indicator
{ // telling us whether or not to use the stream
friend class MultiStreambuf;
std::ostream *d_os;
Mode d_mode;
public:
stream(std::ostream &os, Mode mode = ON); // 1.f
void setMode(Mode mode); // .f
Mode mode() const; // .f
std::ostream &ostream(); // .f
private:
static void setOnce(stream &os); // .f
};
typedef std::vector<stream>::iterator iterator;
typedef std::vector<stream>::const_iterator const_iterator;
private:
std::string d_buffer;
std::vector<stream> d_os;
public:
MultiStreambuf() = default;
explicit MultiStreambuf(std::ostream &os, Mode mode = ON); // 1.f
explicit MultiStreambuf(std::vector<stream> const &osvector); // 2.f
void insert(std::ostream &os, Mode mode = ON); // 1.f
void insert(std::vector<stream> const &os); // 2.f
bool remove(std::ostream &os, Mode mode = ONCE);
iterator begin(); // 1.f
iterator end(); // 1.f
const_iterator begin() const; // 2.f
const_iterator end() const; // 2.f
size_t size() const; // .f
void setOnce(); // reset all `RESET' modes to `ONCE'
protected:
int pSync();
private:
virtual int overflow(int c);
virtual std::streamsize xsputn(char const *buffer, std::streamsize n);
virtual int sync();
struct Insert;
static void insertStruct(stream &os, Insert &insert);
};
inline MultiStreambuf::Mode MultiStreambuf::stream::mode() const
{
return d_mode;
}
inline std::ostream &MultiStreambuf::stream::ostream()
{
return *d_os;
}
inline void MultiStreambuf::stream::setMode(Mode mode)
{
d_mode = mode;
}
inline void MultiStreambuf::stream::setOnce(stream &os)
{
if (os.d_mode == RESET)
os.d_mode = ONCE;
}
inline MultiStreambuf::stream::stream(std::ostream &os, Mode mode)
:
d_os(&os),
d_mode(mode)
{}
inline MultiStreambuf::MultiStreambuf(std::ostream &os, Mode mode)
{
insert(os, mode);
}
inline MultiStreambuf::MultiStreambuf(std::vector<stream> const &osvector)
{
insert(osvector);
}
inline MultiStreambuf::iterator MultiStreambuf::begin()
{
return d_os.begin();
}
inline MultiStreambuf::const_iterator MultiStreambuf::begin() const
{
return d_os.begin();
}
inline MultiStreambuf::iterator MultiStreambuf::end()
{
return d_os.end();
}
inline MultiStreambuf::const_iterator MultiStreambuf::end() const
{
return d_os.end();
}
inline void MultiStreambuf::insert(std::ostream &os, Mode mode)
{
d_os.push_back(stream(os, mode));
}
inline void MultiStreambuf::insert(std::vector<stream> const &os)
{
d_os.insert(d_os.end(), os.begin(), os.end());
}
} // namespace FBB
#endif
|