ReactOS  0.4.14-dev-49-gfb4591c
_sstream.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999
3  * Silicon Graphics Computer Systems, Inc.
4  *
5  * Copyright (c) 1999
6  * Boris Fomitchev
7  *
8  * This material is provided "as is", with absolutely no warranty expressed
9  * or implied. Any use is at your own risk.
10  *
11  * Permission to use or copy this software for any purpose is hereby granted
12  * without fee, provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  *
17  */
18 
19 
20 // This header defines classes basic_stringbuf, basic_istringstream,
21 // basic_ostringstream, and basic_stringstream. These classes
22 // represent streamsbufs and streams whose sources or destinations are
23 // C++ strings.
24 
25 #ifndef _STLP_INTERNAL_SSTREAM
26 #define _STLP_INTERNAL_SSTREAM
27 
28 #ifndef _STLP_INTERNAL_STREAMBUF
29 # include <stl/_streambuf.h>
30 #endif
31 
32 #ifndef _STLP_INTERNAL_ISTREAM
33 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
34 #endif
35 
36 #ifndef _STLP_INTERNAL_STRING_H
37 # include <stl/_string.h>
38 #endif
39 
41 
42 //----------------------------------------------------------------------
43 // This version of basic_stringbuf relies on the internal details of
44 // basic_string. It relies on the fact that, in this implementation,
45 // basic_string's iterators are pointers. It also assumes (as allowed
46 // by the standard) that _CharT is a POD type.
47 
48 // We have a very small buffer for the put area, just so that we don't
49 // have to use append() for every sputc. Conceptually, the buffer
50 // immediately follows the end of the underlying string. We use this
51 // buffer when appending to write-only streambufs, but we don't use it
52 // for read-write streambufs.
53 
54 template <class _CharT, class _Traits, class _Alloc>
55 class basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
56 public: // Typedefs.
57  typedef _CharT char_type;
58  typedef typename _Traits::int_type int_type;
59  typedef typename _Traits::pos_type pos_type;
60  typedef typename _Traits::off_type off_type;
61  typedef _Traits traits_type;
62 
66 
67 public: // Constructors, destructor.
68  explicit basic_stringbuf(ios_base::openmode __mode
70  explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
72  virtual ~basic_stringbuf();
73 
74 public: // Get or set the string.
75  _String str() const { return _M_str; }
76  void str(const _String& __s);
77 
78 protected: // Overridden virtual member functions.
79  virtual int_type underflow();
80  virtual int_type uflow();
81  virtual int_type pbackfail(int_type __c);
82  virtual int_type overflow(int_type __c);
85 
86  virtual streamsize xsputn(const char_type* __s, streamsize __n);
88 
89  virtual _Base* setbuf(_CharT* __buf, streamsize __n);
90  virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
91  ios_base::openmode __mode
93  virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
95 
96 private: // Helper functions.
97  void _M_set_ptrs();
98  static _CharT* _S_start(const _String& __str) { return __CONST_CAST(_CharT*, __str.data()); }
99  static _CharT* _S_finish(const _String& __str) { return __CONST_CAST(_CharT*, __str.data()) + __str.size(); }
100 
101 private:
104 };
105 
106 #if defined (_STLP_USE_TEMPLATE_EXPORT)
108 # if !defined (_STLP_NO_WCHAR_T)
110 # endif
111 #endif /* _STLP_USE_TEMPLATE_EXPORT */
112 
113 //----------------------------------------------------------------------
114 // Class basic_istringstream, an input stream that uses a stringbuf.
115 
116 template <class _CharT, class _Traits, class _Alloc>
117 class basic_istringstream : public basic_istream<_CharT, _Traits> {
118 public: // Typedefs
119  typedef typename _Traits::char_type char_type;
120  typedef typename _Traits::int_type int_type;
121  typedef typename _Traits::pos_type pos_type;
122  typedef typename _Traits::off_type off_type;
123  typedef _Traits traits_type;
124 
129 
130 public: // Constructors, destructor.
132  basic_istringstream(const _String& __str,
135 
136 public: // Member functions
137 
139  { return __CONST_CAST(_Buf*,&_M_buf); }
140 
141  _String str() const { return _M_buf.str(); }
142  void str(const _String& __s) { _M_buf.str(__s); }
143 
144 private:
146 
147 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
149  //explicitely defined as private to avoid warnings:
150  basic_istringstream(_Self const&);
151  _Self& operator = (_Self const&);
152 #endif
153 };
154 
155 
156 //----------------------------------------------------------------------
157 // Class basic_ostringstream, an output stream that uses a stringbuf.
158 
159 template <class _CharT, class _Traits, class _Alloc>
160 class basic_ostringstream : public basic_ostream<_CharT, _Traits> {
161 public: // Typedefs
162  typedef typename _Traits::char_type char_type;
163  typedef typename _Traits::int_type int_type;
164  typedef typename _Traits::pos_type pos_type;
165  typedef typename _Traits::off_type off_type;
166  typedef _Traits traits_type;
167 
172 
173 public: // Constructors, destructor.
175  basic_ostringstream(const _String& __str,
178 
179 public: // Member functions.
180 
182  { return __CONST_CAST(_Buf*,&_M_buf); }
183 
184  _String str() const { return _M_buf.str(); }
185  void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
186 
187 
188 private:
190 
191 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
193  //explicitely defined as private to avoid warnings:
194  basic_ostringstream(_Self const&);
195  _Self& operator = (_Self const&);
196 #endif
197 };
198 
199 
200 //----------------------------------------------------------------------
201 // Class basic_stringstream, a bidirectional stream that uses a stringbuf.
202 
203 template <class _CharT, class _Traits, class _Alloc>
204 class basic_stringstream : public basic_iostream<_CharT, _Traits> {
205 public: // Typedefs
206  typedef typename _Traits::char_type char_type;
207  typedef typename _Traits::int_type int_type;
208  typedef typename _Traits::pos_type pos_type;
209  typedef typename _Traits::off_type off_type;
210  typedef _Traits traits_type;
211 
216 
218 
219 public: // Constructors, destructor.
221  basic_stringstream(const _String& __str,
224 
225 public: // Member functions.
226 
228  { return __CONST_CAST(_Buf*,&_M_buf); }
229 
230  _String str() const { return _M_buf.str(); }
231  void str(const _String& __s) { _M_buf.str(__s); }
232 
233 private:
235 
236 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
238  //explicitely defined as private to avoid warnings:
239  basic_stringstream(_Self const&);
240  _Self& operator = (_Self const&);
241 #endif
242 };
243 
244 
245 #if defined (_STLP_USE_TEMPLATE_EXPORT)
249 # if !defined (_STLP_NO_WCHAR_T)
253 # endif
254 #endif /* _STLP_USE_TEMPLATE_EXPORT */
255 
257 
258 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
259 # include <stl/_sstream.c>
260 #endif
261 
262 #endif /* _STLP_INTERNAL_SSTREAM */
263 
264 // Local Variables:
265 // mode:C++
266 // End:
_CharT char_type
Definition: _sstream.h:57
_Traits::pos_type pos_type
Definition: _sstream.h:121
basic_string< _CharT, _Traits, _Alloc > _String
Definition: _sstream.h:214
_Traits::off_type off_type
Definition: _sstream.h:209
_Traits::pos_type pos_type
Definition: _sstream.h:164
return __n
Definition: _algo.h:75
_Traits::int_type int_type
Definition: _sstream.h:120
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Definition: _sstream.c:170
_Traits traits_type
Definition: _sstream.h:166
_Traits::char_type char_type
Definition: _sstream.h:162
void str(const _String &__s)
Definition: _sstream.h:142
void operator=(const ios_base &)
_String str() const
Definition: _sstream.h:230
_Traits::pos_type pos_type
Definition: _sstream.h:208
_Traits::off_type off_type
Definition: _sstream.h:165
_String str() const
Definition: _sstream.h:141
const _CharT * data() const
Definition: _string.h:950
virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, ios_base::openmode __mode=ios_base::in|ios_base::out)
Definition: _sstream.c:300
virtual _Base * setbuf(_CharT *__buf, streamsize __n)
Definition: _sstream.c:262
void str(const _String &__s)
Definition: _sstream.h:185
basic_stringbuf< _CharT, _Traits, _Alloc > _Buf
Definition: _sstream.h:215
basic_stringbuf< _CharT, _Traits, _Alloc > * rdbuf() const
Definition: _sstream.h:138
basic_ostream< _CharT, _Traits > _Self
Definition: _ostream.h:54
int seekdir
Definition: _ios_base.h:60
#define __c
Definition: schilyio.h:209
_String _M_str
Definition: _sstream.h:103
_String str() const
Definition: _sstream.h:184
basic_stringbuf< _CharT, _Traits, _Alloc > * rdbuf() const
Definition: _sstream.h:181
size_type size() const
Definition: _string.h:400
ios_base::openmode openmode
Definition: _sstream.h:217
virtual int_type underflow()
Definition: _sstream.c:96
basic_istream< _CharT, _Traits > _Base
Definition: _sstream.h:126
virtual ~basic_stringbuf()
Definition: _sstream.c:58
_Traits::off_type off_type
Definition: _sstream.h:60
Definition: _ios.h:48
int_type pbackfail()
Definition: _sstream.h:83
basic_iostream< _CharT, _Traits > _Base
Definition: _sstream.h:213
basic_streambuf< _CharT, _Traits > _Base
Definition: _sstream.h:63
void _M_set_ptrs()
Definition: _sstream.c:72
_Traits::char_type char_type
Definition: _sstream.h:119
static _CharT * _S_start(const _String &__str)
Definition: _sstream.h:98
static _CharT * _S_finish(const _String &__str)
Definition: _sstream.h:99
basic_stringbuf< _CharT, _Traits, _Alloc > _M_buf
Definition: _sstream.h:145
_Traits::int_type int_type
Definition: _sstream.h:207
_Traits::int_type int_type
Definition: _sstream.h:163
basic_string< _CharT, _Traits, _Alloc > _String
Definition: _sstream.h:127
int_type overflow()
Definition: _sstream.h:84
int openmode
Definition: _ios_base.h:59
static FILE * out
Definition: regtests2xml.c:44
#define _STLP_EXPORT_TEMPLATE_CLASS
Definition: features.h:987
virtual int_type uflow()
Definition: _sstream.c:105
_Traits::char_type char_type
Definition: _sstream.h:206
ios_base::openmode _M_mode
Definition: _sstream.h:102
basic_stringbuf(ios_base::openmode __mode=ios_base::in|ios_base::out)
Definition: _sstream.c:45
_Traits::off_type off_type
Definition: _sstream.h:122
basic_stringbuf< _CharT, _Traits, _Alloc > * rdbuf() const
Definition: _sstream.h:227
basic_stringstream(openmode __mod=ios_base::in|ios_base::out)
Definition: _sstream.c:440
_Traits::pos_type pos_type
Definition: _sstream.h:59
_Traits::int_type int_type
Definition: _sstream.h:58
basic_ios< _CharT, _Traits > _Basic_ios
Definition: _sstream.h:212
virtual streamsize _M_xsputnc(char_type __c, streamsize __n)
Definition: _sstream.c:213
basic_ios< _CharT, _Traits > _Basic_ios
Definition: _sstream.h:168
basic_stringbuf< _CharT, _Traits, _Alloc > _Buf
Definition: _sstream.h:171
basic_ostringstream(ios_base::openmode __mode=ios_base::out)
Definition: _sstream.c:417
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
basic_ios< _CharT, _Traits > _Basic_ios
Definition: _sstream.h:125
basic_stringbuf< _CharT, _Traits, _Alloc > _Self
Definition: _sstream.h:64
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Definition: _sstream.c:358
GLuint in
Definition: glext.h:9616
#define __CONST_CAST(__x, __y)
Definition: features.h:584
_Traits traits_type
Definition: _sstream.h:61
#define _STLP_END_NAMESPACE
Definition: features.h:503
basic_istream< _CharT, _Traits > _Self
Definition: _istream.h:64
_Traits traits_type
Definition: _sstream.h:210
basic_string< _CharT, _Traits, _Alloc > _String
Definition: _sstream.h:65
basic_string< _CharT, _Traits, _Alloc > _String
Definition: _sstream.h:170
ptrdiff_t streamsize
Definition: char_traits.h:81
basic_stringbuf< _CharT, _Traits, _Alloc > _M_buf
Definition: _sstream.h:189
basic_ostream< _CharT, _Traits > _Base
Definition: _sstream.h:169
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
basic_stringbuf< _CharT, _Traits, _Alloc > _M_buf
Definition: _sstream.h:234
_String str() const
Definition: _sstream.h:75
basic_stringbuf< _CharT, _Traits, _Alloc > _Buf
Definition: _sstream.h:128
void str(const _String &__s)
Definition: _sstream.h:231
basic_istringstream(ios_base::openmode __mode=ios_base::in)
Definition: _sstream.c:394
_Traits traits_type
Definition: _sstream.h:123