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 #ifndef _STLP_STREAMBUF_C
19 #define _STLP_STREAMBUF_C
20 
21 #ifndef _STLP_INTERNAL_STREAMBUF
22 #  include <stl/_streambuf.h>
23 #endif
24 
25 _STLP_BEGIN_NAMESPACE
26 //----------------------------------------------------------------------
27 // Non-inline basic_streambuf<> member functions.
28 
29 #if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300) || !defined (_STLP_USE_STATIC_LIB)
30 template <class _CharT, class _Traits>
basic_streambuf()31 basic_streambuf<_CharT, _Traits>::basic_streambuf()
32   : _M_gbegin(0), _M_gnext(0), _M_gend(0),
33     _M_pbegin(0), _M_pnext(0), _M_pend(0),
34     _M_locale() {
35   //  _M_lock._M_initialize();
36 }
37 #endif
38 
39 template <class _CharT, class _Traits>
~basic_streambuf()40 basic_streambuf<_CharT, _Traits>::~basic_streambuf()
41 {}
42 
43 template <class _CharT, class _Traits>
44 locale
pubimbue(const locale & __loc)45 basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
46   this->imbue(__loc);
47   locale __tmp = _M_locale;
48   _M_locale = __loc;
49   return __tmp;
50 }
51 
52 template <class _CharT, class _Traits>
53 streamsize
xsgetn(_CharT * __s,streamsize __n)54 basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n) {
55   streamsize __result = 0;
56   const int_type __eof = _Traits::eof();
57 
58   while (__result < __n) {
59     if (_M_gnext < _M_gend) {
60       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
61                               __STATIC_CAST(size_t,__n - __result));
62       _Traits::copy(__s, _M_gnext, __chunk);
63       __result += __chunk;
64       __s += __chunk;
65       _M_gnext += __chunk;
66     }
67     else {
68       int_type __c = this->sbumpc();
69       if (!_Traits::eq_int_type(__c, __eof)) {
70         *__s = _Traits::to_char_type(__c);
71         ++__result;
72         ++__s;
73       }
74       else
75         break;
76     }
77   }
78 
79   return __result;
80 }
81 
82 template <class _CharT, class _Traits>
83 streamsize
xsputn(const _CharT * __s,streamsize __n)84 basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
85 {
86   streamsize __result = 0;
87   const int_type __eof = _Traits::eof();
88 
89   while (__result < __n) {
90     if (_M_pnext < _M_pend) {
91       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
92                            __STATIC_CAST(size_t,__n - __result));
93       _Traits::copy(_M_pnext, __s, __chunk);
94       __result += __chunk;
95       __s += __chunk;
96       _M_pnext += __chunk;
97     }
98 
99     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
100                                    __eof)) {
101       ++__result;
102       ++__s;
103     }
104     else
105       break;
106   }
107   return __result;
108 }
109 
110 template <class _CharT, class _Traits>
111 streamsize
_M_xsputnc(_CharT __c,streamsize __n)112 basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
113 {
114   streamsize __result = 0;
115   const int_type __eof = _Traits::eof();
116 
117   while (__result < __n) {
118     if (_M_pnext < _M_pend) {
119       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
120                            __STATIC_CAST(size_t,__n - __result));
121       _Traits::assign(_M_pnext, __chunk, __c);
122       __result += __chunk;
123       _M_pnext += __chunk;
124     }
125 
126     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
127                                    __eof))
128       ++__result;
129     else
130       break;
131   }
132   return __result;
133 }
134 
135 template <class _CharT, class _Traits>
136 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
_M_snextc_aux()137 basic_streambuf<_CharT, _Traits>::_M_snextc_aux()
138 {
139   int_type __eof = _Traits::eof();
140   if (_M_gend == _M_gnext)
141     return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
142   else {
143     _M_gnext = _M_gend;
144     return this->underflow();
145   }
146 }
147 
148 template <class _CharT, class _Traits>
149 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
pbackfail(int_type)150 basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
151  return _Traits::eof();
152 }
153 
154 template <class _CharT, class _Traits>
155 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
overflow(int_type)156 basic_streambuf<_CharT, _Traits>::overflow(int_type) {
157   return _Traits::eof();
158 }
159 
160 template <class _CharT, class _Traits>
161 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
uflow()162 basic_streambuf<_CharT, _Traits>::uflow() {
163     return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
164              _Traits::eof() :
165              _Traits::to_int_type(*_M_gnext++));
166 }
167 
168 template <class _CharT, class _Traits>
169 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
underflow()170 basic_streambuf<_CharT, _Traits>::underflow()
171 { return _Traits::eof(); }
172 
173 template <class _CharT, class _Traits>
174 streamsize
showmanyc()175 basic_streambuf<_CharT, _Traits>::showmanyc()
176 { return 0; }
177 
178 template <class _CharT, class _Traits>
179 void
imbue(const locale &)180 basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
181 
182 template <class _CharT, class _Traits>
183 int
sync()184 basic_streambuf<_CharT, _Traits>::sync() { return 0; }
185 
186 template <class _CharT, class _Traits>
187 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
seekpos(pos_type,ios_base::openmode)188 basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
189 { return pos_type(-1); }
190 
191 template <class _CharT, class _Traits>
192 _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
seekoff(off_type,ios_base::seekdir,ios_base::openmode)193 basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
194                                           ios_base::openmode)
195 { return pos_type(-1); }
196 
197 template <class _CharT, class _Traits>
198 basic_streambuf<_CharT, _Traits>*
setbuf(char_type *,streamsize)199 basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
200 { return this; }
201 
202 _STLP_END_NAMESPACE
203 
204 #endif
205 
206 // Local Variables:
207 // mode:C++
208 // End:
209