Changeset 95993 in vbox for trunk/include/iprt/nocrt/ios
- Timestamp:
- Aug 3, 2022 9:25:58 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/nocrt/ios
r95985 r95993 54 54 namespace std 55 55 { 56 typedef RTFOFFstreamsize;56 typedef ptrdiff_t streamsize; 57 57 58 58 /** 59 59 * I/O stream format flags. 60 60 */ 61 enum rtNoCrtIosFmtFlags61 class rtNoCrtIosEnums 62 62 { 63 /* int: */ 64 dec = 0x00000001, 65 oct = 0x00000002, 66 hex = 0x00000004, 67 basefield = 0x00000007, 68 /* float: */ 69 scientific = 0x00000010, 70 fixed = 0x00000020, 71 floatfield = 0x00000030, 72 /* int and float output tweaks: */ 73 showbase = 0x00000100, 74 showpoint = 0x00000200, 75 showpos = 0x00000400, 76 /* bool: */ 77 boolalpha = 0x00000800, 78 /* adjustment: */ 79 left = 0x00001000, 80 right = 0x00002000, 81 internal = 0x00004000, 82 adjustfield = 0x00007000, 83 /* misc: */ 84 skipws = 0x00010000, 85 unitbuf = 0x00020000, 86 uppercase = 0x00040000, 63 public: 64 enum fmtflags 65 { 66 /* int: */ 67 dec = 0x00000001, 68 oct = 0x00000002, 69 hex = 0x00000004, 70 basefield = 0x00000007, 71 /* float: */ 72 scientific = 0x00000010, 73 fixed = 0x00000020, 74 floatfield = 0x00000030, 75 /* int and float output tweaks: */ 76 showbase = 0x00000100, 77 showpoint = 0x00000200, 78 showpos = 0x00000400, 79 /* bool: */ 80 boolalpha = 0x00000800, 81 /* adjustment: */ 82 left = 0x00001000, 83 right = 0x00002000, 84 internal = 0x00004000, 85 adjustfield = 0x00007000, 86 /* misc: */ 87 skipws = 0x00010000, 88 unitbuf = 0x00020000, 89 uppercase = 0x00040000, 90 }; 91 92 enum seekdir 93 { 94 beg = 1, 95 end, 96 cur, 97 }; 98 99 enum openmode 100 { 101 app = 1, 102 binary, 103 in, 104 out, 105 trunc, 106 ate 107 }; 108 109 enum iostate 110 { 111 goodbit = 0, 112 badbit = 1, 113 failbit = 2, 114 eofbit = 4 115 }; 87 116 }; 88 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosFmtFlags, int) 89 90 enum rtNoCrtIosSeekDir 91 { 92 beg = 1, 93 end, 94 cur, 95 }; 96 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosSeekDir, int) 97 98 enum rtNoCrtIosOpenMode 99 { 100 app = 1, 101 binary, 102 in, 103 out, 104 trunc, 105 ate 106 }; 107 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosOpenMode, int) 108 109 enum rtNoCrtIosState 110 { 111 goodbit = 0, 112 badbit = 1, 113 failbit = 2, 114 eofbit = 4 115 }; 116 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosState, int) 117 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::fmtflags, int) 118 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::seekdir, int) 119 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::openmode, int) 120 RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::iostate, int) 117 121 118 122 … … 120 124 * I/O stream base class. 121 125 */ 122 class ios_base 126 class ios_base : public rtNoCrtIosEnums 123 127 { 124 128 public: 125 typedef rtNoCrtIosFmtFlags fmtflags;126 typedef rtNoCrtIosSeekDir seekdir;127 typedef rtNoCrtIosOpenMode openmode;128 typedef rtNoCrtIosState iostate;129 //typedef rtNoCrtIosFmtFlags fmtflags; 130 //typedef rtNoCrtIosSeekDir seekdir; 131 //typedef rtNoCrtIosOpenMode openmode; 132 //typedef rtNoCrtIosState iostate; 129 133 130 134 protected: … … 222 226 223 227 protected: 224 basic_streambuf() 225 { 226 } 227 228 basic_streambuf(const basic_streambuf &a_rSrc) 228 /** @name Put buffering 229 * @{ */ 230 char_type *m_pachPut; /**< The put buffer pointer. */ 231 std::size_t m_cchPut; /**< Put buffer size. */ 232 std::size_t m_offPutNext; /**< The current put buffer position (where to write next). */ 233 std::size_t m_offPutStart; /**< Where the buffered put sequence starts. */ 234 235 void setp(char_type *a_pachNewBuf, char_type *a_pachNewBufEnd) 236 { 237 Assert((uintptr_t)a_pachNewBuf <= (uintptr_t)a_pachNewBufEnd); 238 m_pachPut = a_pachNewBuf; 239 m_cchPut = static_cast<std::size_t>(a_pachNewBufEnd - a_pachNewBuf); 240 m_offPutNext = 0; 241 m_offPutStart = 0; 242 } 243 244 char_type *pbbase() const RT_NOEXCEPT 245 { 246 Assert(m_offPutNext >= m_offPutStart); Assert(m_offPutNext <= m_cchPut); Assert(m_offPutStart <= m_cchPut); 247 return &m_pachPut[m_offPutStart]; 248 } 249 250 char_type *pptr() const RT_NOEXCEPT 251 { 252 Assert(m_offPutNext <= m_cchPut); 253 return &m_pachPut[m_offPutNext]; 254 } 255 256 char_type *epptr() const RT_NOEXCEPT 257 { 258 return &m_pachBuf[m_cchPut]; 259 } 260 261 void pbump(int a_cchAdvance) const RT_NOEXCEPT 262 { 263 Assert(m_offPutNext <= m_cchPut); 264 m_offPutNext += a_cchAdvance; 265 Assert(m_offPutNext <= m_cchPut); 266 } 267 /** @} */ 268 269 protected: 270 basic_streambuf() RT_NOEXCEPT 271 : m_pachPut(NULL) 272 , m_cchPut(0) 273 , m_offPutNext(0) 274 , m_offPutStart(0) 275 { 276 } 277 278 basic_streambuf(const basic_streambuf &a_rSrc) RT_NOEXCEPT 279 : m_pachPut(a_rSrc.m_pachPut) 280 , m_cchPut(a_rSrc.m_cchPut) 281 , m_offPutNext(a_rSrc.m_offPutNext) 282 , m_offPutStart(a_rSrc.m_offPutStart) 229 283 { 230 284 } … … 246 300 basic_streambuf *pubsetbuf(char_type *a_pchBuf, std::streamsize a_cchBuf) 247 301 { 248 return setbuf(a_ off, a_enmDir, a_enmTarget);302 return setbuf(a_pchBuf, a_cchBuf); 249 303 } 250 304 … … 253 307 std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) 254 308 { 255 RT_NOREF(a_off, a_enmDir, out);309 RT_NOREF(a_off, a_enmDir, a_enmTarget); 256 310 return pos_type(off_type(-1)); 257 311 } … … 266 320 virtual pos_type seekpos(pos_type a_pos, std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out) 267 321 { 268 RT_NOREF(a_ off, a_enmDir, out);322 RT_NOREF(a_pos, a_enmTarget); 269 323 return pos_type(off_type(-1)); 270 324 } … … 287 341 /** @} */ 288 342 289 /** @todo add the remainin members... */ 343 /** @name Output 344 * @{ */ 345 protected: 346 virtual int_type overflow(int_type a_iChar) 347 { 348 RT_NOREF(a_iChar); 349 return traits_type::eof(); 350 } 351 352 virtual std::streamsize xsputn(char_type const *a_pchSrc, std::streamsize a_cchSrc) 353 { 354 std::streamsize cchWritten = 0; 355 while (a_cchSrc > 0) 356 { 357 std::size_t cchCopied = m_cchPut - m_offPutNext; 358 if (cchCopied > 0) 359 { 360 cchCopied = RT_MIN(cchCopied, a_cchSrc); 361 traits_type::copy(&m_pachPut[m_offPutNext], a_pchSrc, cchCopied); 362 m_cchPut += cchCopied; 363 } 364 else 365 { 366 if (overflow(traits_type::to_int_type(m_pachPut[m_offPutNext])) != traits_type::eof()) 367 cchCopied = 1; 368 else 369 break; 370 } 371 a_pchSrc += cchCopied; 372 a_cchSrc -= cchCopied; 373 } 374 return cchWritten; 375 } 376 377 public: 378 int_type sputc(char_type a_ch) 379 { 380 if (m_offPutNext < m_cchPut) 381 { 382 m_pachPut[m_offPutNext++] = a_ch; 383 return traits_type::to_int_type(a_ch); 384 } 385 return overflow(traits_type::to_int_type(a_ch)); 386 } 387 388 std::streamsize sputn(char_type const *a_pchSrc, std::streamsize a_cchSrc) 389 { 390 AssertReturn(a_cchSrc >= 0, 0); 391 return xsputn(a_pchSrc, a_cchSrc); 392 } 393 394 /** @} */ 395 396 /** @todo add the remaining members... */ 290 397 }; 291 398 … … 306 413 protected: 307 414 basic_streambuf<a_CharType, a_CharTraits> *m_pBuf; 308 309 protected: 310 void init(const std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) 415 basic_ostream<a_CharType, a_CharTraits> *m_pTiedStream; 416 417 protected: 418 void init(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) 311 419 { 312 420 m_pBuf = a_pBuf; 313 421 m_cWidth = 0; 314 422 m_cPrecision = 6; 315 m_fFlags = ios_base::dec | ios_base:: wskip;423 m_fFlags = ios_base::dec | ios_base::skipws; 316 424 m_fState = ios_base::goodbit; 317 425 } … … 319 427 public: 320 428 basic_ios() 321 : m_pBuf(NULL) 322 , ios_base() 323 { 324 } 325 326 basic_ios(const std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) 327 : m_pBuf(NULL) 328 , ios_base() 329 { 330 init(a_pBuf) 429 : ios_base() 430 , m_pBuf(NULL) 431 , m_pTiedStream(NULL) 432 { 433 } 434 435 basic_ios(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf) 436 : ios_base() 437 , m_pBuf(NULL) 438 , m_pTiedStream(NULL) 439 { 440 init(a_pBuf); 331 441 } 332 442 private: … … 384 494 return pOldBuf; 385 495 } 496 497 std::basic_ostream<a_CharType, a_CharTraits> *tie() const 498 { 499 return m_pTiedStream; 500 } 501 502 std::basic_ostream<a_CharType, a_CharTraits> tie(std::basic_ostream<a_CharType, a_CharTraits> *a_pNew) const RT_NOEXCEPT 503 { 504 std::basic_ostream<a_CharType, a_CharTraits> * const pOld = m_pTiedStream; 505 m_pTiedStream = a_pNew; 506 return pOld; 507 } 386 508 /** @} */ 387 509
Note:
See TracChangeset
for help on using the changeset viewer.