Пример #1
0
streamsize basic_streambuf<char, char_traits<char> >
  ::xsgetn(char* s, streamsize n)
{
  streamsize result = 0;
  const int_type eof = traits_type::eof();

  while (result < n) {
    if (_FILE_I_avail(_M_get) > 0) {
      size_t chunk = min(__STATIC_CAST(size_t,_FILE_I_avail(_M_get)),
                         __STATIC_CAST(size_t,n - result));
      traits_type::copy(s, _FILE_I_next(_M_get), chunk);
      result += chunk;
      s += chunk;
      _FILE_I_bump(_M_get, chunk);
    }
    else {
      int_type c = sbumpc();
      if (c != eof) {
        s[result] = c;
        ++result;
        ++s;
      }
      else
        break; 
    }
  }
  
  return result;
}
Пример #2
0
streamsize basic_streambuf<char, char_traits<char> >
  ::xsputn(const char* s, streamsize n)
{
  streamsize result = 0;
  const int_type eof = traits_type::eof();

  while (result < n) {
    if (_FILE_O_avail(_M_put) > 0) {
      size_t chunk = min(__STATIC_CAST(size_t,_FILE_O_avail(_M_put)),
                         __STATIC_CAST(size_t,n - result));
      traits_type::copy(_FILE_O_next(_M_put), s, chunk);
      result += chunk;
      s += chunk;
      _FILE_O_bump(_M_put, chunk);
    }

    else if (this->overflow(traits_type::to_int_type(*s)) != eof) {
      ++result;
      ++s;
    }
    else
      break;
  }
  return result;
}
Пример #3
0
streamsize
basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n)
{
  streamsize __result = 0;
  const int_type __eof = _Traits::eof();

  while (__result < __n) {
    if (_M_gnext < _M_gend) {
      size_t __chunk = min(__STATIC_CAST(size_t,_M_gend - _M_gnext),
                           __STATIC_CAST(size_t,__n - __result));
      _Traits::copy(__s, _M_gnext, __chunk);
      __result += __chunk;
      __s += __chunk;
      _M_gnext += __chunk;
    }
    else {
      int_type __c = this->sbumpc();
      if (!_Traits::eq_int_type(__c, __eof)) {
        __s[__result] = __c;
        ++__result;
        ++__s;
      }
      else
        break; 
    }
  }
  
  return __result;
}
Пример #4
0
streamsize
basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
{
  streamsize __result = 0;
  const int_type __eof = _Traits::eof();

  while (__result < __n) {
    if (_M_pnext < _M_pend) {
      size_t __chunk = min(__STATIC_CAST(size_t,_M_pend - _M_pnext),
                           __STATIC_CAST(size_t,__n - __result));
      _Traits::copy(_M_pnext, __s, __chunk);
      __result += __chunk;
      __s += __chunk;
      _M_pnext += __chunk;
    }

    else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
                                   __eof)) {
      ++__result;
      ++__s;
    }
    else
      break;
  }
  return __result;
}
Пример #5
0
bool _STLP_CALL
__get_integer(_InputIter& __first, _InputIter& __last,
              int __base, _Integer& __val,
              int __got, bool __is_negative, _CharT __separator, const string& __grouping, const __false_type& /*_IsSigned*/) {
  bool __ovflow = false;
  _Integer __result = 0;
  bool __is_group = !__grouping.empty();
  char __group_sizes[64];
  char __current_group_size = 0;
  char* __group_sizes_end = __group_sizes;

  _Integer  __over_base = (numeric_limits<_Integer>::max)() / __STATIC_CAST(_Integer, __base);

  for ( ; __first != __last ; ++__first) {

    const _CharT __c = *__first;

    if (__is_group && __c == __separator) {
      *__group_sizes_end++ = __current_group_size;
      __current_group_size = 0;
      continue;
    }

    int __n = __get_digit_from_table(__c);

    if (__n >= __base)
      break;

    ++__got;
    ++__current_group_size;

    if (__result > __over_base)
      __ovflow = true;  //don't need to keep accumulating
    else {
      _Integer __next = __STATIC_CAST(_Integer, __base * __result + __n);
      if (__result != 0)
        __ovflow = __ovflow || __next <= __result;
        __result = __next;
      }
  }

  if (__is_group && __group_sizes_end != __group_sizes) {
      *__group_sizes_end++ = __current_group_size;
  }

  // fbp : added to not modify value if nothing was read
  if (__got > 0) {
      __val = __ovflow ? (numeric_limits<_Integer>::max)()
                       : (__is_negative ? __STATIC_CAST(_Integer, -__result)
                                        : __result);
  }

  // overflow is being treated as failure
  return ((__got > 0) && !__ovflow) &&
          (__is_group == 0 ||
           __valid_grouping(__group_sizes, __group_sizes_end,
                            __grouping.data(), __grouping.data()+ __grouping.size()));
}
Пример #6
0
_Underflow< char, char_traits<char> >::int_type _STLP_CALL
_Underflow< char, char_traits<char> >::_M_doit(basic_filebuf<char, char_traits<char> >* __this)
{
  typedef char_traits<char> traits_type;
  typedef traits_type::int_type int_type;

  if (!__this->_M_in_input_mode) {
    if (!__this->_M_switch_to_input_mode())
      return traits_type::eof();
  }
  else if (__this->_M_in_putback_mode) {
    __this->_M_exit_putback_mode();
    if (__this->gptr() != __this->egptr()) {
      int_type __c = traits_type::to_int_type(*__this->gptr());
      return __c;
    }
  }

  // If it's a disk file, and if the internal and external character
  // sequences are guaranteed to be identical, then try to use memory
  // mapped I/O.  Otherwise, revert to ordinary read.
  if (__this->_M_base.__regular_file()
      && __this->_M_always_noconv
      && __this->_M_base._M_in_binary_mode()) {
    // If we've mmapped part of the file already, then unmap it.
    if (__this->_M_mmap_base) {
      __this->_M_base._M_unmap(__this->_M_mmap_base, __this->_M_mmap_len);
      __this->_M_mmap_base = 0;
      __this->_M_mmap_len = 0;
    }

    // Determine the position where we start mapping.  It has to be
    // a multiple of the page size.
    streamoff __cur = __this->_M_base._M_seek(0, ios_base::cur);
    streamoff __size = __this->_M_base._M_file_size();
    if (__size > 0 && __cur >= 0 && __cur < __size) {
      streamoff __offset = (__cur / __this->_M_base.__page_size()) * __this->_M_base.__page_size();
      streamoff __remainder = __cur - __offset;

      __this->_M_mmap_len = __size - __offset;

      if (__this->_M_mmap_len > MMAP_CHUNK)
        __this->_M_mmap_len = MMAP_CHUNK;

      if ((__this->_M_mmap_base = __this->_M_base._M_mmap(__offset, __this->_M_mmap_len)) != 0) {
        __this->setg((char*) __this->_M_mmap_base,
                     (char*) __this->_M_mmap_base + __STATIC_CAST(ptrdiff_t, __remainder),
                     (char*) __this->_M_mmap_base + __STATIC_CAST(ptrdiff_t, __this->_M_mmap_len));
        return traits_type::to_int_type(*__this->gptr());
      }
      else
        __this->_M_mmap_len = 0;
    }
  }

  return __this->_M_underflow_aux();
}
Пример #7
0
_STLP_STD::streambuf* stdio_streambuf_base::setbuf(char* s, streamsize n) {
#ifdef _STLP_WCE
  // no buffering in windows ce .NET
#else
  size_t __n_size_t = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()), n))
                                                            : __STATIC_CAST(size_t, n);
  _STLP_VENDOR_CSTD::setvbuf(_M_file, s, (s == 0 && n == 0) ? _IONBF : _IOFBF, __n_size_t);
