14684ddb6SLionel Sambuc //===-------------------------- ios.cpp -----------------------------------===//
24684ddb6SLionel Sambuc //
34684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
44684ddb6SLionel Sambuc //
54684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
64684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
74684ddb6SLionel Sambuc //
84684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
94684ddb6SLionel Sambuc
10*0a6a1f1dSLionel Sambuc #include "__config"
114684ddb6SLionel Sambuc
124684ddb6SLionel Sambuc #include "ios"
13*0a6a1f1dSLionel Sambuc
14*0a6a1f1dSLionel Sambuc #include <stdlib.h>
15*0a6a1f1dSLionel Sambuc
164684ddb6SLionel Sambuc #include "__locale"
174684ddb6SLionel Sambuc #include "algorithm"
18*0a6a1f1dSLionel Sambuc #include "include/config_elast.h"
19*0a6a1f1dSLionel Sambuc #include "istream"
20*0a6a1f1dSLionel Sambuc #include "limits"
214684ddb6SLionel Sambuc #include "memory"
224684ddb6SLionel Sambuc #include "new"
23*0a6a1f1dSLionel Sambuc #include "streambuf"
24*0a6a1f1dSLionel Sambuc #include "string"
254684ddb6SLionel Sambuc
264684ddb6SLionel Sambuc _LIBCPP_BEGIN_NAMESPACE_STD
274684ddb6SLionel Sambuc
284684ddb6SLionel Sambuc template class basic_ios<char>;
294684ddb6SLionel Sambuc template class basic_ios<wchar_t>;
304684ddb6SLionel Sambuc
314684ddb6SLionel Sambuc template class basic_streambuf<char>;
324684ddb6SLionel Sambuc template class basic_streambuf<wchar_t>;
334684ddb6SLionel Sambuc
344684ddb6SLionel Sambuc template class basic_istream<char>;
354684ddb6SLionel Sambuc template class basic_istream<wchar_t>;
364684ddb6SLionel Sambuc
374684ddb6SLionel Sambuc template class basic_ostream<char>;
384684ddb6SLionel Sambuc template class basic_ostream<wchar_t>;
394684ddb6SLionel Sambuc
404684ddb6SLionel Sambuc template class basic_iostream<char>;
414684ddb6SLionel Sambuc
424684ddb6SLionel Sambuc class _LIBCPP_HIDDEN __iostream_category
434684ddb6SLionel Sambuc : public __do_message
444684ddb6SLionel Sambuc {
454684ddb6SLionel Sambuc public:
464684ddb6SLionel Sambuc virtual const char* name() const _NOEXCEPT;
474684ddb6SLionel Sambuc virtual string message(int ev) const;
484684ddb6SLionel Sambuc };
494684ddb6SLionel Sambuc
504684ddb6SLionel Sambuc const char*
name() const514684ddb6SLionel Sambuc __iostream_category::name() const _NOEXCEPT
524684ddb6SLionel Sambuc {
534684ddb6SLionel Sambuc return "iostream";
544684ddb6SLionel Sambuc }
554684ddb6SLionel Sambuc
564684ddb6SLionel Sambuc string
message(int ev) const574684ddb6SLionel Sambuc __iostream_category::message(int ev) const
584684ddb6SLionel Sambuc {
594684ddb6SLionel Sambuc if (ev != static_cast<int>(io_errc::stream)
60*0a6a1f1dSLionel Sambuc #ifdef _LIBCPP_ELAST
61*0a6a1f1dSLionel Sambuc && ev <= _LIBCPP_ELAST
62*0a6a1f1dSLionel Sambuc #endif // _LIBCPP_ELAST
634684ddb6SLionel Sambuc )
644684ddb6SLionel Sambuc return __do_message::message(ev);
654684ddb6SLionel Sambuc return string("unspecified iostream_category error");
664684ddb6SLionel Sambuc }
674684ddb6SLionel Sambuc
684684ddb6SLionel Sambuc const error_category&
iostream_category()694684ddb6SLionel Sambuc iostream_category() _NOEXCEPT
704684ddb6SLionel Sambuc {
714684ddb6SLionel Sambuc static __iostream_category s;
724684ddb6SLionel Sambuc return s;
734684ddb6SLionel Sambuc }
744684ddb6SLionel Sambuc
754684ddb6SLionel Sambuc // ios_base::failure
764684ddb6SLionel Sambuc
failure(const string & msg,const error_code & ec)774684ddb6SLionel Sambuc ios_base::failure::failure(const string& msg, const error_code& ec)
784684ddb6SLionel Sambuc : system_error(ec, msg)
794684ddb6SLionel Sambuc {
804684ddb6SLionel Sambuc }
814684ddb6SLionel Sambuc
failure(const char * msg,const error_code & ec)824684ddb6SLionel Sambuc ios_base::failure::failure(const char* msg, const error_code& ec)
834684ddb6SLionel Sambuc : system_error(ec, msg)
844684ddb6SLionel Sambuc {
854684ddb6SLionel Sambuc }
864684ddb6SLionel Sambuc
~failure()874684ddb6SLionel Sambuc ios_base::failure::~failure() throw()
884684ddb6SLionel Sambuc {
894684ddb6SLionel Sambuc }
904684ddb6SLionel Sambuc
914684ddb6SLionel Sambuc // ios_base locale
924684ddb6SLionel Sambuc
934684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::boolalpha;
944684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::dec;
954684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::fixed;
964684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::hex;
974684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::internal;
984684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::left;
994684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::oct;
1004684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::right;
1014684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::scientific;
1024684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showbase;
1034684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showpoint;
1044684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::showpos;
1054684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::skipws;
1064684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::unitbuf;
1074684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::uppercase;
1084684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::adjustfield;
1094684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::basefield;
1104684ddb6SLionel Sambuc const ios_base::fmtflags ios_base::floatfield;
1114684ddb6SLionel Sambuc
1124684ddb6SLionel Sambuc const ios_base::iostate ios_base::badbit;
1134684ddb6SLionel Sambuc const ios_base::iostate ios_base::eofbit;
1144684ddb6SLionel Sambuc const ios_base::iostate ios_base::failbit;
1154684ddb6SLionel Sambuc const ios_base::iostate ios_base::goodbit;
1164684ddb6SLionel Sambuc
1174684ddb6SLionel Sambuc const ios_base::openmode ios_base::app;
1184684ddb6SLionel Sambuc const ios_base::openmode ios_base::ate;
1194684ddb6SLionel Sambuc const ios_base::openmode ios_base::binary;
1204684ddb6SLionel Sambuc const ios_base::openmode ios_base::in;
1214684ddb6SLionel Sambuc const ios_base::openmode ios_base::out;
1224684ddb6SLionel Sambuc const ios_base::openmode ios_base::trunc;
1234684ddb6SLionel Sambuc
1244684ddb6SLionel Sambuc void
__call_callbacks(event ev)1254684ddb6SLionel Sambuc ios_base::__call_callbacks(event ev)
1264684ddb6SLionel Sambuc {
1274684ddb6SLionel Sambuc for (size_t i = __event_size_; i;)
1284684ddb6SLionel Sambuc {
1294684ddb6SLionel Sambuc --i;
1304684ddb6SLionel Sambuc __fn_[i](ev, *this, __index_[i]);
1314684ddb6SLionel Sambuc }
1324684ddb6SLionel Sambuc }
1334684ddb6SLionel Sambuc
1344684ddb6SLionel Sambuc // locale
1354684ddb6SLionel Sambuc
1364684ddb6SLionel Sambuc locale
imbue(const locale & newloc)1374684ddb6SLionel Sambuc ios_base::imbue(const locale& newloc)
1384684ddb6SLionel Sambuc {
1394684ddb6SLionel Sambuc static_assert(sizeof(locale) == sizeof(__loc_), "");
140*0a6a1f1dSLionel Sambuc locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
1414684ddb6SLionel Sambuc locale oldloc = loc_storage;
1424684ddb6SLionel Sambuc loc_storage = newloc;
1434684ddb6SLionel Sambuc __call_callbacks(imbue_event);
1444684ddb6SLionel Sambuc return oldloc;
1454684ddb6SLionel Sambuc }
1464684ddb6SLionel Sambuc
1474684ddb6SLionel Sambuc locale
getloc() const1484684ddb6SLionel Sambuc ios_base::getloc() const
1494684ddb6SLionel Sambuc {
150*0a6a1f1dSLionel Sambuc const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
1514684ddb6SLionel Sambuc return loc_storage;
1524684ddb6SLionel Sambuc }
1534684ddb6SLionel Sambuc
1544684ddb6SLionel Sambuc // xalloc
155*0a6a1f1dSLionel Sambuc #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
1564684ddb6SLionel Sambuc atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
1574684ddb6SLionel Sambuc #else
1584684ddb6SLionel Sambuc int ios_base::__xindex_ = 0;
1594684ddb6SLionel Sambuc #endif
1604684ddb6SLionel Sambuc
161*0a6a1f1dSLionel Sambuc template <typename _Tp>
__ios_new_cap(size_t __req_size,size_t __current_cap)162*0a6a1f1dSLionel Sambuc static size_t __ios_new_cap(size_t __req_size, size_t __current_cap)
163*0a6a1f1dSLionel Sambuc { // Precondition: __req_size > __current_cap
164*0a6a1f1dSLionel Sambuc const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
165*0a6a1f1dSLionel Sambuc if (__req_size < mx/2)
166*0a6a1f1dSLionel Sambuc return _VSTD::max(2 * __current_cap, __req_size);
167*0a6a1f1dSLionel Sambuc else
168*0a6a1f1dSLionel Sambuc return mx;
169*0a6a1f1dSLionel Sambuc }
170*0a6a1f1dSLionel Sambuc
1714684ddb6SLionel Sambuc int
xalloc()1724684ddb6SLionel Sambuc ios_base::xalloc()
1734684ddb6SLionel Sambuc {
1744684ddb6SLionel Sambuc return __xindex_++;
1754684ddb6SLionel Sambuc }
1764684ddb6SLionel Sambuc
1774684ddb6SLionel Sambuc long&
iword(int index)1784684ddb6SLionel Sambuc ios_base::iword(int index)
1794684ddb6SLionel Sambuc {
1804684ddb6SLionel Sambuc size_t req_size = static_cast<size_t>(index)+1;
1814684ddb6SLionel Sambuc if (req_size > __iarray_cap_)
1824684ddb6SLionel Sambuc {
183*0a6a1f1dSLionel Sambuc size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
184*0a6a1f1dSLionel Sambuc long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
1854684ddb6SLionel Sambuc if (iarray == 0)
1864684ddb6SLionel Sambuc {
1874684ddb6SLionel Sambuc setstate(badbit);
1884684ddb6SLionel Sambuc static long error;
1894684ddb6SLionel Sambuc error = 0;
1904684ddb6SLionel Sambuc return error;
1914684ddb6SLionel Sambuc }
1924684ddb6SLionel Sambuc __iarray_ = iarray;
193*0a6a1f1dSLionel Sambuc for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
1944684ddb6SLionel Sambuc *p = 0;
195*0a6a1f1dSLionel Sambuc __iarray_cap_ = newcap;
1964684ddb6SLionel Sambuc }
1974684ddb6SLionel Sambuc __iarray_size_ = max<size_t>(__iarray_size_, req_size);
1984684ddb6SLionel Sambuc return __iarray_[index];
1994684ddb6SLionel Sambuc }
2004684ddb6SLionel Sambuc
2014684ddb6SLionel Sambuc void*&
pword(int index)2024684ddb6SLionel Sambuc ios_base::pword(int index)
2034684ddb6SLionel Sambuc {
2044684ddb6SLionel Sambuc size_t req_size = static_cast<size_t>(index)+1;
2054684ddb6SLionel Sambuc if (req_size > __parray_cap_)
2064684ddb6SLionel Sambuc {
207*0a6a1f1dSLionel Sambuc size_t newcap = __ios_new_cap<void *>(req_size, __iarray_cap_);
208*0a6a1f1dSLionel Sambuc void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void *)));
2094684ddb6SLionel Sambuc if (parray == 0)
2104684ddb6SLionel Sambuc {
2114684ddb6SLionel Sambuc setstate(badbit);
2124684ddb6SLionel Sambuc static void* error;
2134684ddb6SLionel Sambuc error = 0;
2144684ddb6SLionel Sambuc return error;
2154684ddb6SLionel Sambuc }
2164684ddb6SLionel Sambuc __parray_ = parray;
217*0a6a1f1dSLionel Sambuc for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
2184684ddb6SLionel Sambuc *p = 0;
219*0a6a1f1dSLionel Sambuc __parray_cap_ = newcap;
2204684ddb6SLionel Sambuc }
2214684ddb6SLionel Sambuc __parray_size_ = max<size_t>(__parray_size_, req_size);
2224684ddb6SLionel Sambuc return __parray_[index];
2234684ddb6SLionel Sambuc }
2244684ddb6SLionel Sambuc
2254684ddb6SLionel Sambuc // register_callback
2264684ddb6SLionel Sambuc
2274684ddb6SLionel Sambuc void
register_callback(event_callback fn,int index)2284684ddb6SLionel Sambuc ios_base::register_callback(event_callback fn, int index)
2294684ddb6SLionel Sambuc {
2304684ddb6SLionel Sambuc size_t req_size = __event_size_ + 1;
2314684ddb6SLionel Sambuc if (req_size > __event_cap_)
2324684ddb6SLionel Sambuc {
233*0a6a1f1dSLionel Sambuc size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
234*0a6a1f1dSLionel Sambuc event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
2354684ddb6SLionel Sambuc if (fns == 0)
2364684ddb6SLionel Sambuc setstate(badbit);
2374684ddb6SLionel Sambuc __fn_ = fns;
238*0a6a1f1dSLionel Sambuc int* indxs = static_cast<int *>(realloc(__index_, newcap * sizeof(int)));
2394684ddb6SLionel Sambuc if (indxs == 0)
2404684ddb6SLionel Sambuc setstate(badbit);
2414684ddb6SLionel Sambuc __index_ = indxs;
242*0a6a1f1dSLionel Sambuc __event_cap_ = newcap;
2434684ddb6SLionel Sambuc }
2444684ddb6SLionel Sambuc __fn_[__event_size_] = fn;
2454684ddb6SLionel Sambuc __index_[__event_size_] = index;
2464684ddb6SLionel Sambuc ++__event_size_;
2474684ddb6SLionel Sambuc }
2484684ddb6SLionel Sambuc
~ios_base()2494684ddb6SLionel Sambuc ios_base::~ios_base()
2504684ddb6SLionel Sambuc {
2514684ddb6SLionel Sambuc __call_callbacks(erase_event);
252*0a6a1f1dSLionel Sambuc locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
2534684ddb6SLionel Sambuc loc_storage.~locale();
2544684ddb6SLionel Sambuc free(__fn_);
2554684ddb6SLionel Sambuc free(__index_);
2564684ddb6SLionel Sambuc free(__iarray_);
2574684ddb6SLionel Sambuc free(__parray_);
2584684ddb6SLionel Sambuc }
2594684ddb6SLionel Sambuc
2604684ddb6SLionel Sambuc // iostate
2614684ddb6SLionel Sambuc
2624684ddb6SLionel Sambuc void
clear(iostate state)2634684ddb6SLionel Sambuc ios_base::clear(iostate state)
2644684ddb6SLionel Sambuc {
2654684ddb6SLionel Sambuc if (__rdbuf_)
2664684ddb6SLionel Sambuc __rdstate_ = state;
2674684ddb6SLionel Sambuc else
2684684ddb6SLionel Sambuc __rdstate_ = state | badbit;
2694684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
2704684ddb6SLionel Sambuc if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
2714684ddb6SLionel Sambuc throw failure("ios_base::clear");
2724684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
2734684ddb6SLionel Sambuc }
2744684ddb6SLionel Sambuc
2754684ddb6SLionel Sambuc // init
2764684ddb6SLionel Sambuc
2774684ddb6SLionel Sambuc void
init(void * sb)2784684ddb6SLionel Sambuc ios_base::init(void* sb)
2794684ddb6SLionel Sambuc {
2804684ddb6SLionel Sambuc __rdbuf_ = sb;
2814684ddb6SLionel Sambuc __rdstate_ = __rdbuf_ ? goodbit : badbit;
2824684ddb6SLionel Sambuc __exceptions_ = goodbit;
2834684ddb6SLionel Sambuc __fmtflags_ = skipws | dec;
2844684ddb6SLionel Sambuc __width_ = 0;
2854684ddb6SLionel Sambuc __precision_ = 6;
2864684ddb6SLionel Sambuc __fn_ = 0;
2874684ddb6SLionel Sambuc __index_ = 0;
2884684ddb6SLionel Sambuc __event_size_ = 0;
2894684ddb6SLionel Sambuc __event_cap_ = 0;
2904684ddb6SLionel Sambuc __iarray_ = 0;
2914684ddb6SLionel Sambuc __iarray_size_ = 0;
2924684ddb6SLionel Sambuc __iarray_cap_ = 0;
2934684ddb6SLionel Sambuc __parray_ = 0;
2944684ddb6SLionel Sambuc __parray_size_ = 0;
2954684ddb6SLionel Sambuc __parray_cap_ = 0;
2964684ddb6SLionel Sambuc ::new(&__loc_) locale;
2974684ddb6SLionel Sambuc }
2984684ddb6SLionel Sambuc
2994684ddb6SLionel Sambuc void
copyfmt(const ios_base & rhs)3004684ddb6SLionel Sambuc ios_base::copyfmt(const ios_base& rhs)
3014684ddb6SLionel Sambuc {
3024684ddb6SLionel Sambuc // If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
303*0a6a1f1dSLionel Sambuc // Don't alter *this until all needed resources are acquired
3044684ddb6SLionel Sambuc unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
3054684ddb6SLionel Sambuc unique_ptr<int, void (*)(void*)> new_ints(0, free);
3064684ddb6SLionel Sambuc unique_ptr<long, void (*)(void*)> new_longs(0, free);
3074684ddb6SLionel Sambuc unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
3084684ddb6SLionel Sambuc if (__event_cap_ < rhs.__event_size_)
3094684ddb6SLionel Sambuc {
310*0a6a1f1dSLionel Sambuc size_t newesize = sizeof(event_callback) * rhs.__event_size_;
311*0a6a1f1dSLionel Sambuc new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
3124684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
3134684ddb6SLionel Sambuc if (!new_callbacks)
3144684ddb6SLionel Sambuc throw bad_alloc();
3154684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
316*0a6a1f1dSLionel Sambuc
317*0a6a1f1dSLionel Sambuc size_t newisize = sizeof(int) * rhs.__event_size_;
318*0a6a1f1dSLionel Sambuc new_ints.reset(static_cast<int *>(malloc(newisize)));
3194684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
3204684ddb6SLionel Sambuc if (!new_ints)
3214684ddb6SLionel Sambuc throw bad_alloc();
3224684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
3234684ddb6SLionel Sambuc }
3244684ddb6SLionel Sambuc if (__iarray_cap_ < rhs.__iarray_size_)
3254684ddb6SLionel Sambuc {
326*0a6a1f1dSLionel Sambuc size_t newsize = sizeof(long) * rhs.__iarray_size_;
327*0a6a1f1dSLionel Sambuc new_longs.reset(static_cast<long*>(malloc(newsize)));
3284684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
3294684ddb6SLionel Sambuc if (!new_longs)
3304684ddb6SLionel Sambuc throw bad_alloc();
3314684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
3324684ddb6SLionel Sambuc }
3334684ddb6SLionel Sambuc if (__parray_cap_ < rhs.__parray_size_)
3344684ddb6SLionel Sambuc {
335*0a6a1f1dSLionel Sambuc size_t newsize = sizeof(void*) * rhs.__parray_size_;
336*0a6a1f1dSLionel Sambuc new_pointers.reset(static_cast<void**>(malloc(newsize)));
3374684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
3384684ddb6SLionel Sambuc if (!new_pointers)
3394684ddb6SLionel Sambuc throw bad_alloc();
3404684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
3414684ddb6SLionel Sambuc }
3424684ddb6SLionel Sambuc // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
3434684ddb6SLionel Sambuc __fmtflags_ = rhs.__fmtflags_;
3444684ddb6SLionel Sambuc __precision_ = rhs.__precision_;
3454684ddb6SLionel Sambuc __width_ = rhs.__width_;
346*0a6a1f1dSLionel Sambuc locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
347*0a6a1f1dSLionel Sambuc const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
3484684ddb6SLionel Sambuc lhs_loc = rhs_loc;
3494684ddb6SLionel Sambuc if (__event_cap_ < rhs.__event_size_)
3504684ddb6SLionel Sambuc {
3514684ddb6SLionel Sambuc free(__fn_);
3524684ddb6SLionel Sambuc __fn_ = new_callbacks.release();
3534684ddb6SLionel Sambuc free(__index_);
3544684ddb6SLionel Sambuc __index_ = new_ints.release();
3554684ddb6SLionel Sambuc __event_cap_ = rhs.__event_size_;
3564684ddb6SLionel Sambuc }
3574684ddb6SLionel Sambuc for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_)
3584684ddb6SLionel Sambuc {
3594684ddb6SLionel Sambuc __fn_[__event_size_] = rhs.__fn_[__event_size_];
3604684ddb6SLionel Sambuc __index_[__event_size_] = rhs.__index_[__event_size_];
3614684ddb6SLionel Sambuc }
3624684ddb6SLionel Sambuc if (__iarray_cap_ < rhs.__iarray_size_)
3634684ddb6SLionel Sambuc {
3644684ddb6SLionel Sambuc free(__iarray_);
3654684ddb6SLionel Sambuc __iarray_ = new_longs.release();
3664684ddb6SLionel Sambuc __iarray_cap_ = rhs.__iarray_size_;
3674684ddb6SLionel Sambuc }
3684684ddb6SLionel Sambuc for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
3694684ddb6SLionel Sambuc __iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
3704684ddb6SLionel Sambuc if (__parray_cap_ < rhs.__parray_size_)
3714684ddb6SLionel Sambuc {
3724684ddb6SLionel Sambuc free(__parray_);
3734684ddb6SLionel Sambuc __parray_ = new_pointers.release();
3744684ddb6SLionel Sambuc __parray_cap_ = rhs.__parray_size_;
3754684ddb6SLionel Sambuc }
3764684ddb6SLionel Sambuc for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
3774684ddb6SLionel Sambuc __parray_[__parray_size_] = rhs.__parray_[__parray_size_];
3784684ddb6SLionel Sambuc }
3794684ddb6SLionel Sambuc
3804684ddb6SLionel Sambuc void
move(ios_base & rhs)3814684ddb6SLionel Sambuc ios_base::move(ios_base& rhs)
3824684ddb6SLionel Sambuc {
3834684ddb6SLionel Sambuc // *this is uninitialized
3844684ddb6SLionel Sambuc __fmtflags_ = rhs.__fmtflags_;
3854684ddb6SLionel Sambuc __precision_ = rhs.__precision_;
3864684ddb6SLionel Sambuc __width_ = rhs.__width_;
3874684ddb6SLionel Sambuc __rdstate_ = rhs.__rdstate_;
3884684ddb6SLionel Sambuc __exceptions_ = rhs.__exceptions_;
3894684ddb6SLionel Sambuc __rdbuf_ = 0;
390*0a6a1f1dSLionel Sambuc locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
3914684ddb6SLionel Sambuc ::new(&__loc_) locale(rhs_loc);
3924684ddb6SLionel Sambuc __fn_ = rhs.__fn_;
3934684ddb6SLionel Sambuc rhs.__fn_ = 0;
3944684ddb6SLionel Sambuc __index_ = rhs.__index_;
3954684ddb6SLionel Sambuc rhs.__index_ = 0;
3964684ddb6SLionel Sambuc __event_size_ = rhs.__event_size_;
3974684ddb6SLionel Sambuc rhs.__event_size_ = 0;
3984684ddb6SLionel Sambuc __event_cap_ = rhs.__event_cap_;
3994684ddb6SLionel Sambuc rhs.__event_cap_ = 0;
4004684ddb6SLionel Sambuc __iarray_ = rhs.__iarray_;
4014684ddb6SLionel Sambuc rhs.__iarray_ = 0;
4024684ddb6SLionel Sambuc __iarray_size_ = rhs.__iarray_size_;
4034684ddb6SLionel Sambuc rhs.__iarray_size_ = 0;
4044684ddb6SLionel Sambuc __iarray_cap_ = rhs.__iarray_cap_;
4054684ddb6SLionel Sambuc rhs.__iarray_cap_ = 0;
4064684ddb6SLionel Sambuc __parray_ = rhs.__parray_;
4074684ddb6SLionel Sambuc rhs.__parray_ = 0;
4084684ddb6SLionel Sambuc __parray_size_ = rhs.__parray_size_;
4094684ddb6SLionel Sambuc rhs.__parray_size_ = 0;
4104684ddb6SLionel Sambuc __parray_cap_ = rhs.__parray_cap_;
4114684ddb6SLionel Sambuc rhs.__parray_cap_ = 0;
4124684ddb6SLionel Sambuc }
4134684ddb6SLionel Sambuc
4144684ddb6SLionel Sambuc void
swap(ios_base & rhs)4154684ddb6SLionel Sambuc ios_base::swap(ios_base& rhs) _NOEXCEPT
4164684ddb6SLionel Sambuc {
4174684ddb6SLionel Sambuc _VSTD::swap(__fmtflags_, rhs.__fmtflags_);
4184684ddb6SLionel Sambuc _VSTD::swap(__precision_, rhs.__precision_);
4194684ddb6SLionel Sambuc _VSTD::swap(__width_, rhs.__width_);
4204684ddb6SLionel Sambuc _VSTD::swap(__rdstate_, rhs.__rdstate_);
4214684ddb6SLionel Sambuc _VSTD::swap(__exceptions_, rhs.__exceptions_);
422*0a6a1f1dSLionel Sambuc locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
423*0a6a1f1dSLionel Sambuc locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
4244684ddb6SLionel Sambuc _VSTD::swap(lhs_loc, rhs_loc);
4254684ddb6SLionel Sambuc _VSTD::swap(__fn_, rhs.__fn_);
4264684ddb6SLionel Sambuc _VSTD::swap(__index_, rhs.__index_);
4274684ddb6SLionel Sambuc _VSTD::swap(__event_size_, rhs.__event_size_);
4284684ddb6SLionel Sambuc _VSTD::swap(__event_cap_, rhs.__event_cap_);
4294684ddb6SLionel Sambuc _VSTD::swap(__iarray_, rhs.__iarray_);
4304684ddb6SLionel Sambuc _VSTD::swap(__iarray_size_, rhs.__iarray_size_);
4314684ddb6SLionel Sambuc _VSTD::swap(__iarray_cap_, rhs.__iarray_cap_);
4324684ddb6SLionel Sambuc _VSTD::swap(__parray_, rhs.__parray_);
4334684ddb6SLionel Sambuc _VSTD::swap(__parray_size_, rhs.__parray_size_);
4344684ddb6SLionel Sambuc _VSTD::swap(__parray_cap_, rhs.__parray_cap_);
4354684ddb6SLionel Sambuc }
4364684ddb6SLionel Sambuc
4374684ddb6SLionel Sambuc void
__set_badbit_and_consider_rethrow()4384684ddb6SLionel Sambuc ios_base::__set_badbit_and_consider_rethrow()
4394684ddb6SLionel Sambuc {
4404684ddb6SLionel Sambuc __rdstate_ |= badbit;
4414684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
4424684ddb6SLionel Sambuc if (__exceptions_ & badbit)
4434684ddb6SLionel Sambuc throw;
4444684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
4454684ddb6SLionel Sambuc }
4464684ddb6SLionel Sambuc
4474684ddb6SLionel Sambuc void
__set_failbit_and_consider_rethrow()4484684ddb6SLionel Sambuc ios_base::__set_failbit_and_consider_rethrow()
4494684ddb6SLionel Sambuc {
4504684ddb6SLionel Sambuc __rdstate_ |= failbit;
4514684ddb6SLionel Sambuc #ifndef _LIBCPP_NO_EXCEPTIONS
4524684ddb6SLionel Sambuc if (__exceptions_ & failbit)
4534684ddb6SLionel Sambuc throw;
4544684ddb6SLionel Sambuc #endif // _LIBCPP_NO_EXCEPTIONS
4554684ddb6SLionel Sambuc }
4564684ddb6SLionel Sambuc
4574684ddb6SLionel Sambuc bool
sync_with_stdio(bool sync)4584684ddb6SLionel Sambuc ios_base::sync_with_stdio(bool sync)
4594684ddb6SLionel Sambuc {
4604684ddb6SLionel Sambuc static bool previous_state = true;
4614684ddb6SLionel Sambuc bool r = previous_state;
4624684ddb6SLionel Sambuc previous_state = sync;
4634684ddb6SLionel Sambuc return r;
4644684ddb6SLionel Sambuc }
4654684ddb6SLionel Sambuc
4664684ddb6SLionel Sambuc _LIBCPP_END_NAMESPACE_STD
467