31
|
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 |
#ifndef _STLP_SSTREAM_C
|
|
20 |
#define _STLP_SSTREAM_C
|
|
21 |
|
|
22 |
#ifndef _STLP_INTERNAL_SSTREAM
|
|
23 |
# include <stl/_sstream.h>
|
|
24 |
#endif
|
|
25 |
|
|
26 |
#if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
|
|
27 |
// no wint_t is supported for this mode
|
|
28 |
# define __BSB_int_type__ int
|
|
29 |
# define __BSB_pos_type__ streampos
|
|
30 |
#else
|
|
31 |
# define __BSB_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
|
|
32 |
# define __BSB_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
|
|
33 |
#endif
|
|
34 |
|
|
35 |
_STLP_BEGIN_NAMESPACE
|
|
36 |
|
|
37 |
//----------------------------------------------------------------------
|
|
38 |
// Non-inline stringbuf member functions.
|
|
39 |
|
|
40 |
// Constructors. Note that the base class constructor sets all of the
|
|
41 |
// get and area pointers to null.
|
|
42 |
|
|
43 |
template <class _CharT, class _Traits, class _Alloc>
|
|
44 |
basic_stringbuf<_CharT, _Traits, _Alloc>
|
|
45 |
::basic_stringbuf(ios_base::openmode __mode)
|
|
46 |
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str()
|
|
47 |
{}
|
|
48 |
|
|
49 |
template <class _CharT, class _Traits, class _Alloc>
|
|
50 |
basic_stringbuf<_CharT, _Traits, _Alloc>
|
|
51 |
::basic_stringbuf(const basic_string<_CharT, _Traits, _Alloc>& __s, ios_base::openmode __mode)
|
|
52 |
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str(__s)
|
|
53 |
{
|
|
54 |
_M_set_ptrs();
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
// Set the underlying string to a new value.
|
|
60 |
template <class _CharT, class _Traits, class _Alloc>
|
|
61 |
void
|
|
62 |
basic_stringbuf<_CharT, _Traits, _Alloc>::str(const basic_string<_CharT, _Traits, _Alloc>& __s)
|
|
63 |
{
|
|
64 |
_M_str = __s;
|
|
65 |
_M_set_ptrs();
|
|
66 |
}
|
|
67 |
|
|
68 |
template <class _CharT, class _Traits, class _Alloc>
|
|
69 |
void
|
|
70 |
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_set_ptrs() {
|
|
71 |
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
|
|
72 |
_CharT* __data_end = __data_ptr + _M_str.size();
|
|
73 |
// The initial read position is the beginning of the string.
|
|
74 |
if (_M_mode & ios_base::in) {
|
|
75 |
if (_M_mode & ios_base::ate)
|
|
76 |
this->setg(__data_ptr, __data_end, __data_end);
|
|
77 |
else
|
|
78 |
this->setg(__data_ptr, __data_ptr, __data_end);
|
|
79 |
}
|
|
80 |
|
|
81 |
// The initial write position is the beginning of the string.
|
|
82 |
if (_M_mode & ios_base::out) {
|
|
83 |
if (_M_mode & (ios_base::app | ios_base::ate))
|
|
84 |
this->setp(__data_end, __data_end);
|
|
85 |
else
|
|
86 |
this->setp(__data_ptr, __data_end);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
// This is declared as a const member function because it is
|
|
94 |
// called by basic_stringbuf<>::str(). Precondition: this is a
|
|
95 |
// write-only stringbuf. We can't use an output buffer for read-
|
|
96 |
// write stringbufs. Postcondition: pptr is reset to the beginning
|
|
97 |
// of the buffer.
|
|
98 |
template <class _CharT, class _Traits, class _Alloc>
|
|
99 |
void basic_stringbuf<_CharT, _Traits, _Alloc>::_M_append_buffer() const {
|
|
100 |
// Do we have a buffer to append?
|
|
101 |
if (this->pbase() == this->_M_Buf && this->pptr() != this->_M_Buf) {
|
|
102 |
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
|
|
103 |
__this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
|
|
104 |
#ifndef __MWERKS__
|
|
105 |
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
|
|
106 |
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
|
107 |
#else // CodeWarrior treat const char * and const char [8] as different types
|
|
108 |
__this->setp((_CharT*)_M_Buf,
|
|
109 |
(_CharT*)(_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
|
110 |
#endif
|
|
111 |
}
|
|
112 |
|
|
113 |
// Have we run off the end of the string?
|
|
114 |
else if (this->pptr() == this->epptr()) {
|
|
115 |
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
|
|
116 |
#ifndef __MWERKS__
|
|
117 |
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
|
|
118 |
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
|
119 |
#else // CodeWarrior treat const char * and const char [8] as different types
|
|
120 |
__this->setp((_CharT*)_M_Buf,
|
|
121 |
(_CharT*)(_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
|
|
122 |
#endif
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
//----------------------------------------------------------------------
|
|
127 |
// Non-inline istringstream member functions.
|
|
128 |
|
|
129 |
template <class _CharT, class _Traits, class _Alloc>
|
|
130 |
basic_istringstream<_CharT, _Traits, _Alloc>
|
|
131 |
::basic_istringstream(ios_base::openmode __mode)
|
|
132 |
: basic_istream<_CharT, _Traits>(0),
|
|
133 |
_M_buf(__mode | ios_base::in) {
|
|
134 |
this->init(&_M_buf);
|
|
135 |
}
|
|
136 |
|
|
137 |
template <class _CharT, class _Traits, class _Alloc>
|
|
138 |
basic_istringstream<_CharT, _Traits, _Alloc>
|
|
139 |
::basic_istringstream(const _String& __str,ios_base::openmode __mode)
|
|
140 |
: basic_istream<_CharT, _Traits>(0),
|
|
141 |
_M_buf(__str, __mode | ios_base::in) {
|
|
142 |
this->init(&_M_buf);
|
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
//----------------------------------------------------------------------
|
|
148 |
// Non-inline ostringstream member functions.
|
|
149 |
|
|
150 |
template <class _CharT, class _Traits, class _Alloc>
|
|
151 |
basic_ostringstream<_CharT, _Traits, _Alloc>
|
|
152 |
::basic_ostringstream(ios_base::openmode __mode)
|
|
153 |
: basic_ostream<_CharT, _Traits>(0),
|
|
154 |
_M_buf(__mode | ios_base::out) {
|
|
155 |
this->init(&_M_buf);
|
|
156 |
}
|
|
157 |
|
|
158 |
template <class _CharT, class _Traits, class _Alloc>
|
|
159 |
basic_ostringstream<_CharT, _Traits, _Alloc>
|
|
160 |
::basic_ostringstream(const _String& __str, ios_base::openmode __mode)
|
|
161 |
: basic_ostream<_CharT, _Traits>(0),
|
|
162 |
_M_buf(__str, __mode | ios_base::out) {
|
|
163 |
this->init(&_M_buf);
|
|
164 |
}
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
//----------------------------------------------------------------------
|
|
169 |
// Non-inline stringstream member functions.
|
|
170 |
|
|
171 |
template <class _CharT, class _Traits, class _Alloc>
|
|
172 |
basic_stringstream<_CharT, _Traits, _Alloc>
|
|
173 |
::basic_stringstream(ios_base::openmode __mode)
|
|
174 |
: basic_iostream<_CharT, _Traits>(0), _M_buf(__mode) {
|
|
175 |
this->init(&_M_buf);
|
|
176 |
}
|
|
177 |
|
|
178 |
template <class _CharT, class _Traits, class _Alloc>
|
|
179 |
basic_stringstream<_CharT, _Traits, _Alloc>
|
|
180 |
::basic_stringstream(const _String& __str, ios_base::openmode __mode)
|
|
181 |
: basic_iostream<_CharT, _Traits>(0), _M_buf(__str, __mode) {
|
|
182 |
this->init(&_M_buf);
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
_STLP_END_NAMESPACE
|
|
191 |
|
|
192 |
# undef __BSB_int_type__
|
|
193 |
# undef __BSB_pos_type__
|
|
194 |
|
|
195 |
#endif /* _STLP_SSTREAM_C */
|
|
196 |
|
|
197 |
// Local Variables:
|
|
198 |
// mode:C++
|
|
199 |
// End:
|