#endif
  return this;
}
Пример #8
0
int codecvt<char, char, mbstate_t>::do_length(const mbstate_t&,
                                              const  char* from, 
                                              const  char* end,
                                              size_t max) const
{
  return min( __STATIC_CAST(size_t, (end - from)), max);
}
Пример #9
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);
  }
}
Пример #10
0
void
_Rb_tree<_Key,_Compare,_Value,_KeyOfValue,_Traits,_Alloc>::_M_erase(_Rb_tree_node_base *__x) {
  // erase without rebalancing
  while (__x != 0) {
    _M_erase(_S_right(__x));
    _Base_ptr __y = _S_left(__x);
    _STLP_STD::_Destroy(&_S_value(__x));
    this->_M_header.deallocate(__STATIC_CAST(_Link_type, __x),1);
    __x = __y;
  }
}
Пример #11
0
_InputIter 
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
				    ios_base::iostate& __err,
                                    long double& __val) const {
  string __buf ;
  bool __ok = _M_read_float(__buf, __in, __end, __str, (_CharT*)0 );
  __string_to_float(__buf, __val);
  __err = __STATIC_CAST(ios_base::iostate, __ok ? ios_base::goodbit : ios_base::failbit);
  if (__in == __end)
    __err |= ios_base::eofbit;
  return __in;
}
Пример #12
0
streamsize basic_streambuf<char, char_traits<char> >
  ::_M_xsputnc(char c, streamsize n)
{
  streamsize result = 0;
  const int_type eof = traits_type::eof();

  while (result < n) {
    if (_FILE_O_avail(_M_put) > 0) {
      size_t chunk = min(__STATIC_CAST(size_t,_FILE_O_avail(_M_put)),
                         __STATIC_CAST(size_t,n - result));
      traits_type::assign(_FILE_O_next(_M_put), chunk, c);
      result += chunk;
      _FILE_O_bump(_M_put, chunk);
    }

    else if (this->overflow(traits_type::to_int_type(c)) != eof)
      ++result;
    else
      break;
  }
  return result;
}
Пример #13
0
// Takes a reference to a locale::id, assign a numeric index if not already
// affected and returns it. The returned index is always positive.
static const locale::id& _Stl_loc_get_index(locale::id& id) {
  if (id._M_index == 0) {
#if defined (_STLP_ATOMIC_INCREMENT) && !defined (_STLP_WIN95_LIKE)
    static _STLP_VOLATILE __stl_atomic_t _S_index = __STATIC_CAST(__stl_atomic_t, locale::id::_S_max);
    id._M_index = _STLP_ATOMIC_INCREMENT(&_S_index);
#else
    static _STLP_STATIC_MUTEX _Index_lock _STLP_MUTEX_INITIALIZER;
    _STLP_auto_lock sentry(_Index_lock);
    size_t new_index = locale::id::_S_max++;
    id._M_index = new_index;
#endif
  }
  return id;
}
Пример #14
0
streamsize
basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
{
  streamsize __result = 0;
  const int_type __eof = _Traits::eof();

  while (__result < __n) {
    if (_M_pnext < _M_pend) {
      size_t __chunk = min(__STATIC_CAST(size_t,_M_pend - _M_pnext),
                           __STATIC_CAST(size_t,__n - __result));
      _Traits::assign(_M_pnext, __chunk, __c);
      __result += __chunk;
      _M_pnext += __chunk;
    }

    else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
                                   __eof))
      ++__result;
    else
      break;
  }
  return __result;
}
Пример #15
0
_InputIter _STLP_CALL
_M_do_get_integer(_InputIter& __in, _InputIter& __end, ios_base& __str,
                  ios_base::iostate& __err, _Integer& __val, _CharT* __pc) 
{

#if defined(__HP_aCC) && (__HP_aCC == 1)
  bool _IsSigned = !((_Integer)(-1) > 0);
#else
  typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
#endif

  const numpunct<_CharT>& __numpunct = *(const numpunct<_CharT>*)__str._M_numpunct_facet();
  const string& __grouping = __str._M_grouping(); // cached copy

  const int __base_or_zero = _M_get_base_or_zero(__in, __end, __str, __pc);
  int  __got = __base_or_zero & 1;

  bool __result;

  if (__in == __end) {      // We may have already read a 0.  If so,

    if (__got > 0) {       // the result is 0 even if we're at eof.
      __val = 0;
      __result = true;
    }
    else
      __result = false;    
  } else {

    const bool __negative = __base_or_zero & 2;
    const int __base = __base_or_zero >> 2;

#if defined(__HP_aCC) && (__HP_aCC == 1)
     if (_IsSigned)
       __result = __get_integer(__in, __end, __base,  __val, __got, __negative, __numpunct.thousands_sep(), __grouping, __true_type() );
     else
      __result = __get_integer(__in, __end, __base,  __val, __got, __negative, __numpunct.thousands_sep(), __grouping, __false_type() );
#else
    __result = __get_integer(__in, __end, __base,  __val, __got, __negative, __numpunct.thousands_sep(), __grouping, _IsSigned());
# endif
  }

  __err = __STATIC_CAST(ios_base::iostate, __result ? ios_base::goodbit : ios_base::failbit);

  if (__in == __end)
    __err |= ios_base::eofbit;
  return __in;
}
Пример #16
0
_InputIter _STLP_CALL
__do_get_integer(_InputIter& __in_ite, _InputIter& __end, ios_base& __str,
                 ios_base::iostate& __err, _Integer& __val, _CharT* /*__pc*/) {
  locale __loc = __str.getloc();
  const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);

