1
/* Copyright (C) 2004 Garrett A. Kajmowicz
3
This file is part of the uClibc++ Library.
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <basic_definitions>
25
#ifndef HEADER_STD_STREAMBUF
26
#define HEADER_STD_STREAMBUF 1
30
#pragma GCC visibility push(default)
34
template <class charT, class traits> class _UCXXEXPORT basic_streambuf{
36
#ifdef __UCLIBCXX_SUPPORT_CDIR__
37
friend ios_base::Init::Init();
40
typedef charT char_type;
41
typedef typename traits::int_type int_type;
42
typedef typename traits::pos_type pos_type;
43
typedef typename traits::off_type off_type;
44
typedef traits traits_type;
46
virtual ~basic_streambuf();
48
locale pubimbue(const locale &loc);
50
locale getloc() const{
54
basic_streambuf<char_type,traits>* pubsetbuf(char_type* s, streamsize n){
57
pos_type pubseekoff(off_type off,
58
typename ios_base::seekdir way,
59
ios_base::openmode which = ios_base::in |
63
return seekoff(off,way,which);
65
pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out){
66
return seekpos(sp,which);
72
streamsize in_avail();
80
streamsize sgetn(char_type* s, streamsize n){
84
int_type sputbackc(char_type c);
88
int_type sputc(char_type c);
90
streamsize sputn(const char_type* s, streamsize n){
91
if(openedFor & ios_base::app){
92
seekoff(0, ios_base::end, ios_base::out);
99
//Pointers for the "get" buffers
104
//Pointers for the "put" buffers
109
//In the event of null buffers Lets us know what the buffer is opened for
110
ios_base::openmode openedFor;
114
basic_streambuf(const basic_streambuf<char, char_traits<char> > &)
116
mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0),
119
basic_streambuf<char, char_traits<char> > & operator=(const basic_streambuf<char, char_traits<char> > &){
123
char_type* eback() const{
126
char_type* gptr() const{
129
char_type* egptr() const{
135
void setg(char_type* gbeg, char_type* gnext, char_type* gend){
141
char_type* pbase() const{
144
char_type* pptr() const{
147
char_type* epptr() const{
153
void setp(char_type* pbeg, char_type* pend){
159
virtual void imbue(const locale &loc){
163
//Virtual functions which we will not implement
165
virtual basic_streambuf<char_type,traits>* setbuf(char_type* , streamsize){
168
virtual pos_type seekoff(off_type , ios_base::seekdir,
169
ios_base::openmode = ios_base::in | ios_base::out)
173
virtual pos_type seekpos(pos_type , ios_base::openmode = ios_base::in | ios_base::out){
180
virtual int showmanyc(){
183
virtual streamsize xsgetn(char_type* , streamsize ){
186
virtual int_type underflow(){
187
return traits_type::eof();
189
virtual int_type uflow(){
190
int_type ret = underflow();
191
if (!traits_type::eq_int_type(ret, traits_type::eof()))
196
virtual int_type pbackfail(int_type c = traits::eof()){
199
virtual streamsize xsputn(const char_type* c, streamsize n){
200
//This function is designed to be replaced by subclasses
201
for(streamsize i = 0; i< n; ++i){
202
if(sputc(c[i]) == traits::eof()){
208
virtual int_type overflow (int_type c = traits::eof()){
213
typedef basic_streambuf<char> streambuf;
214
#ifdef __UCLIBCXX_HAS_WCHAR__
215
typedef basic_streambuf<wchar_t> wstreambuf;
219
//Definitions put below to allow for easy expansion of code
221
template <class C, class T> basic_streambuf<C, T>::~basic_streambuf(){ }
223
template <class C, class T> locale basic_streambuf<C, T>::pubimbue(const locale &loc){
224
locale temp = myLocale;
229
template <class C, class T> streamsize basic_streambuf<C, T>::in_avail(){
230
if(mgend !=0 && mgnext !=0){
231
return mgend - mgnext;
236
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::sbumpc(){
237
if(mgbeg == 0 || mgnext == mgend){
240
int_type retval = T::to_int_type(*gptr());
245
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::snextc(){
246
if(sbumpc() == T::eof() ){
252
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::sgetc(){
253
if(mgbeg == 0 || mgnext == mgend){
256
return T::to_int_type(*gptr());
259
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::sputbackc(char_type c){
260
if(mgbeg == 0 || mgnext == mgbeg || !T::eq(c, gptr()[-1] )){
261
return pbackfail(T::to_int_type(c));
264
return T::to_int_type(*gptr());
267
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::sungetc(){
268
if(mgbeg == 0 || mgnext == mgbeg){
269
return ios_base::failbit;
272
return T::to_int_type(*gptr());
275
template <class C, class T> typename basic_streambuf<C, T>::int_type basic_streambuf<C, T>::sputc(char_type c){
276
if(openedFor & ios_base::app){
277
seekoff(0, ios_base::end, ios_base::out);
283
return overflow( T::to_int_type(c) );
285
return T::to_int_type(c);
288
template <class C, class T> basic_streambuf<C, T>::basic_streambuf()
290
mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0),
299
#ifdef __UCLIBCXX_EXPAND_STREAMBUF_CHAR__
300
#ifndef __UCLIBCXX_COMPILE_STREAMBUF__
302
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
304
template <> _UCXXEXPORT streambuf::basic_streambuf();
305
template <> _UCXXEXPORT streambuf::~basic_streambuf();
307
#endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
309
template <> _UCXXEXPORT locale streambuf::pubimbue(const locale &loc);
310
template <> _UCXXEXPORT streamsize streambuf::in_avail();
311
template <> _UCXXEXPORT streambuf::int_type streambuf::sbumpc();
312
template <> _UCXXEXPORT streambuf::int_type streambuf::snextc();
313
template <> _UCXXEXPORT streambuf::int_type streambuf::sgetc();
314
template <> _UCXXEXPORT streambuf::int_type streambuf::sputbackc(char_type c);
315
template <> _UCXXEXPORT streambuf::int_type streambuf::sungetc();
316
template <> _UCXXEXPORT streambuf::int_type streambuf::sputc(char_type c);
327
#pragma GCC visibility pop