diff -r 000000000000 -r e4d67989cc36 stdcpp/src/streambuf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stdcpp/src/streambuf.cpp Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,254 @@ +/* + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. + * + * Copyright (c) 1999 + * Silicon Graphics Computer Systems, Inc. + * + * Copyright (c) 1999 + * Boris Fomitchev + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ +# include "stlport_prefix.h" + + +#include +#include + +// Implementation of non-inline member functions of class +// basic_streambuf > + +# if defined (__hpux) +# define FILE_CAST(x) (__REINTERPRET_CAST(FILE*, x)) +# else +# define FILE_CAST(x) x +# endif + +_STLP_BEGIN_NAMESPACE + +#if !defined(_STLP_WINCE) + +_STLP_EXP_DECLSPEC basic_streambuf >::~basic_streambuf() {} + +// This constructor is an extension. It is for streambuf subclasses that +// are synchronized with C stdio files. +_STLP_EXP_DECLSPEC basic_streambuf > + ::basic_streambuf(FILE* __get, FILE* __put) + : _M_get(__get ? __get : FILE_CAST(&_M_default_get)), + _M_put(__put ? __put : FILE_CAST(&_M_default_put)), + _M_locale() +{ + _M_lock._M_initialize(); + + if (_M_get == FILE_CAST(&_M_default_get)) + _FILE_I_set(_M_get, 0, 0, 0); + if (_M_put == FILE_CAST(&_M_default_put)) + _FILE_O_set(_M_put, 0, 0, 0); +} + +_STLP_EXP_DECLSPEC basic_streambuf > + ::basic_streambuf _STLP_PSPEC2(char, char_traits) () + : _M_get(__REINTERPRET_CAST(FILE*,&_M_default_get)), + _M_put(__REINTERPRET_CAST(FILE*,&_M_default_put)), _M_locale() + { + // _M_lock._M_initialize(); + _FILE_I_set(_M_get, 0, 0, 0); + _FILE_O_set(_M_put, 0, 0, 0); + } + +// virtual functions + +_STLP_EXP_DECLSPEC void basic_streambuf >::imbue(const locale&) +{} + +_STLP_EXP_DECLSPEC basic_streambuf >* +basic_streambuf >::setbuf(char*, streamsize) +{ + return this; +} + +_STLP_EXP_DECLSPEC basic_streambuf >::pos_type +basic_streambuf > + ::seekoff(off_type, ios_base::seekdir, ios_base::openmode) +{ + return pos_type(-1); +} + +_STLP_EXP_DECLSPEC basic_streambuf >::pos_type +basic_streambuf > + ::seekpos(pos_type, ios_base::openmode) +{ + return pos_type(-1); +} + +_STLP_EXP_DECLSPEC int basic_streambuf >::sync() +{ + return 0; +} + +_STLP_EXP_DECLSPEC streamsize basic_streambuf >::showmanyc() +{ + return 0; +} + +_STLP_EXP_DECLSPEC streamsize basic_streambuf > + ::xsgetn(char* s, streamsize n) +{ + streamsize result = 0; + const int_type eof = traits_type::eof(); + + while (result < n) { + if (_FILE_I_avail(_M_get) > 0) { + size_t chunk = (min) (__STATIC_CAST(size_t,_FILE_I_avail(_M_get)), + __STATIC_CAST(size_t,n - result)); + traits_type::copy(s, _FILE_I_next(_M_get), chunk); + result += chunk; + s += chunk; + _FILE_I_bump(_M_get, chunk); + } + else { + int_type c = sbumpc(); + if (c != eof) { + *s = c; + ++result; + ++s; + } + else + break; + } + } + + return result; +} + +_STLP_EXP_DECLSPEC basic_streambuf >::int_type +basic_streambuf >::underflow() +{ + return traits_type::eof(); +} + +_STLP_EXP_DECLSPEC basic_streambuf >::int_type +basic_streambuf >::uflow() +{ + const int_type eof = traits_type::eof(); + return this->underflow() == eof + ? eof + : traits_type::to_int_type(_FILE_I_postincr(_M_get)); +} + +_STLP_EXP_DECLSPEC basic_streambuf >::int_type +basic_streambuf >::pbackfail(int_type /* __c */) +{ + return traits_type::eof(); +} + + +_STLP_EXP_DECLSPEC streamsize basic_streambuf > + ::xsputn(const char* s, streamsize n) +{ + streamsize result = 0; + const int_type eof = traits_type::eof(); + + while (result < n) { + if (_FILE_O_avail(_M_put) > 0) { + size_t chunk = (min) (__STATIC_CAST(size_t,_FILE_O_avail(_M_put)), + __STATIC_CAST(size_t,n - result)); + traits_type::copy(_FILE_O_next(_M_put), s, chunk); + result += chunk; + s += chunk; + _FILE_O_bump(_M_put, (int)chunk); + } + + else if (this->overflow(traits_type::to_int_type(*s)) != eof) { + ++result; + ++s; + } + else + break; + } + return result; +} + +_STLP_EXP_DECLSPEC streamsize basic_streambuf > + ::_M_xsputnc(char c, streamsize n) +{ + streamsize result = 0; + const int_type eof = traits_type::eof(); + + while (result < n) { + if (_FILE_O_avail(_M_put) > 0) { + size_t chunk = (min) (__STATIC_CAST(size_t,_FILE_O_avail(_M_put)), + __STATIC_CAST(size_t,n - result)); + traits_type::assign(_FILE_O_next(_M_put), chunk, c); + result += chunk; + _FILE_O_bump(_M_put, (int)chunk); + } + + else if (this->overflow(traits_type::to_int_type(c)) != eof) + ++result; + else + break; + } + return result; +} + +_STLP_EXP_DECLSPEC basic_streambuf >::int_type +basic_streambuf >::overflow(int_type/* c */) +{ + return traits_type::eof(); +} + +_STLP_EXP_DECLSPEC basic_streambuf >::int_type +basic_streambuf >::_M_snextc_aux() +{ + int_type eof = traits_type::eof(); + if (_FILE_I_avail(_M_get) == 0) + return this->uflow() == eof ? eof : this->sgetc(); + else { + _FILE_I_set(_M_get, + _FILE_I_begin(_M_get), _FILE_I_end(_M_get), _FILE_I_end(_M_get)); + return this->underflow(); + } +} + + +_STLP_EXP_DECLSPEC locale basic_streambuf >::pubimbue(const locale& loc) +{ + this->imbue(loc); + locale tmp = _M_locale; + _M_locale = loc; + return tmp; +} + +#else + +#if !defined(_STLP_NO_FORCE_INSTANTIATE) +template class basic_streambuf >; +#endif + +#endif /* _STLP_WINCE */ + +//---------------------------------------------------------------------- +// Force instantiation of basic_streambuf + +// not basic_streambuf, because it's specialized. + +#if !defined(_STLP_NO_FORCE_INSTANTIATE) +#if !defined (_STLP_NO_WCHAR_T) +template class basic_streambuf >; +#endif /* INSTANTIATE_WIDE_STREAMS */ +#endif + +_STLP_END_NAMESPACE + +// Local Variables: +// mode:C++ +// End: