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)
30template <class _CharT, class _Traits>
31basic_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
39template <class _CharT, class _Traits>
40basic_streambuf<_CharT, _Traits>::~basic_streambuf()
41{}
42
43template <class _CharT, class _Traits>
44locale
45basic_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
52template <class _CharT, class _Traits>
53streamsize
54basic_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
82template <class _CharT, class _Traits>
83streamsize
84basic_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
110template <class _CharT, class _Traits>
111streamsize
112basic_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
135template <class _CharT, class _Traits>
136_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
137basic_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
148template <class _CharT, class _Traits>
149_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
150basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
151 return _Traits::eof();
152}
153
154template <class _CharT, class _Traits>
155_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
156basic_streambuf<_CharT, _Traits>::overflow(int_type) {
157  return _Traits::eof();
158}
159
160template <class _CharT, class _Traits>
161_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
162basic_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
168template <class _CharT, class _Traits>
169_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
170basic_streambuf<_CharT, _Traits>::underflow()
171{ return _Traits::eof(); }
172
173template <class _CharT, class _Traits>
174streamsize
175basic_streambuf<_CharT, _Traits>::showmanyc()
176{ return 0; }
177
178template <class _CharT, class _Traits>
179void
180basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
181
182template <class _CharT, class _Traits>
183int
184basic_streambuf<_CharT, _Traits>::sync() { return 0; }
185
186template <class _CharT, class _Traits>
187_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
188basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
189{ return pos_type(-1); }
190
191template <class _CharT, class _Traits>
192_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
193basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
194                                          ios_base::openmode)
195{ return pos_type(-1); }
196
197template <class _CharT, class _Traits>
198basic_streambuf<_CharT, _Traits>*
199basic_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