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