Esempio n. 1
0
    void operator& (string& x, istream& stream) {
	size_t len;
	len & stream;
	validateListSize (len);
	x.resize (len);
	stream.read (&x[0], x.length());
	if (!stream || stream.gcount() != streamsize(len))
	    throw checkpoint_error ("stream read error string");
    }
Esempio n. 2
0
basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, 
           const basic_string<_CharT,_Traits,_Alloc>& __s)
{

  _STLP_USING_IO
  typedef basic_ostream<_CharT, _Traits> __ostream;
  typename __ostream::sentry __sentry(__os);
  bool __ok = false;

  if (__sentry) {
    __ok = true;
    size_t __n = __s.size();
    size_t __pad_len = 0;
    const bool __left = (__os.flags() & __ostream::left) != 0;
    const size_t __w = __os.width(0);
    basic_streambuf<_CharT, _Traits>* __buf = __os.rdbuf();

    if (__n < __w) {
      __pad_len = __w - __n;
    }
    
    if (!__left)
      __ok = __stlp_string_fill(__os, __buf, __pad_len);    

    __ok = __ok && (__buf->sputn(__s.data(), streamsize(__n)) == streamsize(__n));

    if (__left)
      __ok = __ok && __stlp_string_fill(__os, __buf, __pad_len);
  }

  if (!__ok)
    __os.setstate(__ostream::failbit);

  return __os;
}
Esempio n. 3
0
_STLP_BEGIN_NAMESPACE

// strstreambuf constructor, destructor.

_STLP_EXP_DECLSPEC strstreambuf::strstreambuf(streamsize initial_capacity)
   :  _M_alloc_fun(0), _M_free_fun(0),
     _M_dynamic(true), _M_frozen(false), _M_constant(false)  
#ifdef __SYMBIAN32__
    , _pfrozenendsave(NULL)
    ,_pgetfrozenendsave( NULL)
#endif     
{
  streamsize n = (max)(initial_capacity, streamsize(16));

  char* buf = _M_alloc(n);
#ifdef __SYMBIAN32__  
  *buf = '\0';
#endif  
  if (buf) {
    setp(buf, buf + n);
    setg(buf, buf, buf);
  }
}
Esempio n. 4
0
_STLP_BEGIN_NAMESPACE

// strstreambuf constructor, destructor.
strstreambuf::strstreambuf(streamsize initial_capacity)
   : _M_alloc_fun(0), _M_free_fun(0),
     _M_dynamic(true), _M_frozen(false), _M_constant(false) {
  size_t n = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()),
                                                                                 (max)(initial_capacity, streamsize(16))))
                                                   : __STATIC_CAST(size_t, (max)(initial_capacity, streamsize(16)));

  char* buf = _M_alloc(n);
  if (buf) {
    setp(buf, buf + n);
    setg(buf, buf, buf);
  }
}
Esempio n. 5
0
/* virtual */ streambuf*
strstreambuf::setbuf (char_type* buf, streamsize bufsize)
{
    _RWSTD_ASSERT (_C_is_valid ());

    if (   !(_C_state & _C_dynamic) || (_C_state & _C_frozen)
        || (!buf && !bufsize)) {
        // lwg issue 66
        return 0;
    }

    // determine the existing (possibly disjoint) sequences
    // in the (possibly two distinct) buffer(s) and copy
    // them into the new buffer

    // [.....]  [.....]          or [....[.]...]
    // ^     ^  ^     ^             ^          ^
    // |     |  |     |             |          |
    // |     |  |     +- xend       |          +- xend, gap_beg, gap_end
    // |     |  +------- gap_end    +------------ xbeg
    // |     +---------- gap_beg
    // +---------------- xbeg

    const char_type* const xbeg =
        eback () && eback () < pbase () ? eback () : pbase ();

    const char_type* const xend =
        epptr () && epptr () < egptr () ? egptr () : epptr ();

    const char_type *gap_beg = pptr () < eback ()
        ? pptr () : egptr () < pbase () ? egptr () : pbase ();

    const char_type *gap_end = pptr () < eback ()
        ? eback () : egptr () < pbase () ? egptr () : pbase ();

    // if gap_end is before gap_beg, set both so as to make the gap zero size
    if (gap_end <= gap_beg)
        gap_beg = gap_end = xend;

    // compute the cumulative size of both sequences minus the gap
    const streamsize slen = streamsize ((xend - xbeg) - (gap_end - gap_beg));

    if (bufsize < slen || !_C_is_out ())
        return 0;   // failure

    const bool free_old_buf = _C_own_buf ();
    
    if (!buf) {
        _TRY {
            // allocate a new buffer
            buf = _C_palloc ?
                  _RWSTD_STATIC_CAST (char_type*, _C_palloc (bufsize))
                : new char [bufsize];
        }
        _CATCH (...) {
            // catch all exceptions, indicate failure by returning 0
        }

        if (!buf)
            return 0;

        _C_own_buf (true);
    }