|
|
|
1 |
|
// sstream standard header |
2 |
|
#pragma once |
3 |
|
#ifndef _SSTREAM_ |
4 |
|
#define _SSTREAM_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <string> |
7 |
|
|
8 |
|
#ifdef _MSC_VER |
9 |
|
#pragma pack(push,_CRT_PACKING) |
10 |
|
#pragma warning(push,3) |
11 |
|
#endif /* _MSC_VER */ |
12 |
|
|
13 |
|
_STD_BEGIN |
14 |
|
|
15 |
|
#pragma warning(disable:4251) |
16 |
|
|
17 |
|
// TEMPLATE CLASS basic_stringbuf |
18 |
|
template<class _Elem, |
19 |
|
class _Traits, |
20 |
|
class _Alloc> |
21 |
|
class basic_stringbuf |
22 |
|
: public basic_streambuf<_Elem, _Traits> |
23 |
|
{ // stream buffer maintaining an allocated character array |
24 |
|
public: |
25 |
|
typedef _Alloc allocator_type; |
26 |
|
typedef basic_streambuf<_Elem, _Traits> _Mysb; |
27 |
|
typedef basic_string<_Elem, _Traits, _Alloc> _Mystr; |
28 |
|
|
29 |
|
explicit __CLR_OR_THIS_CALL basic_stringbuf(ios_base::openmode _Mode = |
30 |
|
ios_base::in | ios_base::out) |
31 |
|
{ // construct empty character buffer from mode |
32 |
|
_Init(0, 0, _Getstate(_Mode)); |
33 |
|
} |
34 |
|
|
35 |
|
explicit __CLR_OR_THIS_CALL basic_stringbuf(const _Mystr& _Str, |
36 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out) |
37 |
|
{ // construct character buffer from string, mode |
38 |
|
_Init(_Str.c_str(), _Str.size(), _Getstate(_Mode)); |
39 |
|
} |
40 |
|
|
41 |
|
virtual __CLR_OR_THIS_CALL ~basic_stringbuf() |
42 |
|
{ // destroy the object |
43 |
|
_Tidy(); |
44 |
|
} |
45 |
|
|
46 |
|
enum |
47 |
|
{ // constants for bits in stream state |
48 |
|
_Allocated = 1, // set if character array storage has been allocated |
49 |
|
_Constant = 2, // set if character array nonmutable |
50 |
|
_Noread = 4, // set if character array cannot be read |
51 |
|
_Append = 8, // set if all writes are appends |
52 |
|
_Atend = 16}; // set if initial writes are appends |
53 |
|
typedef int _Strstate; |
54 |
|
|
55 |
|
typedef typename _Traits::int_type int_type; |
56 |
|
typedef typename _Traits::pos_type pos_type; |
57 |
|
typedef typename _Traits::off_type off_type; |
58 |
|
|
286 |
|
_Pnew + _Count); // setup read buffer |
287 |
|
if (!(_Mystate & _Constant)) |
288 |
|
{ // setup write buffer, and maybe read buffer |
289 |
|
_Mysb::setp(_Pnew, |
290 |
|
(_Mystate & _Atend) ? _Pnew + _Count : _Pnew, |
291 |
|
_Pnew + _Count); |
292 |
|
if (_Mysb::gptr() == 0) |
293 |
|
_Mysb::setg(_Pnew, 0, _Pnew); |
294 |
|
} |
295 |
|
_Mystate |= _Allocated; |
296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
|
void __CLR_OR_THIS_CALL _Tidy() |
300 |
|
{ // discard any allocated buffer and clear pointers |
301 |
|
if (_Mystate & _Allocated) |
302 |
|
_Al.deallocate(_Mysb::eback(), |
303 |
|
(_Mysb::pptr() != 0 ? _Mysb::epptr() |
304 |
|
: _Mysb::egptr()) - _Mysb::eback()); |
305 |
|
_Mysb::setg(0, 0, 0); |
306 |
|
_Mysb::setp(0, 0); |
307 |
|
_Seekhigh = 0; |
308 |
|
_Mystate &= ~_Allocated; |
309 |
|
} |
310 |
|
|
311 |
|
private: |
312 |
|
enum |
313 |
|
{ // constant for minimum buffer size |
314 |
|
_MINSIZE = 32}; |
315 |
|
|
316 |
|
_Strstate __CLR_OR_THIS_CALL _Getstate(ios_base::openmode _Mode) |
317 |
|
{ // convert open mode to stream state bits |
318 |
|
_Strstate _State = (_Strstate)0; |
319 |
|
if (!(_Mode & ios_base::in)) |
320 |
|
_State |= _Noread; |
321 |
|
if (!(_Mode & ios_base::out)) |
322 |
|
_State |= _Constant; |
323 |
|
if (_Mode & ios_base::app) |
324 |
|
_State |= _Append; |
325 |
|
if (_Mode & ios_base::ate) |
326 |
|
_State |= _Atend; |
327 |
|
return (_State); |
328 |
|
} |
329 |
|
|
330 |
|
_Elem *_Seekhigh; // the high-water pointer in character array |
331 |
|
_Strstate _Mystate; // the stream state |
332 |
|
allocator_type _Al; // the allocator object |
333 |
|
}; |
334 |
|
|
335 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
336 |
|
|
337 |
|
template class _CRTIMP2_PURE basic_stringbuf<char, |
338 |
|
char_traits<char>, allocator<char> >; |
339 |
|
template class _CRTIMP2_PURE basic_stringbuf<wchar_t, |
340 |
|
char_traits<wchar_t>, allocator<wchar_t> >; |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
#endif /* _DLL_CPPLIB */ |
345 |
|
|
346 |
|
// TEMPLATE CLASS basic_istringstream |
347 |
|
template<class _Elem, |
348 |
|
class _Traits, |
349 |
|
class _Alloc> |
350 |
|
class basic_istringstream |
351 |
|
: public basic_istream<_Elem, _Traits> |
352 |
|
{ // input stream associated with a character array |
353 |
|
public: |
354 |
|
typedef _Alloc allocator_type; |
355 |
|
typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb; |
356 |
|
typedef basic_string<_Elem, _Traits, _Alloc> _Mystr; |
357 |
|
|
358 |
|
explicit __CLR_OR_THIS_CALL basic_istringstream(ios_base::openmode _Mode = ios_base::in) |
359 |
|
: basic_istream<_Elem, _Traits>(&_Stringbuffer), |
360 |
|
_Stringbuffer(_Mode | ios_base::in) |
361 |
|
{ // construct empty readable character buffer |
362 |
|
} |
363 |
|
|
364 |
|
explicit __CLR_OR_THIS_CALL basic_istringstream(const _Mystr& _Str, |
365 |
|
ios_base::openmode _Mode = ios_base::in) |
366 |
|
: basic_istream<_Elem, _Traits>(&_Stringbuffer), |
367 |
|
_Stringbuffer(_Str, _Mode | ios_base::in) |
368 |
|
{ // construct readable character buffer from NTCS |
369 |
|
} |
370 |
|
|
371 |
|
virtual __CLR_OR_THIS_CALL ~basic_istringstream() |
372 |
|
{ // destroy the object |
373 |
|
} |
374 |
|
|
375 |
|
_Mysb *__CLR_OR_THIS_CALL rdbuf() const |
376 |
|
{ // return pointer to file buffer |
377 |
|
return ((_Mysb *)&_Stringbuffer); |
378 |
|
} |
379 |
|
|
380 |
|
_Mystr __CLR_OR_THIS_CALL str() const |
381 |
|
{ // return string copy of character array |
382 |
|
return (_Stringbuffer.str()); |
383 |
|
} |
384 |
|
|
385 |
|
void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr) |
386 |
|
{ // replace character array from string |
387 |
|
_Stringbuffer.str(_Newstr); |
388 |
|
} |
389 |
|
|
390 |
|
private: |
391 |
|
_Mysb _Stringbuffer; // the string buffer |
392 |
|
}; |
393 |
|
|
394 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
395 |
|
|
396 |
|
template class _CRTIMP2_PURE basic_istringstream<char, |
397 |
|
char_traits<char>, allocator<char> >; |
398 |
|
template class _CRTIMP2_PURE basic_istringstream<wchar_t, |
399 |
|
char_traits<wchar_t>, allocator<wchar_t> >; |
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
#endif /* _DLL_CPPLIB */ |
404 |
|
|
405 |
|
// TEMPLATE CLASS basic_ostringstream |
406 |
|
template<class _Elem, |
407 |
|
class _Traits, |
408 |
|
class _Alloc> |
409 |
|
class basic_ostringstream |
410 |
|
: public basic_ostream<_Elem, _Traits> |
411 |
|
{ // output stream associated with a character array |
412 |
|
public: |
413 |
|
typedef _Alloc allocator_type; |
414 |
|
typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb; |
415 |
|
typedef basic_string<_Elem, _Traits, _Alloc> _Mystr; |
416 |
|
|
417 |
|
explicit __CLR_OR_THIS_CALL basic_ostringstream(ios_base::openmode _Mode = ios_base::out) |
418 |
|
: basic_ostream<_Elem, _Traits>(&_Stringbuffer), |
419 |
|
_Stringbuffer(_Mode | ios_base::out) |
420 |
|
{ // construct empty writable character buffer |
421 |
|
} |
422 |
|
|
423 |
|
explicit __CLR_OR_THIS_CALL basic_ostringstream(const _Mystr& _Str, |
424 |
|
ios_base::openmode _Mode = ios_base::out) |
425 |
|
: basic_ostream<_Elem, _Traits>(&_Stringbuffer), |
426 |
|
_Stringbuffer(_Str, _Mode | ios_base::out) |
427 |
|
{ // construct writable character buffer from NTCS |
428 |
|
} |
429 |
|
|
430 |
|
virtual __CLR_OR_THIS_CALL ~basic_ostringstream() |
431 |
|
{ // destroy the object |
432 |
|
} |
433 |
|
|
434 |
|
_Mysb *__CLR_OR_THIS_CALL rdbuf() const |
435 |
|
{ // return pointer to buffer |
436 |
|
return ((_Mysb *)&_Stringbuffer); |
437 |
|
} |
438 |
|
|
439 |
|
_Mystr __CLR_OR_THIS_CALL str() const |
440 |
|
{ // return string copy of character array |
441 |
|
return (_Stringbuffer.str()); |
442 |
|
} |
443 |
|
|
444 |
|
void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr) |
445 |
|
{ // replace character array from string |
446 |
|
_Stringbuffer.str(_Newstr); |
447 |
|
} |
448 |
|
|
449 |
|
private: |
450 |
|
_Mysb _Stringbuffer; // the string buffer |
451 |
|
}; |
452 |
|
|
453 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
454 |
|
|
455 |
|
template class _CRTIMP2_PURE basic_ostringstream<char, |
456 |
|
char_traits<char>, allocator<char> >; |
457 |
|
template class _CRTIMP2_PURE basic_ostringstream<wchar_t, |
458 |
|
char_traits<wchar_t>, allocator<wchar_t> >; |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
#endif /* _DLL_CPPLIB */ |
463 |
|
|
464 |
|
// TEMPLATE CLASS basic_stringstream |
465 |
|
template<class _Elem, |
466 |
|
class _Traits, |
467 |
|
class _Alloc> |
468 |
|
class basic_stringstream |
469 |
|
: public basic_iostream<_Elem, _Traits> |
470 |
|
{ // input/output stream associated with a character array |
471 |
|
public: |
472 |
|
typedef _Elem char_type; |
473 |
|
typedef _Traits traits_type; |
474 |
|
typedef _Alloc allocator_type; |
475 |
|
typedef typename _Traits::int_type int_type; |
476 |
|
typedef typename _Traits::pos_type pos_type; |
477 |
|
typedef typename _Traits::off_type off_type; |
478 |
|
typedef basic_string<_Elem, _Traits, _Alloc> _Mystr; |
479 |
|
|
480 |
|
explicit __CLR_OR_THIS_CALL basic_stringstream(ios_base::openmode _Mode = |
481 |
|
ios_base::in | ios_base::out) |
482 |
|
: basic_iostream<_Elem, _Traits>(&_Stringbuffer), |
483 |
|
_Stringbuffer(_Mode) |
484 |
|
{ // construct empty character buffer |
485 |
|
} |
486 |
|
|
487 |
|
explicit __CLR_OR_THIS_CALL basic_stringstream(const _Mystr& _Str, |
488 |
|
ios_base::openmode _Mode = ios_base::in | ios_base::out) |
489 |
|
: basic_iostream<_Elem, _Traits>(&_Stringbuffer), |
490 |
|
_Stringbuffer(_Str, _Mode) |
491 |
|
{ // construct character buffer from NTCS |
492 |
|
} |
493 |
|
|
494 |
|
virtual __CLR_OR_THIS_CALL ~basic_stringstream() |
495 |
|
{ // destroy the object |
496 |
|
} |
497 |
|
|
498 |
|
basic_stringbuf<_Elem, _Traits, _Alloc> *__CLR_OR_THIS_CALL rdbuf() const |
499 |
|
{ // return pointer to buffer |
500 |
|
return ((basic_stringbuf<_Elem, _Traits, _Alloc> *)&_Stringbuffer); |
501 |
|
} |
502 |
|
|
503 |
|
_Mystr __CLR_OR_THIS_CALL str() const |
504 |
|
{ // return string copy of character array |
505 |
|
return (_Stringbuffer.str()); |
506 |
|
} |
507 |
|
|
508 |
|
void __CLR_OR_THIS_CALL str(const _Mystr& _Newstr) |
509 |
|
{ // replace character array from string |
510 |
|
_Stringbuffer.str(_Newstr); |
511 |
|
} |
512 |
|
|
513 |
|
private: |
514 |
|
basic_stringbuf<_Elem, _Traits, _Alloc> |
515 |
|
_Stringbuffer; // the string buffer |
516 |
|
}; |
517 |
|
|
518 |
|
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) |
519 |
|
|
520 |
|
template class _CRTIMP2_PURE basic_stringstream<char, |
521 |
|
char_traits<char>, allocator<char> >; |
522 |
|
template class _CRTIMP2_PURE basic_stringstream<wchar_t, |
523 |
|
char_traits<wchar_t>, allocator<wchar_t> >; |
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
#endif /* _DLL_CPPLIB */ |
528 |
|
_STD_END |
529 |
|
|
530 |
|
#ifdef _MSC_VER |
531 |
|
#pragma warning(pop) |
532 |
|
#pragma pack(pop) |
533 |
|
#endif /* _MSC_VER */ |
534 |
|
|
535 |
|
#endif /* RC_INVOKED */ |
536 |
|
#endif /* _SSTREAM_ */ |
537 |
|
|
538 |
|
/* |
539 |
|
* Copyright (c) 1992-2008 by P.J. Plauger. ALL RIGHTS RESERVED. |
540 |
|
* Consult your license regarding permissions and restrictions. |
541 |
|
V5.05:0009 */ |
542 |
|
|
543 |
|
|
544 |
|
|
|
|
|