summaryrefslogtreecommitdiff
path: root/static/v10/man3/ssbuf.3
blob: 1056700b1fde437f7c7f8927c34adb092ab93a24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.  \"ident	"%W%"
.  \"Copyright (c) 1984 AT&T
.  \"All Rights Reserved
.  \"THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
.  \"The copyright notice above does not evidence any
.  \"actual or intended publication of such source code.
.TH SSBUF 3I+ "C++ Stream Library" " "
.SH NAME
strstreambuf \- streambuf specialized to arrays
.SH SYNOPSIS
.ta1i 2i 4i
.ft B
.nf
#include <iostream.h>
#include <strstream.h>

class strstreambuf : streambuf {
public:
		strstreambuf() ;
		strstreambuf(char*,int,char*);
		strstreambuf(int);
		strstreambuf(unsigned char*, int, unsigned char*);
		strstreambuf(void* (*a)(long), void(*f)(void*));

	void	freeze(int n=1) ;
	char*	str();
	streambuf*	setbuf(char*,int)
};
.fi
.ft R
.SH DESCRIPTION
A \f(CWstrstreambuf\fR
is a \f(CWstreambuf\fR that uses an array of bytes (a string) to hold
the sequence of characters.
Given the convention that a \f(CWchar*\fR should be interpreted as
pointing just before the \f(CWchar\fR it really points at, the mapping
between the abstract get/put pointers and \f(CWchar*\fR pointers
is direct.  Moving the pointers corresponds exactly to incrementing
and decrementing the \f(CWchar*\fR values.
.PP
To accommodate the need for arbitrary length strings
\f(CWstrstreambuf\fRs
supports an automatic mode.
When a \fBstrstreambuf\fR is in automatic mode, space for
the character sequence is
allocated as needed.
When the sequence is extended too far, it will be copied
to a new array.
.PP
Assume
.br
\(em \fBssb\fR is a \f(CWstrstreambuf*\fR.
.br
\(em \fBn\fR is an \f(CWint\fR.
.br
\(em \fBptr\fR and \fBpstart\fR are \f(CWchar*\fR or \f(CWunsigned char*\fR.
.br
\(em \fBa\fR is \f(CWvoid* (*)(long)\fR.
.br
\(em \fBf\fR is \f(CWvoid* (*)(void*)\fR.
.PP
The constructors:
.TP
\fBstrstreambuf()\fR
Constructs an empty buffer in dynamic mode.  This means that
space will be automatically allocated to accomodate the
characters that are put into the buffer (using operators \f(CWnew\fR
and \f(CWdelete\fR).  Because this may require copying the
original characters, it is recommended that when large strings
will be used that \fBsetbuf\fR be used (as described below) to
inform the \f(CWstrstreambuf\fR.
.TP
\fBstrstreambuf(a,f)\fR
Constructs an empty buffer in dynamic mode.
\fBa\fR is used as the allocator function
in dynamic mode.  If it is null, \f(CWoperator new\fR will be used.
\fBf\fR is used to free (or delete) areas returned by \fBa\fR.
If it is null \f(CWoperator delete\fR is used.
.TP
\fBstrstreambuf(n)\fR
Constructs an empty buffer in dynamic mode.  The initial allocation
of space will be at least \fBn\fR bytes.
.TP
\fBstrstreambuf(ptr,n,pstart)\fR
Constructs a buffer to use the bytes starting at
\fBptr\fR.  If \fBn\fR is positive and the \fBn\fR bytes starting
at \fBptr\fR are used.  If \fBn\fR is zero, \fBptr\fR is assumed
to point to the beginning of a null terminated strings and
the bytes of that string (not including the terminating null character)
will constitute the buffer.  If \fBn\fR is negative the buffer is
assumed to continue indefinitely.
The get pointer is initialized to \fBptr\fR.  The
put pointer is initialized to \fBpstart\fR.  If \fBpstart\fR is
null then stores will be treated as errors.  If \fBpstart\fR
is non null then the initial sequence (for fetching) consists
of the bytes between \fBptr\fR and \fBpstart\fR.  If \fBpstart\fR
is null then the initial sequence consists of the entire array.
.PP
Member functions:
.TP
\fBssb->freeze(n)\fR
Inhibits (\fBn\fR nonzero) or permits (\fBn\fR zero) automatic
deletion
of the current array.
Deletion normally occurs when more space is needed
or when \fBssb\fR is being destroyed.  Only
space obtained dynamic allocation is ever freed.
It is an error (and the effect is undefined) to store characters
into a buffer that was in automatic allocation mode and is now
frozen.
It is possible, however, to thaw (unfreeze) such a buffer and
resume storing characters.
.TP
\fBptr=ssb->str()\fR
Returns a pointer to the first char of the current array and freezes
\fBssb\fR.  If \fBssb\fR was constructed with an explicit array
\fBinit\fR,
\fBptr\fR will point to that array.
If \fBssb\fR is in automatic
allocation mode, but nothing has yet been stored, \fBptr\fR may
be null.
\fBstr\fR freezes \fBssb\fR.
.TP
\Bssb->setbuf(0,n)\fR
\fBssb\fR remembers \fBn\fR and the next time it does a dynamic
mode allocation, it makes sure that at least \fBn\fR bytes
are allocated.
.SH SEE ALSO
sbuf.pub(3C++)
strstream(3C++)