1*c2c66affSColin Finck #ifndef _FULL_STREAM_H
2*c2c66affSColin Finck #define _FULL_STREAM_H
3*c2c66affSColin Finck 
4*c2c66affSColin Finck #include <streambuf>
5*c2c66affSColin Finck 
6*c2c66affSColin Finck /*
7*c2c66affSColin Finck  * This full_streambuf purpose is to act like a full disk to check the right behavior
8*c2c66affSColin Finck  * of the STLport code in such a case.
9*c2c66affSColin Finck  */
10*c2c66affSColin Finck 
11*c2c66affSColin Finck class full_streambuf : public std::streambuf {
12*c2c66affSColin Finck public:
13*c2c66affSColin Finck   typedef std::streambuf _Base;
14*c2c66affSColin Finck 
15*c2c66affSColin Finck   typedef _Base::int_type int_type;
16*c2c66affSColin Finck   typedef _Base::traits_type traits_type;
17*c2c66affSColin Finck 
18*c2c66affSColin Finck   full_streambuf(size_t nb_output, bool do_throw = false)
_nb_output(nb_output)19*c2c66affSColin Finck     : _nb_output(nb_output), _do_throw(do_throw)
20*c2c66affSColin Finck   {}
21*c2c66affSColin Finck 
str()22*c2c66affSColin Finck   std::string const& str() const
23*c2c66affSColin Finck   { return _buf; }
24*c2c66affSColin Finck 
25*c2c66affSColin Finck protected:
overflow(int_type c)26*c2c66affSColin Finck   int_type overflow(int_type c) {
27*c2c66affSColin Finck     if (_nb_output == 0) {
28*c2c66affSColin Finck #if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
29*c2c66affSColin Finck       if (_do_throw) {
30*c2c66affSColin Finck         throw "streambuf full";
31*c2c66affSColin Finck       }
32*c2c66affSColin Finck #endif
33*c2c66affSColin Finck       return traits_type::eof();
34*c2c66affSColin Finck     }
35*c2c66affSColin Finck     --_nb_output;
36*c2c66affSColin Finck     _buf += traits_type::to_char_type(c);
37*c2c66affSColin Finck     return c;
38*c2c66affSColin Finck   }
39*c2c66affSColin Finck 
40*c2c66affSColin Finck private:
41*c2c66affSColin Finck   size_t _nb_output;
42*c2c66affSColin Finck   bool _do_throw;
43*c2c66affSColin Finck   std::string _buf;
44*c2c66affSColin Finck };
45*c2c66affSColin Finck 
46*c2c66affSColin Finck #endif //_FULL_STREAM_H
47