ReactOS 0.4.15-dev-7897-g78dc504
strstreambuf Class Reference

#include <_strstream.h>

Inheritance diagram for strstreambuf:
Collaboration diagram for strstreambuf:

Public Types

typedef char_traits< char_Traits
 
typedef basic_streambuf< char, char_traits< char > > _Base
 
typedef void *(* __alloc_fn) (size_t)
 
typedef void(* __free_fn) (void *)
 
- Public Types inherited from basic_streambuf< char, char_traits< char > >
typedef char char_type
 
typedef _Traits::int_type int_type
 
typedef _Traits::pos_type pos_type
 
typedef _Traits::off_type off_type
 
typedef char_traits< chartraits_type
 

Public Member Functions

 strstreambuf (streamsize _Initial_capacity=0)
 
 strstreambuf (__alloc_fn, __free_fn)
 
 strstreambuf (char *__get, streamsize __n, char *__put=0)
 
 strstreambuf (signed char *__get, streamsize __n, signed char *__put=0)
 
 strstreambuf (unsigned char *__get, streamsize __n, unsigned char *__put=0)
 
 strstreambuf (const char *__get, streamsize __n)
 
 strstreambuf (const signed char *__get, streamsize __n)
 
 strstreambuf (const unsigned char *__get, streamsize __n)
 
virtual ~strstreambuf ()
 
void freeze (bool=true)
 
charstr ()
 
int pcount () const
 
- Public Member Functions inherited from basic_streambuf< char, char_traits< char > >
virtual ~basic_streambuf ()
 
char_type_M_eback () const
 
char_type_M_gptr () const
 
char_type_M_egptr () const
 
void _M_gbump (int __n)
 
void _M_setg (char_type *__gbegin, char_type *__gnext, char_type *__gend)
 
basic_streambuf< char, char_traits< char > > * pubsetbuf (char_type *__s, streamsize __n)
 
pos_type pubseekoff (off_type __offset, ios_base::seekdir __way, ios_base::openmode __mod=ios_base::in|ios_base::out)
 
pos_type pubseekpos (pos_type __sp, ios_base::openmode __mod=ios_base::in|ios_base::out)
 
int pubsync ()
 
int_type sputc (char_type __c)
 
streamsize sputn (const char_type *__s, streamsize __n)
 
streamsize _M_sputnc (char_type __c, streamsize __n)
 
streamsize in_avail ()
 
int_type snextc ()
 
int_type sbumpc ()
 
int_type sgetc ()
 
streamsize sgetn (char_type *__s, streamsize __n)
 
int_type sputbackc (char_type __c)
 
int_type sungetc ()
 
locale pubimbue (const locale &)
 
locale getloc () const
 
void stossc ()
 

Protected Member Functions

virtual int_type overflow (int_type __c=_Traits::eof())
 
virtual int_type pbackfail (int_type __c=_Traits::eof())
 
virtual int_type underflow ()
 
virtual _Basesetbuf (char *__buf, streamsize __n)
 
virtual pos_type seekoff (off_type __off, ios_base::seekdir __dir, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
virtual pos_type seekpos (pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
 
- Protected Member Functions inherited from basic_streambuf< char, char_traits< char > >
 basic_streambuf ()
 
char_typeeback () const
 
char_typegptr () const
 
char_typeegptr () const
 
void gbump (int __n)
 
void setg (char_type *__gbegin, char_type *__gnext, char_type *__gend)
 
char_typepbase () const
 
char_typepptr () const
 
char_typeepptr () const
 
void pbump (int __n)
 
void setp (char_type *__pbegin, char_type *__pend)
 
virtual basic_streambuf< char, char_traits< char > > * setbuf (char_type *, streamsize)
 
virtual pos_type seekoff (off_type, ios_base::seekdir, ios_base::openmode=ios_base::in|ios_base::out)
 
virtual pos_type seekpos (pos_type, ios_base::openmode=ios_base::in|ios_base::out)
 
virtual int sync ()
 
virtual streamsize showmanyc ()
 
virtual streamsize xsgetn (char_type *__s, streamsize __n)
 
virtual int_type underflow ()
 
virtual int_type uflow ()
 
virtual int_type pbackfail (int_type=traits_type::eof())
 
virtual streamsize xsputn (const char_type *__s, streamsize __n)
 
virtual streamsize _M_xsputnc (char_type __c, streamsize __n)
 
virtual int_type overflow (int_type=traits_type::eof())
 
virtual void imbue (const locale &)
 

Private Member Functions

char_M_alloc (size_t)
 
void _M_free (char *)
 
void _M_setup (char *__get, char *__put, streamsize __n)
 

Private Attributes

__alloc_fn _M_alloc_fun
 
__free_fn _M_free_fun
 
bool _M_dynamic: 1
 
bool _M_frozen: 1
 
bool _M_constant: 1
 

Detailed Description

Definition at line 46 of file _strstream.h.

Member Typedef Documentation

◆ __alloc_fn

typedef void *(* strstreambuf::__alloc_fn) (size_t)

Definition at line 50 of file _strstream.h.

◆ __free_fn

typedef void(* strstreambuf::__free_fn) (void *)

Definition at line 51 of file _strstream.h.

◆ _Base

Definition at line 49 of file _strstream.h.

◆ _Traits

Definition at line 48 of file _strstream.h.

Constructor & Destructor Documentation

◆ strstreambuf() [1/8]

_STLP_BEGIN_NAMESPACE strstreambuf::strstreambuf ( streamsize  _Initial_capacity = 0)
explicit

Definition at line 34 of file strstream.cpp.

36 _M_dynamic(true), _M_frozen(false), _M_constant(false) {
37 size_t n = (sizeof(streamsize) > sizeof(size_t)) ? __STATIC_CAST(size_t, (min)(__STATIC_CAST(streamsize, (numeric_limits<size_t>::max)()),
38 (max)(initial_capacity, streamsize(16))))
39 : __STATIC_CAST(size_t, (max)(initial_capacity, streamsize(16)));
40
41 char* buf = _M_alloc(n);
42 if (buf) {
43 setp(buf, buf + n);
44 setg(buf, buf, buf);
45 }
46}
ptrdiff_t streamsize
Definition: char_traits.h:81
void setp(char_type *__pbegin, char_type *__pend)
Definition: _streambuf.h:116
void setg(char_type *__gbegin, char_type *__gnext, char_type *__gend)
Definition: _streambuf.h:92
__alloc_fn _M_alloc_fun
Definition: _strstream.h:92
bool _M_constant
Definition: _strstream.h:96
bool _M_dynamic
Definition: _strstream.h:94
bool _M_frozen
Definition: _strstream.h:95
char * _M_alloc(size_t)
Definition: strstream.cpp:261
__free_fn _M_free_fun
Definition: _strstream.h:93
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define min(a, b)
Definition: monoChain.cc:55
#define max(a, b)
Definition: svc.c:63

◆ strstreambuf() [2/8]

strstreambuf::strstreambuf ( __alloc_fn  alloc_f,
__free_fn  free_f 
)

Definition at line 48 of file strstream.cpp.

49 : _M_alloc_fun(alloc_f), _M_free_fun(free_f),
50 _M_dynamic(true), _M_frozen(false), _M_constant(false) {
51 size_t n = 16;
52
53 char* buf = _M_alloc(n);
54 if (buf) {
55 setp(buf, buf + n);
56 setg(buf, buf, buf);
57 }
58}

◆ strstreambuf() [3/8]

strstreambuf::strstreambuf ( char __get,
streamsize  __n,
char __put = 0 
)

Definition at line 60 of file strstream.cpp.

62 _M_dynamic(false), _M_frozen(false), _M_constant(false) {
63 _M_setup(get, put, n);
64}
void get(int argc, const char *argv[])
Definition: cmds.c:480
void _M_setup(char *__get, char *__put, streamsize __n)
Definition: strstream.cpp:277
#define put(ret, state, sp, n)
Definition: match.c:105

◆ strstreambuf() [4/8]

strstreambuf::strstreambuf ( signed char __get,
streamsize  __n,
signed char __put = 0 
)

Definition at line 66 of file strstream.cpp.

68 _M_dynamic(false), _M_frozen(false), _M_constant(false) {
70}
#define __REINTERPRET_CAST(__x, __y)
Definition: features.h:586

◆ strstreambuf() [5/8]

strstreambuf::strstreambuf ( unsigned char __get,
streamsize  __n,
unsigned char __put = 0 
)

Definition at line 72 of file strstream.cpp.

75 _M_dynamic(false), _M_frozen(false), _M_constant(false) {
77}

◆ strstreambuf() [6/8]

strstreambuf::strstreambuf ( const char __get,
streamsize  __n 
)

Definition at line 79 of file strstream.cpp.

81 _M_dynamic(false), _M_frozen(false), _M_constant(true) {
82 _M_setup(__CONST_CAST(char*,get), 0, n);
83}
#define __CONST_CAST(__x, __y)
Definition: features.h:584

◆ strstreambuf() [7/8]

strstreambuf::strstreambuf ( const signed char __get,
streamsize  __n 
)

Definition at line 85 of file strstream.cpp.

87 _M_dynamic(false), _M_frozen(false), _M_constant(true) {
88 _M_setup(__REINTERPRET_CAST(char*, __CONST_CAST(signed char*,get)), 0, n);
89}

◆ strstreambuf() [8/8]

strstreambuf::strstreambuf ( const unsigned char __get,
streamsize  __n 
)

Definition at line 91 of file strstream.cpp.

93 _M_dynamic(false), _M_frozen(false), _M_constant(true) {
94 _M_setup(__REINTERPRET_CAST(char*, __CONST_CAST(unsigned char*,get)), 0, n);
95}

◆ ~strstreambuf()

strstreambuf::~strstreambuf ( )
virtual

Definition at line 97 of file strstream.cpp.

97 {
98 if (_M_dynamic && !_M_frozen)
99 _M_free(eback());
100}
void _M_free(char *)
Definition: strstream.cpp:268

Member Function Documentation

◆ _M_alloc()

char * strstreambuf::_M_alloc ( size_t  n)
private

Definition at line 261 of file strstream.cpp.

261 {
262 if (_M_alloc_fun)
263 return __STATIC_CAST(char*,_M_alloc_fun(n));
264 else
265 return new char[n];
266}

Referenced by overflow(), and strstreambuf().

◆ _M_free()

void strstreambuf::_M_free ( char p)
private

Definition at line 268 of file strstream.cpp.

268 {
269 if (p) {
270 if (_M_free_fun)
271 _M_free_fun(p);
272 else
273 delete[] p;
274 }
275}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by overflow(), and ~strstreambuf().

◆ _M_setup()

void strstreambuf::_M_setup ( char __get,
char __put,
streamsize  __n 
)
private

Definition at line 277 of file strstream.cpp.

277 {
278 if (get) {
279 size_t N = n > 0 ? size_t(n) : n == 0 ? strlen(get) : size_t(INT_MAX);
280
281 if (put) {
282 setg(get, get, get + N);
283 setp(put, put + N);
284 }
285 else {
286 setg(get, get, get + N);
287 }
288 }
289}
#define N
Definition: crc32.c:57
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
__kernel_size_t size_t
Definition: linux.h:237
#define INT_MAX
Definition: limits.h:40

Referenced by strstreambuf().

◆ freeze()

void strstreambuf::freeze ( bool  frozenflag = true)

Definition at line 102 of file strstream.cpp.

102 {
103 if (_M_dynamic)
104 _M_frozen = frozenflag;
105}

Referenced by ostrstream::freeze(), strstream::freeze(), and str().

◆ overflow()

strstreambuf::int_type strstreambuf::overflow ( int_type  __c = _Traits::eof())
protectedvirtual

Definition at line 116 of file strstream.cpp.

116 {
117 if (c == traits_type::eof())
118 return traits_type::not_eof(c);
119
120 // Try to expand the buffer.
121 if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) {
122 ptrdiff_t old_size = epptr() - pbase();
123 ptrdiff_t new_size = (max)(2 * old_size, ptrdiff_t(1));
124
125 char* buf = _M_alloc(new_size);
126 if (buf) {
127 memcpy(buf, pbase(), old_size);
128
129 char* old_buffer = pbase();
130 bool reposition_get = false;
131 ptrdiff_t old_get_offset;
132 if (gptr() != 0) {
133 reposition_get = true;
134 old_get_offset = gptr() - eback();
135 }
136
137 setp(buf, buf + new_size);
138 pbump((int)old_size);
139
140 if (reposition_get)
141 setg(buf, buf + old_get_offset, buf + (max)(old_get_offset, old_size));
142
143 _M_free(old_buffer);
144 }
145 }
146
147 if (pptr() != epptr()) {
148 *pptr() = traits_type::to_char_type(c);
149 pbump(1);
150 return c;
151 }
152 else
153 return traits_type::eof();
154}
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ pbackfail()

strstreambuf::int_type strstreambuf::pbackfail ( int_type  __c = _Traits::eof())
protectedvirtual

Definition at line 156 of file strstream.cpp.

156 {
157 if (gptr() != eback()) {
158 if (c == traits_type::eof()) {
159 gbump(-1);
160 return traits_type::not_eof(c);
161 }
162 else if (c == gptr()[-1]) {
163 gbump(-1);
164 return c;
165 }
166 else if (!_M_constant) {
167 gbump(-1);
168 *gptr() = traits_type::to_char_type(c);
169 return c;
170 }
171 }
172
173 return traits_type::eof();
174}

◆ pcount()

int strstreambuf::pcount ( ) const

Definition at line 112 of file strstream.cpp.

112 {
113 return int(pptr() ? pptr() - pbase() : 0);
114}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by ostrstream::pcount(), and strstream::pcount().

◆ seekoff()

strstreambuf::pos_type strstreambuf::seekoff ( off_type  __off,
ios_base::seekdir  __dir,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
protectedvirtual

Definition at line 192 of file strstream.cpp.

193 {
194 bool do_get = false;
195 bool do_put = false;
196
197 if ((mode & (ios_base::in | ios_base::out)) ==
198 (ios_base::in | ios_base::out) &&
199 (dir == ios_base::beg || dir == ios_base::end))
200 do_get = do_put = true;
201 else if (mode & ios_base::in)
202 do_get = true;
203 else if (mode & ios_base::out)
204 do_put = true;
205
206 // !gptr() is here because, according to D.7.1 paragraph 4, the seekable
207 // area is undefined if there is no get area.
208 if ((!do_get && !do_put) || (do_put && !pptr()) || !gptr())
209 return pos_type(off_type(-1));
210
211 char* seeklow = eback();
212 char* seekhigh = epptr() ? epptr() : egptr();
213
214 off_type newoff;
215 switch(dir) {
216 case ios_base::beg:
217 newoff = 0;
218 break;
219 case ios_base::end:
220 newoff = seekhigh - seeklow;
221 break;
222 case ios_base::cur:
223 newoff = do_put ? pptr() - seeklow : gptr() - seeklow;
224 break;
225 default:
226 return pos_type(off_type(-1));
227 }
228
229 off += newoff;
230 if (off < 0 || off > seekhigh - seeklow)
231 return pos_type(off_type(-1));
232
233 if (do_put) {
234 if (seeklow + __STATIC_CAST(ptrdiff_t, off) < pbase()) {
235 setp(seeklow, epptr());
236 pbump((int)off);
237 }
238 else {
239 setp(pbase(), epptr());
240 pbump((int)(off - (pbase() - seeklow)));
241 }
242 }
243 if (do_get) {
244 if (off <= egptr() - seeklow)
245 setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), egptr());
246 else if (off <= pptr() - seeklow)
247 setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), pptr());
248 else
249 setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), epptr());
250 }
251
252 return pos_type(newoff);
253}
unsigned int dir
Definition: maze.c:112
GLenum mode
Definition: glext.h:6217