#if defined (__HP_aCC) && (__HP_aCC == 1)
  bool _IsSigned = !((_Integer)(-1) > 0);
#else
  typedef typename is_signed<_Integer>::type::type _IsSigned;
#endif

  const int __base_or_zero = __get_base_or_zero(__in_ite, __end, __str.flags(), __ctype);
  int  __got = __base_or_zero & 1;

  bool __result;

  if (__in_ite == __end) {      // We may have already read a 0.  If so,

    if (__got > 0) {       // the result is 0 even if we're at eof.
      __val = 0;
      __result = true;
    }
    else
      __result = false;
  }
  else {
    const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
    const bool __negative = (__base_or_zero & 2) != 0;
    const int __base = __base_or_zero >> 2;

#if defined (__HP_aCC) && (__HP_aCC == 1)
    if (_IsSigned)
      __result = __get_integer(__in_ite, __end, __base,  __val, __got, __negative, __np.thousands_sep(), __np.grouping(), __true_type() );
    else
      __result = __get_integer(__in_ite, __end, __base,  __val, __got, __negative, __np.thousands_sep(), __np.grouping(), __false_type() );
#else
    __result = __get_integer(__in_ite, __end, __base,  __val, __got, __negative, __np.thousands_sep(), __np.grouping(), _IsSigned());
# endif
  }

  __err = __STATIC_CAST(ios_base::iostate, __result ? ios_base::goodbit : ios_base::failbit);

  if (__in_ite == __end)
    __err |= ios_base::eofbit;
  return __in_ite;
}
Пример #17
0
uint32_t w32_get_current_thread_id()
{
    return __STATIC_CAST( uint32_t, GetCurrentThread() );
}
Пример #18
0
basic_istream<_CharT, _Traits>& _STLP_CALL 
operator>>(basic_istream<_CharT, _Traits>& __is,
           basic_string<_CharT,_Traits, _Alloc>& __s)
{
  _STLP_USING_IO
  typedef basic_istream<_CharT, _Traits> __istream;
  typename __istream::sentry __sentry(__is);

  if (__sentry) {
    basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
    typedef ctype<_CharT> _C_type;

#ifdef _STLP_OWN_IOSTREAMS
    //    const _C_type& _Ctype = use_facet<_C_type>(__loc);
    const _C_type& _Ctype = *(const _C_type*)__is._M_ctype_facet();
#else
# if defined (_STLP_MSVC) && (_STLP_MSVC <= 1200 ) || defined (__ICL)
    const locale& __loc = __is.getloc();
    const _C_type& _Ctype = use_facet(__loc , ( _C_type * ) 0, true);
# elif defined (__SUNPRO_CC)
    const locale& __loc = __is.getloc();
    const _C_type& _Ctype = use_facet(__loc , ( _C_type * ) 0);
# else
    const locale& __loc = __is.getloc();
    const _C_type& _Ctype = use_facet<_C_type>(__loc);
# endif
#endif
    __s.clear();
    size_t __n = __is.width(0);
    if (__n == 0)
      __n = __STATIC_CAST(size_t,-1);
    else
      __s.reserve(__n);
    

    while (__n-- > 0) {
      typename _Traits::int_type __c1 = __buf->sbumpc();
      if (_Traits::eq_int_type(__c1, _Traits::eof())) {
        __is.setstate(__istream::eofbit);
        break;
      }
      else {
        _CharT __c = _Traits::to_char_type(__c1);

        if (_Ctype.is(_C_type::space, __c)) {
          if (_Traits::eq_int_type(__buf->sputbackc(__c), _Traits::eof()))
            __is.setstate(__istream::failbit);
          break;
        }
        else
          __s.push_back(__c);
      }
    }
    
    // If we have read no characters, then set failbit.
    if (__s.size() == 0)
      __is.setstate(__istream::failbit);
  }
  else
    __is.setstate(__istream::failbit);

  return __is;
}
Пример #19
0
_OutputIter _S_do_put(_OutputIter __s, bool  __intl, ios_base&  __str,
                      _CharT __fill, const _Str& __digits, bool __check_digits,
                      _Str_Type * /*__dummy*/) {
  typedef _CharT char_type;
  typedef _Str_Type string_type;
  typedef ctype<char_type>             _Ctype;
  typedef moneypunct<char_type, false> _Punct;
  typedef moneypunct<char_type, true>  _Punct_intl;

  locale __loc = __str.getloc();
  const _Ctype&      __c_type     = use_facet<_Ctype>(__loc) ;
  const _Punct&      __punct      = use_facet<_Punct>(__loc) ;
  const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;

  // some special characters
  char_type __minus = __c_type.widen('-');
  char_type __plus  = __c_type.widen('+');
  char_type __space = __c_type.widen(' ');
  char_type __zero  = __c_type.widen('0');
  char_type __point = __intl ? __punct_intl.decimal_point()
                             : __punct.decimal_point();

  char_type __sep = __intl ? __punct_intl.thousands_sep()
                           : __punct.thousands_sep();

  string __grouping = __intl ? __punct_intl.grouping()
                             : __punct.grouping();

  int __frac_digits      = __intl ? __punct_intl.frac_digits() 
                                  : __punct.frac_digits();

  string_type __curr_sym = __intl ? __punct_intl.curr_symbol() 
                                  : __punct.curr_symbol();

  // if there are no digits we are going to return __s.  If there
  // are digits, but not enough to fill the frac_digits, we are
  // going to add zeros.  I don't know whether this is right or
  // not.
  if (__digits.empty()) 
    return __s;

  typename string_type::const_iterator __digits_first = __digits.begin();
  typename string_type::const_iterator __digits_last  = __digits.end();

  bool __is_negative = *__digits_first == __minus;
  if (__is_negative)
    ++__digits_first;

  string_type __sign = __intl ? __is_negative ? __punct_intl.negative_sign()
                                              : __punct_intl.positive_sign()
                              : __is_negative ? __punct.negative_sign()
                                              : __punct.positive_sign();
  if (__check_digits) {
    typename string_type::const_iterator __cp = __digits_first;
    while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
      ++__cp;
    if (__cp == __digits_first)
      return __s;
    __digits_last = __cp;
  }

  // If grouping is required, we make a copy of __digits and
  // insert the grouping.

  _STLP_BASIC_IOSTRING(char_type) __new_digits;
  if (!__grouping.empty()) {
    __new_digits.assign(__digits_first, __digits_last);
    __insert_grouping(__new_digits,
                      __new_digits.size() - __frac_digits,
                      __grouping,
                      __sep, __plus, __minus, 0);
    __digits_first = __new_digits.begin(); // <<--
    __digits_last  = __new_digits.end();   // <<--
  }

  // Determine the amount of padding required, if any.  
  streamsize __width = __str.width();

#if defined(_STLP_DEBUG) && (defined(__HP_aCC) && (__HP_aCC <= 1))
  size_t __value_length = operator -(__digits_last, __digits_first);
#else
  size_t __value_length = __digits_last - __digits_first;
#endif

  size_t __length = __value_length + __sign.size();

  if (__frac_digits != 0)
    ++__length;

  bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
  if (__generate_curr)
    __length += __curr_sym.size();
  money_base::pattern __format = __intl ? (__is_negative ? __punct_intl.neg_format()
                                                         : __punct_intl.pos_format())
                                        : (__is_negative ? __punct.neg_format()
                                                         : __punct.pos_format());
  {
    //For the moment the following is commented for decoding reason.
    //No reason to add a space last if the money symbol do not have to be display
    //if (__format.field[3] == (char) money_base::symbol && !__generate_curr) {
    //  if (__format.field[2] == (char) money_base::space) {
    //    __format.field[2] = (char) money_base::none;
    //  }
    //}
    //space can only be second or third and only once (22.2.6.3-1):
    if ((__format.field[1] == (char) money_base::space) ||
        (__format.field[2] == (char) money_base::space))
      ++__length;
  }

  const bool __need_fill = (((sizeof(streamsize) > sizeof(size_t)) && (__STATIC_CAST(streamsize, __length) < __width)) ||
                            ((sizeof(streamsize) <= sizeof(size_t)) && (__length < __STATIC_CAST(size_t, __width))));
  streamsize __fill_amt = __need_fill ? __width - __length : 0;

  ios_base::fmtflags __fill_pos = __str.flags() & ios_base::adjustfield;

  if (__fill_amt != 0 &&
      !(__fill_pos & (ios_base::left | ios_base::internal)))
    __s = __fill_n(__s, __fill_amt, __fill);
    
  for (int __i = 0; __i < 4; ++__i) {
    char __ffield = __format.field[__i];
    switch (__ffield) {
    case money_base::none:
      if (__fill_amt != 0 && __fill_pos == ios_base::internal)
        __s = __fill_n(__s, __fill_amt, __fill);
      break;
    case money_base::space:
      *__s++ = __space;
      if (__fill_amt != 0 && __fill_pos == ios_base::internal)
        __s = __fill_n(__s, __fill_amt, __fill);
      break;
    case money_base::symbol:
      if (__generate_curr)
        __s = copy(__curr_sym.begin(), __curr_sym.end(), __s);
      break;
    case money_base::sign:
      if (!__sign.empty())
        *__s++ = __sign[0];
      break;
    case money_base::value:
      if (__frac_digits == 0)
        __s = copy(__digits_first, __digits_last, __s);
      else {
        if ((int)__value_length <= __frac_digits) {
          *__s++ = __point;
          __s = copy(__digits_first, __digits_last, __s);
          __s =  __fill_n(__s, __frac_digits - __value_length, __zero);
        }
        else {
          __s = copy(__digits_first, __digits_last - __frac_digits, __s);
          if (__frac_digits != 0) {
            *__s++ = __point;
            __s = copy(__digits_last - __frac_digits, __digits_last, __s);
          }
        }
      }
    } //Close for switch
  } // Close for loop

  // Ouput rest of sign if necessary.
  if (__sign.size() > 1)
    __s = copy(__sign.begin() + 1, __sign.end(), __s);
  if (__fill_amt != 0 &&
      !(__fill_pos & (ios_base::right | ios_base::internal)))
    __s = __fill_n(__s, __fill_amt, __fill);
  
  return __s;
}
Пример #20
0
strstreambuf::pos_type
strstreambuf::seekoff(off_type off,
                      ios_base::seekdir dir, ios_base::openmode mode) {
  bool do_get = false;
  bool do_put = false;

  if ((mode & (ios_base::in | ios_base::out)) ==
          (ios_base::in | ios_base::out) &&
      (dir == ios_base::beg || dir == ios_base::end))
    do_get = do_put = true;
  else if (mode & ios_base::in)
    do_get = true;
  else if (mode & ios_base::out)
    do_put = true;

  // !gptr() is here because, according to D.7.1 paragraph 4, the seekable
  // area is undefined if there is no get area.
  if ((!do_get && !do_put) || (do_put && !pptr()) || !gptr())
    return pos_type(off_type(-1));

  char* seeklow  = eback();
  char* seekhigh = epptr() ? epptr() : egptr();

  off_type newoff;
  switch(dir) {
  case ios_base::beg:
    newoff = 0;
    break;
  case ios_base::end:
    newoff = seekhigh - seeklow;
    break;
  case ios_base::cur:
    newoff = do_put ? pptr() - seeklow : gptr() - seeklow;
    break;
  default:
    return pos_type(off_type(-1));
  }

  off += newoff;
  if (off < 0 || off > seekhigh - seeklow)
    return pos_type(off_type(-1));

  if (do_put) {
    if (seeklow + __STATIC_CAST(ptrdiff_t, off) < pbase()) {
      setp(seeklow, epptr());
      pbump((int)off);
    }
    else {
      setp(pbase(), epptr());
      pbump((int)(off - (pbase() - seeklow)));
    }
  }
  if (do_get) {
    if (off <= egptr() - seeklow)
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), egptr());
    else if (off <= pptr() - seeklow)
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), pptr());
    else
      setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), epptr());
  }

  return pos_type(newoff);
}
Пример #21
0
int codecvt<char, char, mbstate_t>::do_length(state_type&,
                                              const  char* from,
                                              const  char* end,
                                              size_t mx) const
{ return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }