ossrv_pub/io_stream_api/inc/stdapis/stlport/stl/_streambuf.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
     3  *
       
     4  * Copyright (c) 1999
       
     5  * Silicon Graphics Computer Systems, Inc.
       
     6  *
       
     7  * Copyright (c) 1999 
       
     8  * Boris Fomitchev
       
     9  *
       
    10  * This material is provided "as is", with absolutely no warranty expressed
       
    11  * or implied. Any use is at your own risk.
       
    12  *
       
    13  * Permission to use or copy this software for any purpose is hereby granted 
       
    14  * without fee, provided the above notices are retained on all copies.
       
    15  * Permission to modify the code and to distribute modified code is granted,
       
    16  * provided the above notices are retained, and a notice that the code was
       
    17  * modified is included with the above copyright notice.
       
    18  *
       
    19  */ 
       
    20 #ifndef _STLP_STREAMBUF_C
       
    21 #define _STLP_STREAMBUF_C
       
    22 
       
    23 #ifndef _STLP_INTERNAL_STREAMBUF
       
    24 # include <stl/_streambuf.h>
       
    25 #endif
       
    26 
       
    27 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
       
    28 
       
    29 _STLP_BEGIN_NAMESPACE
       
    30 //----------------------------------------------------------------------
       
    31 // Non-inline basic_streambuf<> member functions.
       
    32 
       
    33 template <class _CharT, class _Traits>
       
    34 _STLP_EXP_DECLSPEC basic_streambuf<_CharT, _Traits>::basic_streambuf()
       
    35   : _M_gbegin(0), _M_gnext(0), _M_gend(0),
       
    36     _M_pbegin(0), _M_pnext(0), _M_pend(0),
       
    37     _M_locale()
       
    38 {
       
    39   //  _M_lock._M_initialize();
       
    40 }
       
    41 
       
    42 template <class _CharT, class _Traits>
       
    43 _STLP_EXP_DECLSPEC  basic_streambuf<_CharT, _Traits>::~basic_streambuf() 
       
    44 {}
       
    45 
       
    46 
       
    47 template <class _CharT, class _Traits>
       
    48 _STLP_EXP_DECLSPEC locale 
       
    49 basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
       
    50   this->imbue(__loc);
       
    51   locale __tmp = _M_locale;
       
    52   _M_locale = __loc;
       
    53   return __tmp;
       
    54 }
       
    55 
       
    56 template <class _CharT, class _Traits>
       
    57 _STLP_EXP_DECLSPEC streamsize
       
    58 basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n)
       
    59 {
       
    60   streamsize __result = 0;
       
    61   const int_type __eof = _Traits::eof();
       
    62 
       
    63   while (__result < __n) {
       
    64     if (_M_gnext < _M_gend) {
       
    65       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
       
    66                            __STATIC_CAST(size_t,__n - __result));
       
    67       _Traits::copy(__s, _M_gnext, __chunk);
       
    68       __result += __chunk;
       
    69       __s += __chunk;
       
    70       _M_gnext += __chunk;
       
    71     }
       
    72     else {
       
    73       int_type __c = this->sbumpc();
       
    74       if (!_Traits::eq_int_type(__c, __eof)) {
       
    75         *__s = __c;
       
    76         ++__result;
       
    77 	++__s;
       
    78       }
       
    79       else
       
    80         break; 
       
    81     }
       
    82   }
       
    83   
       
    84   return __result;
       
    85 }
       
    86 
       
    87 template <class _CharT, class _Traits>
       
    88 _STLP_EXP_DECLSPEC streamsize
       
    89 basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
       
    90 {
       
    91   streamsize __result = 0;
       
    92   const int_type __eof = _Traits::eof();
       
    93 
       
    94   while (__result < __n) {
       
    95     if (_M_pnext < _M_pend) {
       
    96       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
       
    97                            __STATIC_CAST(size_t,__n - __result));
       
    98       _Traits::copy(_M_pnext, __s, __chunk);
       
    99       __result += __chunk;
       
   100       __s += __chunk;
       
   101       _M_pnext += __chunk;
       
   102     }
       
   103 
       
   104     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
       
   105                                    __eof)) {
       
   106       ++__result;
       
   107       ++__s;
       
   108     }
       
   109     else
       
   110       break;
       
   111   }
       
   112   return __result;
       
   113 }
       
   114 
       
   115 template <class _CharT, class _Traits>
       
   116 _STLP_EXP_DECLSPEC streamsize
       
   117 basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
       
   118 {
       
   119   streamsize __result = 0;
       
   120   const int_type __eof = _Traits::eof();
       
   121 
       
   122   while (__result < __n) {
       
   123     if (_M_pnext < _M_pend) {
       
   124       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
       
   125                            __STATIC_CAST(size_t,__n - __result));
       
   126       _Traits::assign(_M_pnext, __chunk, __c);
       
   127       __result += __chunk;
       
   128       _M_pnext += __chunk;
       
   129     }
       
   130 
       
   131     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
       
   132                                    __eof))
       
   133       ++__result;
       
   134     else
       
   135       break;
       
   136   }
       
   137   return __result;
       
   138 }
       
   139 
       
   140 template <class _CharT, class _Traits>
       
   141 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
       
   142 basic_streambuf<_CharT, _Traits>::_M_snextc_aux()  
       
   143 {
       
   144   int_type __eof = _Traits::eof();
       
   145   if (_M_gend == _M_gnext)
       
   146     return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
       
   147   else {
       
   148     _M_gnext = _M_gend;
       
   149     return this->underflow();
       
   150   }
       
   151 }
       
   152 
       
   153 template <class _CharT, class _Traits>
       
   154 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
       
   155 basic_streambuf<_CharT, _Traits>::pbackfail(int_type) { 
       
   156  return _Traits::eof(); 
       
   157 }
       
   158 
       
   159 template <class _CharT, class _Traits>
       
   160 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
       
   161 basic_streambuf<_CharT, _Traits>::overflow(int_type) { 
       
   162   return _Traits::eof(); 
       
   163 }
       
   164 
       
   165 template <class _CharT, class _Traits>
       
   166 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
       
   167 basic_streambuf<_CharT, _Traits>::uflow() {
       
   168     return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
       
   169              _Traits::eof() :
       
   170              _Traits::to_int_type(*_M_gnext++));
       
   171 }
       
   172 
       
   173 template <class _CharT, class _Traits>
       
   174 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
       
   175 basic_streambuf<_CharT, _Traits>::underflow()
       
   176 { return _Traits::eof(); }
       
   177 
       
   178 template <class _CharT, class _Traits>
       
   179 _STLP_EXP_DECLSPEC streamsize 
       
   180 basic_streambuf<_CharT, _Traits>::showmanyc()
       
   181 { return 0; }
       
   182 
       
   183 template <class _CharT, class _Traits>
       
   184 _STLP_EXP_DECLSPEC void 
       
   185 basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
       
   186 
       
   187 template <class _CharT, class _Traits>
       
   188 _STLP_EXP_DECLSPEC int
       
   189 basic_streambuf<_CharT, _Traits>::sync() { return 0; }
       
   190 
       
   191 template <class _CharT, class _Traits>
       
   192 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type 
       
   193 basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
       
   194 { return pos_type(-1); }
       
   195 
       
   196 template <class _CharT, class _Traits>
       
   197 _STLP_EXP_DECLSPEC _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type 
       
   198 basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
       
   199 					  ios_base::openmode)
       
   200 { return pos_type(-1); }
       
   201 
       
   202 template <class _CharT, class _Traits>
       
   203 _STLP_EXP_DECLSPEC basic_streambuf<_CharT, _Traits>* 
       
   204 basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
       
   205 { return this; }
       
   206 
       
   207 
       
   208 # if defined (_STLP_USE_TEMPLATE_EXPORT)
       
   209 #  if !defined (_STLP_NO_WCHAR_T)
       
   210 _STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >;
       
   211 #  endif
       
   212 # endif /* _STLP_USE_TEMPLATE_EXPORT */
       
   213 
       
   214 _STLP_END_NAMESPACE
       
   215 
       
   216 # endif /* EXPOSE */
       
   217 
       
   218 #endif