Referenced by seekpos().

◆ seekpos()

strstreambuf::pos_type strstreambuf::seekpos ( pos_type  __pos,
ios_base::openmode  __mode = ios_base::in | ios_base::out 
)
protectedvirtual

Definition at line 256 of file strstream.cpp.

256 {
257 return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode);
258}
virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, ios_base::openmode __mode=ios_base::in|ios_base::out)
Definition: strstream.cpp:192

◆ setbuf()

basic_streambuf< char, char_traits< char > > * strstreambuf::setbuf ( char __buf,
streamsize  __n 
)
protectedvirtual

Definition at line 187 of file strstream.cpp.

187 {
188 return this;
189}

◆ str()

char * strstreambuf::str ( )

Definition at line 107 of file strstream.cpp.

107 {
108 freeze(true);
109 return eback();
110}
void freeze(bool=true)
Definition: strstream.cpp:102

Referenced by istrstream::str(), ostrstream::str(), and strstream::str().

◆ underflow()

strstreambuf::int_type strstreambuf::underflow ( )
protectedvirtual

Reimplemented from basic_streambuf< char, char_traits< char > >.

Definition at line 176 of file strstream.cpp.

176 {
177 if (gptr() == egptr() && pptr() && pptr() > egptr())
178 setg(eback(), gptr(), pptr());
179
180 if (gptr() != egptr())
181 return (unsigned char) *gptr();
182 else
183 return _Traits::eof();
184}

Member Data Documentation

◆ _M_alloc_fun

__alloc_fn strstreambuf::_M_alloc_fun
private

Definition at line 92 of file _strstream.h.

Referenced by _M_alloc().

◆ _M_constant

bool strstreambuf::_M_constant
private

Definition at line 96 of file _strstream.h.

Referenced by overflow(), and pbackfail().

◆ _M_dynamic

bool strstreambuf::_M_dynamic
private

Definition at line 94 of file _strstream.h.

Referenced by freeze(), overflow(), and ~strstreambuf().

◆ _M_free_fun

__free_fn strstreambuf::_M_free_fun
private

Definition at line 93 of file _strstream.h.

Referenced by _M_free().

◆ _M_frozen

bool strstreambuf::_M_frozen
private

Definition at line 95 of file _strstream.h.

Referenced by freeze(), overflow(), and ~strstreambuf().


The documentation for this class was generated from the following files: