|
|
|
| 1 |
|
// strstream standard header |
| 2 |
|
#pragma once |
| 3 |
|
#ifndef _STRSTREAM_ |
| 4 |
|
#define _STRSTREAM_ |
| 5 |
|
#ifndef RC_INVOKED |
| 6 |
|
#include <istream> |
| 7 |
|
|
| 8 |
|
#ifdef _MSC_VER |
| 9 |
|
#pragma pack(push,_CRT_PACKING) |
| 10 |
|
#pragma warning(push,3) |
| 11 |
|
#endif /* _MSC_VER */ |
| 12 |
|
|
| 13 |
|
extern "C" size_t __cdecl strlen(const char *); |
| 14 |
|
_STD_BEGIN |
| 15 |
|
|
| 16 |
|
// CLASS strstreambuf |
| 17 |
|
class _CRTIMP2_PURE strstreambuf |
| 18 |
|
: public streambuf |
| 19 |
|
{ // stream buffer associated with static or allocated character array |
| 20 |
|
public: |
| 21 |
|
enum |
| 22 |
|
{ // constants for bits in stream state |
| 23 |
|
_Allocated = 1, // set if character array storage has been allocated |
| 24 |
|
_Constant = 2, // set if character array nonmutable |
| 25 |
|
_Dynamic = 4, // set if character array length grows on demand |
| 26 |
|
_Frozen = 8}; // set if character array ownership given away |
| 27 |
|
typedef int _Strstate; |
| 28 |
|
|
| 29 |
|
explicit __CLR_OR_THIS_CALL strstreambuf(streamsize _Count = 0) |
| 30 |
|
{ // construct with empty character array, suggested initial size |
| 31 |
|
_Init(_Count); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
__CLR_OR_THIS_CALL strstreambuf(void *(__CLRCALL_OR_CDECL *_Allocfunc)(size_t), |
| 35 |
|
void (__CLRCALL_OR_CDECL *_Freefunc)(void *)) |
| 36 |
|
{ // construct with empty character array, allocation functions |
| 37 |
|
_Init(); |
| 38 |
|
_Palloc = _Allocfunc; |
| 39 |
|
_Pfree = _Freefunc; |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
__CLR_OR_THIS_CALL strstreambuf(_In_opt_z_ char *_Getptr, streamsize _Count, |
| 43 |
|
_In_opt_z_ char *_Putptr = 0) |
| 44 |
|
{ // construct with [_Getptr, _Getptr + _Count), possibly mutable |
| 45 |
|
_Init(_Count, _Getptr, _Putptr); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
#pragma warning(push) |
| 49 |
|
#pragma warning(disable: 6054) |
| 50 |
|
__CLR_OR_THIS_CALL strstreambuf(_In_opt_z_ unsigned char *_Getptr, streamsize _Count, |
| 51 |
|
_In_opt_z_ unsigned char *_Putptr = 0) |
| 52 |
|
{ // construct with [_Getptr, _Getptr + _Count), possibly mutable |
| 53 |
|
_Init(_Count, (char *)_Getptr, (char *)_Putptr); |
| 54 |
|
} |
| 55 |
|
#pragma warning(pop) |
| 56 |
|
|
| 57 |
|
__CLR_OR_THIS_CALL strstreambuf(_In_z_ const char *_Getptr, streamsize _Count) |
| 58 |
|
{ // construct with [_Getptr, _Getptr + _Count), nonmutable |
| 456 |
|
{ // input/output stream associated with character array buffer |
| 457 |
|
public: |
| 458 |
|
typedef char char_type; |
| 459 |
|
typedef int int_type; |
| 460 |
|
typedef streampos pos_type; |
| 461 |
|
typedef streamoff off_type; |
| 462 |
|
|
| 463 |
|
__CLR_OR_THIS_CALL strstream() |
| 464 |
|
: iostream(&_Mysb), _Mysb() |
| 465 |
|
{ // construct with empty character array |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
__CLR_OR_THIS_CALL strstream(_In_opt_z_ char *_Ptr, streamsize _Count, |
| 469 |
|
ios_base::openmode _Mode= |
| 470 |
|
ios_base::in | ios_base::out) // construct with static array |
| 471 |
|
: iostream(&_Mysb), |
| 472 |
|
_Mysb(_Ptr, _Count, _Ptr == 0 || (_Mode & ios_base::app) == 0 ? |
| 473 |
|
_Ptr : _Ptr + strlen(_Ptr)) |
| 474 |
|
{ // construct with [ptr, ptr + count) |
| 475 |
|
} |
| 476 |
|
|
| 477 |
|
virtual __CLR_OR_THIS_CALL ~strstream() |
| 478 |
|
{ // destroy a strstream |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
strstreambuf *__CLR_OR_THIS_CALL rdbuf() const |
| 482 |
|
{ // return pointer to character array buffer |
| 483 |
|
return ((strstreambuf *)&_Mysb); |
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
void __CLR_OR_THIS_CALL freeze(bool _Freezeit = true) |
| 487 |
|
{ // freeze or unfreeze writing |
| 488 |
|
_Mysb.freeze(_Freezeit); |
| 489 |
|
} |
| 490 |
|
|
| 491 |
|
char *__CLR_OR_THIS_CALL str() |
| 492 |
|
{ // freeze and return pointer to character array |
| 493 |
|
return (_Mysb.str()); |
| 494 |
|
} |
| 495 |
|
|
| 496 |
|
streamsize __CLR_OR_THIS_CALL pcount() const |
| 497 |
|
{ // return size of writable character array |
| 498 |
|
return (_Mysb.pcount()); |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
private: |
| 502 |
|
strstreambuf _Mysb; // the character array buffer |
| 503 |
|
}; |
| 504 |
|
_STD_END |
| 505 |
|
#ifdef _MSC_VER |
| 506 |
|
#pragma warning(pop) |
| 507 |
|
#pragma pack(pop) |
| 508 |
|
#endif /* _MSC_VER */ |
| 509 |
|
|
| 510 |
|
#endif /* RC_INVOKED */ |
| 511 |
|
#endif /* _STRSTREAM_ */ |
| 512 |
|
|
| 513 |
|
/* |
| 514 |
|
* Copyright (c) 1992-2006 by P.J. Plauger. ALL RIGHTS RESERVED. |
| 515 |
|
* Consult your license regarding permissions and restrictions. |
| 516 |
|
V5.02:0009 */ |
| 517 |
|
|
|
|
|