1*4684ddb6SLionel Sambuc //===-------------------------- ios.cpp -----------------------------------===// 2*4684ddb6SLionel Sambuc // 3*4684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure 4*4684ddb6SLionel Sambuc // 5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open 6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details. 7*4684ddb6SLionel Sambuc // 8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===// 9*4684ddb6SLionel Sambuc 10*4684ddb6SLionel Sambuc #define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__; 11*4684ddb6SLionel Sambuc 12*4684ddb6SLionel Sambuc #include "ios" 13*4684ddb6SLionel Sambuc #include "streambuf" 14*4684ddb6SLionel Sambuc #include "istream" 15*4684ddb6SLionel Sambuc #include "string" 16*4684ddb6SLionel Sambuc #include "__locale" 17*4684ddb6SLionel Sambuc #include "algorithm" 18*4684ddb6SLionel Sambuc #include "memory" 19*4684ddb6SLionel Sambuc #include "new" 20*4684ddb6SLionel Sambuc #include "limits" 21*4684ddb6SLionel Sambuc #include <stdlib.h> 22*4684ddb6SLionel Sambuc 23*4684ddb6SLionel Sambuc _LIBCPP_BEGIN_NAMESPACE_STD 24*4684ddb6SLionel Sambuc 25*4684ddb6SLionel Sambuc template class basic_ios<char>; 26*4684ddb6SLionel Sambuc template class basic_ios<wchar_t>; 27*4684ddb6SLionel Sambuc 28*4684ddb6SLionel Sambuc template class basic_streambuf<char>; 29*4684ddb6SLionel Sambuc template class basic_streambuf<wchar_t>; 30*4684ddb6SLionel Sambuc 31*4684ddb6SLionel Sambuc template class basic_istream<char>; 32*4684ddb6SLionel Sambuc template class basic_istream<wchar_t>; 33*4684ddb6SLionel Sambuc 34*4684ddb6SLionel Sambuc template class basic_ostream<char>; 35*4684ddb6SLionel Sambuc template class basic_ostream<wchar_t>; 36*4684ddb6SLionel Sambuc 37*4684ddb6SLionel Sambuc template class basic_iostream<char>; 38*4684ddb6SLionel Sambuc 39*4684ddb6SLionel Sambuc class _LIBCPP_HIDDEN __iostream_category 40*4684ddb6SLionel Sambuc : public __do_message 41*4684ddb6SLionel Sambuc { 42*4684ddb6SLionel Sambuc public: 43*4684ddb6SLionel Sambuc virtual const char* name() const _NOEXCEPT; 44*4684ddb6SLionel Sambuc virtual string message(int ev) const; 45*4684ddb6SLionel Sambuc }; 46*4684ddb6SLionel Sambuc 47*4684ddb6SLionel Sambuc const char* 48*4684ddb6SLionel Sambuc __iostream_category::name() const _NOEXCEPT 49*4684ddb6SLionel Sambuc { 50*4684ddb6SLionel Sambuc return "iostream"; 51*4684ddb6SLionel Sambuc } 52*4684ddb6SLionel Sambuc 53*4684ddb6SLionel Sambuc string 54*4684ddb6SLionel Sambuc __iostream_category::message(int ev) const 55*4684ddb6SLionel Sambuc { 56*4684ddb6SLionel Sambuc if (ev != static_cast<int>(io_errc::stream) 57*4684ddb6SLionel Sambuc #ifdef ELAST 58*4684ddb6SLionel Sambuc && ev <= ELAST 59*4684ddb6SLionel Sambuc #endif 60*4684ddb6SLionel Sambuc ) 61*4684ddb6SLionel Sambuc return __do_message::message(ev); 62*4684ddb6SLionel Sambuc return string("unspecified iostream_category error"); 63*4684ddb6SLionel Sambuc } 64*4684ddb6SLionel Sambuc 65*4684ddb6SLionel Sambuc const error_category& 66*4684ddb6SLionel Sambuc iostream_category() _NOEXCEPT 67*4684ddb6SLionel Sambuc { 68*4684ddb6SLionel Sambuc static __iostream_category s; 69*4684ddb6SLionel Sambuc return s; 70*4684ddb6SLionel Sambuc } 71*4684ddb6SLionel Sambuc 72*4684ddb6SLionel Sambuc // ios_base::failure 73*4684ddb6SLionel Sambuc 74*4684ddb6SLionel Sambuc ios_base::failure::failure(const string& msg, const error_code& ec) 75*4684ddb6SLionel Sambuc : system_error(ec, msg) 76*4684ddb6SLionel Sambuc { 77*4684ddb6SLionel Sambuc } 78*4684ddb6SLionel Sambuc 79*4684ddb6SLionel Sambuc ios_base::failure::failure(const char* msg, const error_code& ec) 80*4684ddb6SLionel Sambuc : system_error(ec, msg) 81*4684ddb6SLionel Sambuc { 82*4684ddb6SLionel Sambuc } 83*4684ddb6SLionel Sambuc 84*4684ddb6SLionel Sambuc ios_base::failure::~failure() throw() 85*4684ddb6SLionel Sambuc { 86*4684ddb6SLionel Sambuc } 87*4684ddb6SLionel Sambuc 88*4684ddb6SLionel Sambuc // ios_base locale 89*4684ddb6SLionel Sambuc 90*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::boolalpha; 91*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::dec; 92*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::fixed; 93*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::hex; 94*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::internal; 95*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::left; 96*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::oct; 97*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::right; 98*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::scientific; 99*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showbase; 100*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showpoint; 101*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showpos; 102*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::skipws; 103*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::unitbuf; 104*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::uppercase; 105*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::adjustfield; 106*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::basefield; 107*4684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::floatfield; 108*4684ddb6SLionel Sambuc 109*4684ddb6SLionel Sambuc const ios_base::iostate ios_base::badbit; 110*4684ddb6SLionel Sambuc const ios_base::iostate ios_base::eofbit; 111*4684ddb6SLionel Sambuc const ios_base::iostate ios_base::failbit; 112*4684ddb6SLionel Sambuc const ios_base::iostate ios_base::goodbit; 113*4684ddb6SLionel Sambuc 114*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::app; 115*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::ate; 116*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::binary; 117*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::in; 118*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::out; 119*4684ddb6SLionel Sambuc const ios_base::openmode ios_base::trunc; 120*4684ddb6SLionel Sambuc 121*4684ddb6SLionel Sambuc void 122*4684ddb6SLionel Sambuc ios_base::__call_callbacks(event ev) 123*4684ddb6SLionel Sambuc { 124*4684ddb6SLionel Sambuc for (size_t i = __event_size_; i;) 125*4684ddb6SLionel Sambuc { 126*4684ddb6SLionel Sambuc --i; 127*4684ddb6SLionel Sambuc __fn_[i](ev, *this, __index_[i]); 128*4684ddb6SLionel Sambuc } 129*4684ddb6SLionel Sambuc } 130*4684ddb6SLionel Sambuc 131*4684ddb6SLionel Sambuc // locale 132*4684ddb6SLionel Sambuc 133*4684ddb6SLionel Sambuc locale 134*4684ddb6SLionel Sambuc ios_base::imbue(const locale& newloc) 135*4684ddb6SLionel Sambuc { 136*4684ddb6SLionel Sambuc static_assert(sizeof(locale) == sizeof(__loc_), ""); 137*4684ddb6SLionel Sambuc locale& loc_storage = *(locale*)&__loc_; 138*4684ddb6SLionel Sambuc locale oldloc = loc_storage; 139*4684ddb6SLionel Sambuc loc_storage = newloc; 140*4684ddb6SLionel Sambuc __call_callbacks(imbue_event); 141*4684ddb6SLionel Sambuc return oldloc; 142*4684ddb6SLionel Sambuc } 143*4684ddb6SLionel Sambuc 144*4684ddb6SLionel Sambuc locale 145*4684ddb6SLionel Sambuc ios_base::getloc() const 146*4684ddb6SLionel Sambuc { 147*4684ddb6SLionel Sambuc const locale& loc_storage = *(locale*)&__loc_; 148*4684ddb6SLionel Sambuc return loc_storage; 149*4684ddb6SLionel Sambuc } 150*4684ddb6SLionel Sambuc 151*4684ddb6SLionel Sambuc // xalloc 152*4684ddb6SLionel Sambuc #if __has_feature(cxx_atomic) 153*4684ddb6SLionel Sambuc atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0); 154*4684ddb6SLionel Sambuc #else 155*4684ddb6SLionel Sambuc int ios_base::__xindex_ = 0; 156*4684ddb6SLionel Sambuc #endif 157*4684ddb6SLionel Sambuc 158*4684ddb6SLionel Sambuc int 159*4684ddb6SLionel Sambuc ios_base::xalloc() 160*4684ddb6SLionel Sambuc { 161*4684ddb6SLionel Sambuc return __xindex_++; 162*4684ddb6SLionel Sambuc } 163*4684ddb6SLionel Sambuc 164*4684ddb6SLionel Sambuc long& 165*4684ddb6SLionel Sambuc ios_base::iword(int index) 166*4684ddb6SLionel Sambuc { 167*4684ddb6SLionel Sambuc size_t req_size = static_cast<size_t>(index)+1; 168*4684ddb6SLionel Sambuc if (req_size > __iarray_cap_) 169*4684ddb6SLionel Sambuc { 170*4684ddb6SLionel Sambuc size_t newcap; 171*4684ddb6SLionel Sambuc const size_t mx = std::numeric_limits<size_t>::max(); 172*4684ddb6SLionel Sambuc if (req_size < mx/2) 173*4684ddb6SLionel Sambuc newcap = _VSTD::max(2 * __iarray_cap_, req_size); 174*4684ddb6SLionel Sambuc else 175*4684ddb6SLionel Sambuc newcap = mx; 176*4684ddb6SLionel Sambuc long* iarray = (long*)realloc(__iarray_, newcap * sizeof(long)); 177*4684ddb6SLionel Sambuc if (iarray == 0) 178*4684ddb6SLionel Sambuc { 179*4684ddb6SLionel Sambuc setstate(badbit); 180*4684ddb6SLionel Sambuc static long error; 181*4684ddb6SLionel Sambuc error = 0; 182*4684ddb6SLionel Sambuc return error; 183*4684ddb6SLionel Sambuc } 184*4684ddb6SLionel Sambuc __iarray_ = iarray; 185*4684ddb6SLionel Sambuc for (long* p = __iarray_ + __iarray_size_; __iarray_cap_ < newcap; ++__iarray_cap_, ++p) 186*4684ddb6SLionel Sambuc *p = 0; 187*4684ddb6SLionel Sambuc } 188*4684ddb6SLionel Sambuc __iarray_size_ = max<size_t>(__iarray_size_, req_size); 189*4684ddb6SLionel Sambuc return __iarray_[index]; 190*4684ddb6SLionel Sambuc } 191*4684ddb6SLionel Sambuc 192*4684ddb6SLionel Sambuc void*& 193*4684ddb6SLionel Sambuc ios_base::pword(int index) 194*4684ddb6SLionel Sambuc { 195*4684ddb6SLionel Sambuc size_t req_size = static_cast<size_t>(index)+1; 196*4684ddb6SLionel Sambuc if (req_size > __parray_cap_) 197*4684ddb6SLionel Sambuc { 198*4684ddb6SLionel Sambuc size_t newcap; 199*4684ddb6SLionel Sambuc const size_t mx = std::numeric_limits<size_t>::max(); 200*4684ddb6SLionel Sambuc if (req_size < mx/2) 201*4684ddb6SLionel Sambuc newcap = _VSTD::max(2 * __parray_cap_, req_size); 202*4684ddb6SLionel Sambuc else 203*4684ddb6SLionel Sambuc newcap = mx; 204*4684ddb6SLionel Sambuc void** parray = (void**)realloc(__parray_, newcap * sizeof(void*)); 205*4684ddb6SLionel Sambuc if (parray == 0) 206*4684ddb6SLionel Sambuc { 207*4684ddb6SLionel Sambuc setstate(badbit); 208*4684ddb6SLionel Sambuc static void* error; 209*4684ddb6SLionel Sambuc error = 0; 210*4684ddb6SLionel Sambuc return error; 211*4684ddb6SLionel Sambuc } 212*4684ddb6SLionel Sambuc __parray_ = parray; 213*4684ddb6SLionel Sambuc for (void** p = __parray_ + __parray_size_; __parray_cap_ < newcap; ++__parray_cap_, ++p) 214*4684ddb6SLionel Sambuc *p = 0; 215*4684ddb6SLionel Sambuc } 216*4684ddb6SLionel Sambuc __parray_size_ = max<size_t>(__parray_size_, req_size); 217*4684ddb6SLionel Sambuc return __parray_[index]; 218*4684ddb6SLionel Sambuc } 219*4684ddb6SLionel Sambuc 220*4684ddb6SLionel Sambuc // register_callback 221*4684ddb6SLionel Sambuc 222*4684ddb6SLionel Sambuc void 223*4684ddb6SLionel Sambuc ios_base::register_callback(event_callback fn, int index) 224*4684ddb6SLionel Sambuc { 225*4684ddb6SLionel Sambuc size_t req_size = __event_size_ + 1; 226*4684ddb6SLionel Sambuc if (req_size > __event_cap_) 227*4684ddb6SLionel Sambuc { 228*4684ddb6SLionel Sambuc size_t newcap; 229*4684ddb6SLionel Sambuc const size_t mx = std::numeric_limits<size_t>::max(); 230*4684ddb6SLionel Sambuc if (req_size < mx/2) 231*4684ddb6SLionel Sambuc newcap = _VSTD::max(2 * __event_cap_, req_size); 232*4684ddb6SLionel Sambuc else 233*4684ddb6SLionel Sambuc newcap = mx; 234*4684ddb6SLionel Sambuc event_callback* fns = (event_callback*)realloc(__fn_, newcap * sizeof(event_callback)); 235*4684ddb6SLionel Sambuc if (fns == 0) 236*4684ddb6SLionel Sambuc setstate(badbit); 237*4684ddb6SLionel Sambuc __fn_ = fns; 238*4684ddb6SLionel Sambuc int* indxs = (int*)realloc(__index_, newcap * sizeof(int)); 239*4684ddb6SLionel Sambuc if (indxs == 0) 240*4684ddb6SLionel Sambuc setstate(badbit); 241*4684ddb6SLionel Sambuc __index_ = indxs; 242*4684ddb6SLionel Sambuc } 243*4684ddb6SLionel Sambuc __fn_[__event_size_] = fn; 244*4684ddb6SLionel Sambuc __index_[__event_size_] = index; 245*4684ddb6SLionel Sambuc ++__event_size_; 246*4684ddb6SLionel Sambuc } 247*4684ddb6SLionel Sambuc 248*4684ddb6SLionel Sambuc ios_base::~ios_base() 249*4684ddb6SLionel Sambuc { 250*4684ddb6SLionel Sambuc __call_callbacks(erase_event); 251*4684ddb6SLionel Sambuc locale& loc_storage = *(locale*)&__loc_; 252*4684ddb6SLionel Sambuc loc_storage.~locale(); 253*4684ddb6SLionel Sambuc free(__fn_); 254*4684ddb6SLionel Sambuc free(__index_); 255*4684ddb6SLionel Sambuc free(__iarray_); 256*4684ddb6SLionel Sambuc free(__parray_); 257*4684ddb6SLionel Sambuc } 258*4684ddb6SLionel Sambuc 259*4684ddb6SLionel Sambuc // iostate 260*4684ddb6SLionel Sambuc 261*4684ddb6SLionel Sambuc void 262*4684ddb6SLionel Sambuc ios_base::clear(iostate state) 263*4684ddb6SLionel Sambuc { 264*4684ddb6SLionel Sambuc if (__rdbuf_) 265*4684ddb6SLionel Sambuc __rdstate_ = state; 266*4684ddb6SLionel Sambuc else 267*4684ddb6SLionel Sambuc __rdstate_ = state | badbit; 268*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 269*4684ddb6SLionel Sambuc if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0) 270*4684ddb6SLionel Sambuc throw failure("ios_base::clear"); 271*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 272*4684ddb6SLionel Sambuc } 273*4684ddb6SLionel Sambuc 274*4684ddb6SLionel Sambuc // init 275*4684ddb6SLionel Sambuc 276*4684ddb6SLionel Sambuc void 277*4684ddb6SLionel Sambuc ios_base::init(void* sb) 278*4684ddb6SLionel Sambuc { 279*4684ddb6SLionel Sambuc __rdbuf_ = sb; 280*4684ddb6SLionel Sambuc __rdstate_ = __rdbuf_ ? goodbit : badbit; 281*4684ddb6SLionel Sambuc __exceptions_ = goodbit; 282*4684ddb6SLionel Sambuc __fmtflags_ = skipws | dec; 283*4684ddb6SLionel Sambuc __width_ = 0; 284*4684ddb6SLionel Sambuc __precision_ = 6; 285*4684ddb6SLionel Sambuc __fn_ = 0; 286*4684ddb6SLionel Sambuc __index_ = 0; 287*4684ddb6SLionel Sambuc __event_size_ = 0; 288*4684ddb6SLionel Sambuc __event_cap_ = 0; 289*4684ddb6SLionel Sambuc __iarray_ = 0; 290*4684ddb6SLionel Sambuc __iarray_size_ = 0; 291*4684ddb6SLionel Sambuc __iarray_cap_ = 0; 292*4684ddb6SLionel Sambuc __parray_ = 0; 293*4684ddb6SLionel Sambuc __parray_size_ = 0; 294*4684ddb6SLionel Sambuc __parray_cap_ = 0; 295*4684ddb6SLionel Sambuc ::new(&__loc_) locale; 296*4684ddb6SLionel Sambuc } 297*4684ddb6SLionel Sambuc 298*4684ddb6SLionel Sambuc void 299*4684ddb6SLionel Sambuc ios_base::copyfmt(const ios_base& rhs) 300*4684ddb6SLionel Sambuc { 301*4684ddb6SLionel Sambuc // If we can't acquire the needed resources, throw bad_alloc (can't set badbit) 302*4684ddb6SLionel Sambuc // Don't alter *this until all needed resources are aquired 303*4684ddb6SLionel Sambuc unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free); 304*4684ddb6SLionel Sambuc unique_ptr<int, void (*)(void*)> new_ints(0, free); 305*4684ddb6SLionel Sambuc unique_ptr<long, void (*)(void*)> new_longs(0, free); 306*4684ddb6SLionel Sambuc unique_ptr<void*, void (*)(void*)> new_pointers(0, free); 307*4684ddb6SLionel Sambuc if (__event_cap_ < rhs.__event_size_) 308*4684ddb6SLionel Sambuc { 309*4684ddb6SLionel Sambuc new_callbacks.reset((event_callback*)malloc(sizeof(event_callback) * rhs.__event_size_)); 310*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 311*4684ddb6SLionel Sambuc if (!new_callbacks) 312*4684ddb6SLionel Sambuc throw bad_alloc(); 313*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 314*4684ddb6SLionel Sambuc new_ints.reset((int*)malloc(sizeof(int) * rhs.__event_size_)); 315*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 316*4684ddb6SLionel Sambuc if (!new_ints) 317*4684ddb6SLionel Sambuc throw bad_alloc(); 318*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 319*4684ddb6SLionel Sambuc } 320*4684ddb6SLionel Sambuc if (__iarray_cap_ < rhs.__iarray_size_) 321*4684ddb6SLionel Sambuc { 322*4684ddb6SLionel Sambuc new_longs.reset((long*)malloc(sizeof(long) * rhs.__iarray_size_)); 323*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 324*4684ddb6SLionel Sambuc if (!new_longs) 325*4684ddb6SLionel Sambuc throw bad_alloc(); 326*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 327*4684ddb6SLionel Sambuc } 328*4684ddb6SLionel Sambuc if (__parray_cap_ < rhs.__parray_size_) 329*4684ddb6SLionel Sambuc { 330*4684ddb6SLionel Sambuc new_pointers.reset((void**)malloc(sizeof(void*) * rhs.__parray_size_)); 331*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 332*4684ddb6SLionel Sambuc if (!new_pointers) 333*4684ddb6SLionel Sambuc throw bad_alloc(); 334*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 335*4684ddb6SLionel Sambuc } 336*4684ddb6SLionel Sambuc // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_ 337*4684ddb6SLionel Sambuc __fmtflags_ = rhs.__fmtflags_; 338*4684ddb6SLionel Sambuc __precision_ = rhs.__precision_; 339*4684ddb6SLionel Sambuc __width_ = rhs.__width_; 340*4684ddb6SLionel Sambuc locale& lhs_loc = *(locale*)&__loc_; 341*4684ddb6SLionel Sambuc locale& rhs_loc = *(locale*)&rhs.__loc_; 342*4684ddb6SLionel Sambuc lhs_loc = rhs_loc; 343*4684ddb6SLionel Sambuc if (__event_cap_ < rhs.__event_size_) 344*4684ddb6SLionel Sambuc { 345*4684ddb6SLionel Sambuc free(__fn_); 346*4684ddb6SLionel Sambuc __fn_ = new_callbacks.release(); 347*4684ddb6SLionel Sambuc free(__index_); 348*4684ddb6SLionel Sambuc __index_ = new_ints.release(); 349*4684ddb6SLionel Sambuc __event_cap_ = rhs.__event_size_; 350*4684ddb6SLionel Sambuc } 351*4684ddb6SLionel Sambuc for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_) 352*4684ddb6SLionel Sambuc { 353*4684ddb6SLionel Sambuc __fn_[__event_size_] = rhs.__fn_[__event_size_]; 354*4684ddb6SLionel Sambuc __index_[__event_size_] = rhs.__index_[__event_size_]; 355*4684ddb6SLionel Sambuc } 356*4684ddb6SLionel Sambuc if (__iarray_cap_ < rhs.__iarray_size_) 357*4684ddb6SLionel Sambuc { 358*4684ddb6SLionel Sambuc free(__iarray_); 359*4684ddb6SLionel Sambuc __iarray_ = new_longs.release(); 360*4684ddb6SLionel Sambuc __iarray_cap_ = rhs.__iarray_size_; 361*4684ddb6SLionel Sambuc } 362*4684ddb6SLionel Sambuc for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_) 363*4684ddb6SLionel Sambuc __iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_]; 364*4684ddb6SLionel Sambuc if (__parray_cap_ < rhs.__parray_size_) 365*4684ddb6SLionel Sambuc { 366*4684ddb6SLionel Sambuc free(__parray_); 367*4684ddb6SLionel Sambuc __parray_ = new_pointers.release(); 368*4684ddb6SLionel Sambuc __parray_cap_ = rhs.__parray_size_; 369*4684ddb6SLionel Sambuc } 370*4684ddb6SLionel Sambuc for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_) 371*4684ddb6SLionel Sambuc __parray_[__parray_size_] = rhs.__parray_[__parray_size_]; 372*4684ddb6SLionel Sambuc } 373*4684ddb6SLionel Sambuc 374*4684ddb6SLionel Sambuc void 375*4684ddb6SLionel Sambuc ios_base::move(ios_base& rhs) 376*4684ddb6SLionel Sambuc { 377*4684ddb6SLionel Sambuc // *this is uninitialized 378*4684ddb6SLionel Sambuc __fmtflags_ = rhs.__fmtflags_; 379*4684ddb6SLionel Sambuc __precision_ = rhs.__precision_; 380*4684ddb6SLionel Sambuc __width_ = rhs.__width_; 381*4684ddb6SLionel Sambuc __rdstate_ = rhs.__rdstate_; 382*4684ddb6SLionel Sambuc __exceptions_ = rhs.__exceptions_; 383*4684ddb6SLionel Sambuc __rdbuf_ = 0; 384*4684ddb6SLionel Sambuc locale& rhs_loc = *(locale*)&rhs.__loc_; 385*4684ddb6SLionel Sambuc ::new(&__loc_) locale(rhs_loc); 386*4684ddb6SLionel Sambuc __fn_ = rhs.__fn_; 387*4684ddb6SLionel Sambuc rhs.__fn_ = 0; 388*4684ddb6SLionel Sambuc __index_ = rhs.__index_; 389*4684ddb6SLionel Sambuc rhs.__index_ = 0; 390*4684ddb6SLionel Sambuc __event_size_ = rhs.__event_size_; 391*4684ddb6SLionel Sambuc rhs.__event_size_ = 0; 392*4684ddb6SLionel Sambuc __event_cap_ = rhs.__event_cap_; 393*4684ddb6SLionel Sambuc rhs.__event_cap_ = 0; 394*4684ddb6SLionel Sambuc __iarray_ = rhs.__iarray_; 395*4684ddb6SLionel Sambuc rhs.__iarray_ = 0; 396*4684ddb6SLionel Sambuc __iarray_size_ = rhs.__iarray_size_; 397*4684ddb6SLionel Sambuc rhs.__iarray_size_ = 0; 398*4684ddb6SLionel Sambuc __iarray_cap_ = rhs.__iarray_cap_; 399*4684ddb6SLionel Sambuc rhs.__iarray_cap_ = 0; 400*4684ddb6SLionel Sambuc __parray_ = rhs.__parray_; 401*4684ddb6SLionel Sambuc rhs.__parray_ = 0; 402*4684ddb6SLionel Sambuc __parray_size_ = rhs.__parray_size_; 403*4684ddb6SLionel Sambuc rhs.__parray_size_ = 0; 404*4684ddb6SLionel Sambuc __parray_cap_ = rhs.__parray_cap_; 405*4684ddb6SLionel Sambuc rhs.__parray_cap_ = 0; 406*4684ddb6SLionel Sambuc } 407*4684ddb6SLionel Sambuc 408*4684ddb6SLionel Sambuc void 409*4684ddb6SLionel Sambuc ios_base::swap(ios_base& rhs) _NOEXCEPT 410*4684ddb6SLionel Sambuc { 411*4684ddb6SLionel Sambuc _VSTD::swap(__fmtflags_, rhs.__fmtflags_); 412*4684ddb6SLionel Sambuc _VSTD::swap(__precision_, rhs.__precision_); 413*4684ddb6SLionel Sambuc _VSTD::swap(__width_, rhs.__width_); 414*4684ddb6SLionel Sambuc _VSTD::swap(__rdstate_, rhs.__rdstate_); 415*4684ddb6SLionel Sambuc _VSTD::swap(__exceptions_, rhs.__exceptions_); 416*4684ddb6SLionel Sambuc locale& lhs_loc = *(locale*)&__loc_; 417*4684ddb6SLionel Sambuc locale& rhs_loc = *(locale*)&rhs.__loc_; 418*4684ddb6SLionel Sambuc _VSTD::swap(lhs_loc, rhs_loc); 419*4684ddb6SLionel Sambuc _VSTD::swap(__fn_, rhs.__fn_); 420*4684ddb6SLionel Sambuc _VSTD::swap(__index_, rhs.__index_); 421*4684ddb6SLionel Sambuc _VSTD::swap(__event_size_, rhs.__event_size_); 422*4684ddb6SLionel Sambuc _VSTD::swap(__event_cap_, rhs.__event_cap_); 423*4684ddb6SLionel Sambuc _VSTD::swap(__iarray_, rhs.__iarray_); 424*4684ddb6SLionel Sambuc _VSTD::swap(__iarray_size_, rhs.__iarray_size_); 425*4684ddb6SLionel Sambuc _VSTD::swap(__iarray_cap_, rhs.__iarray_cap_); 426*4684ddb6SLionel Sambuc _VSTD::swap(__parray_, rhs.__parray_); 427*4684ddb6SLionel Sambuc _VSTD::swap(__parray_size_, rhs.__parray_size_); 428*4684ddb6SLionel Sambuc _VSTD::swap(__parray_cap_, rhs.__parray_cap_); 429*4684ddb6SLionel Sambuc } 430*4684ddb6SLionel Sambuc 431*4684ddb6SLionel Sambuc void 432*4684ddb6SLionel Sambuc ios_base::__set_badbit_and_consider_rethrow() 433*4684ddb6SLionel Sambuc { 434*4684ddb6SLionel Sambuc __rdstate_ |= badbit; 435*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 436*4684ddb6SLionel Sambuc if (__exceptions_ & badbit) 437*4684ddb6SLionel Sambuc throw; 438*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 439*4684ddb6SLionel Sambuc } 440*4684ddb6SLionel Sambuc 441*4684ddb6SLionel Sambuc void 442*4684ddb6SLionel Sambuc ios_base::__set_failbit_and_consider_rethrow() 443*4684ddb6SLionel Sambuc { 444*4684ddb6SLionel Sambuc __rdstate_ |= failbit; 445*4684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS 446*4684ddb6SLionel Sambuc if (__exceptions_ & failbit) 447*4684ddb6SLionel Sambuc throw; 448*4684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS 449*4684ddb6SLionel Sambuc } 450*4684ddb6SLionel Sambuc 451*4684ddb6SLionel Sambuc bool 452*4684ddb6SLionel Sambuc ios_base::sync_with_stdio(bool sync) 453*4684ddb6SLionel Sambuc { 454*4684ddb6SLionel Sambuc static bool previous_state = true; 455*4684ddb6SLionel Sambuc bool r = previous_state; 456*4684ddb6SLionel Sambuc previous_state = sync; 457*4684ddb6SLionel Sambuc return r; 458*4684ddb6SLionel Sambuc } 459*4684ddb6SLionel Sambuc 460*4684ddb6SLionel Sambuc _LIBCPP_END_NAMESPACE_STD 461