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