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