/usr/include/bobcat/multistreambuf is in libbobcat-dev 2.20.01-1.
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 137 138 139 140 141 142 143 144 145 | #ifndef INCLUDED_BOBCAT_MULTISTREAMBUF_
#define INCLUDED_BOBCAT_MULTISTREAMBUF_
#include <cstdio>
#include <streambuf>
#include <vector>
#include <ostream>
#include <string>
namespace FBB
{
class MultiStreambuf: public std::streambuf
{
public:
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
};
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);
void setMode(Mode mode);
Mode mode() const;
std::ostream &ostream();
private:
static void setOnce(stream &os);
};
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);
explicit MultiStreambuf(std::vector<stream> const &osvector);
void insert(std::ostream &os, Mode mode = ON);
void insert(std::vector<stream> const &os);
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
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
{
std::string &buffer;
bool ok;
};
static void insertStruct(stream &os, Insert &insert);
};
inline MultiStreambuf::stream::stream(std::ostream &os, Mode mode)
:
d_os(&os),
d_mode(mode)
{}
inline void MultiStreambuf::stream::setMode(Mode mode)
{
d_mode = mode;
}
inline MultiStreambuf::Mode MultiStreambuf::stream::mode() const
{
return d_mode;
}
inline std::ostream &MultiStreambuf::stream::ostream()
{
return *d_os;
}
inline void MultiStreambuf::stream::setOnce(stream &os)
{
if (os.d_mode == RESET)
os.d_mode = ONCE;
}
inline MultiStreambuf::MultiStreambuf(std::ostream &os, Mode mode)
{
insert(os, mode);
}
inline MultiStreambuf::MultiStreambuf(std::vector<stream> const &osvector)
{
insert(osvector);
}
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());
}
inline MultiStreambuf::iterator MultiStreambuf::begin()
{
return d_os.begin();
}
inline MultiStreambuf::iterator MultiStreambuf::end()
{
return d_os.end();
}
inline MultiStreambuf::const_iterator MultiStreambuf::begin() const
{
return d_os.begin();
}
inline MultiStreambuf::const_iterator MultiStreambuf::end() const
{
return d_os.end();
}
} // namespace FBB
#endif
|