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_IOS
 
 
26
#define __HEADER_STD_IOS 1
 
 
28
#pragma GCC visibility push(default)
 
 
31
        typedef signed long int streamoff;
 
 
33
        template <class stateT> class fpos;
 
 
35
        class _UCXXEXPORT ios_base {
 
 
38
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
 
 
39
                class failure : public exception {
 
 
41
                        explicit failure(const std::string& msg) { }
 
 
42
                        explicit failure() { }
 
 
43
                        virtual const char* what() const throw() {
 
 
44
                                return "std::ios_base failure exception";
 
 
48
#ifdef __UCLIBCXX_SUPPORT_CDIR__
 
 
49
                class _UCXXLOCAL Init{
 
 
60
                typedef unsigned short int fmtflags;
 
 
62
                static const fmtflags skipws            = 0x0001;
 
 
64
                static const fmtflags left              = 0x0002;
 
 
65
                static const fmtflags right             = 0x0004;
 
 
66
                static const fmtflags internal          = 0x0008;
 
 
68
                static const fmtflags boolalpha         = 0x0010;
 
 
70
                static const fmtflags dec               = 0x0020;
 
 
71
                static const fmtflags oct               = 0x0040;
 
 
72
                static const fmtflags hex               = 0x0080;
 
 
74
                static const fmtflags scientific        = 0x0100;
 
 
75
                static const fmtflags fixed             = 0x0200;
 
 
77
                static const fmtflags showbase          = 0x0400;
 
 
78
                static const fmtflags showpoint         = 0x0800;
 
 
79
                static const fmtflags showpos           = 0x1000;
 
 
80
                static const fmtflags uppercase         = 0x2000;
 
 
82
                static const fmtflags adjustfield       = left | right | internal;
 
 
83
                static const fmtflags basefield         = dec | oct | hex;
 
 
84
                static const fmtflags floatfield        = fixed | scientific;
 
 
86
                static const fmtflags unitbuf           = 0x4000;
 
 
88
                typedef unsigned char iostate;
 
 
89
                static const iostate goodbit            = 0x00;
 
 
90
                static const iostate badbit             = 0x01;
 
 
91
                static const iostate eofbit             = 0x02;
 
 
92
                static const iostate failbit            = 0x04;
 
 
94
                typedef unsigned char openmode;
 
 
95
                static const openmode app               = 0x01;
 
 
96
                static const openmode ate               = 0x02;
 
 
97
                static const openmode binary            = 0x04;
 
 
98
                static const openmode in                = 0x08;
 
 
99
                static const openmode out               = 0x10;
 
 
100
                static const openmode trunc             = 0x20;
 
 
102
                typedef unsigned char seekdir;
 
 
103
                static const seekdir beg                = 0x01;
 
 
104
                static const seekdir cur                = 0x02;
 
 
105
                static const seekdir end                = 0x04;
 
 
107
                _UCXXEXPORT fmtflags flags() const{
 
 
110
                _UCXXEXPORT fmtflags flags(fmtflags fmtfl);
 
 
112
                fmtflags setf(fmtflags fmtfl);
 
 
113
                fmtflags setf(fmtflags fmtfl, fmtflags mask );
 
 
115
                _UCXXEXPORT void unsetf(fmtflags mask){
 
 
119
                _UCXXEXPORT streamsize precision() const{
 
 
123
                _UCXXEXPORT streamsize precision(streamsize prec);
 
 
125
                _UCXXEXPORT streamsize width() const{
 
 
129
                _UCXXEXPORT streamsize width(streamsize wide);
 
 
131
                _UCXXEXPORT locale imbue(const locale& loc);
 
 
133
                _UCXXEXPORT locale getloc() const{
 
 
137
//              FIXME - These need to be implemented
 
 
138
//              static int xalloc();
 
 
139
//              long&  iword(int index);
 
 
140
//              void*& pword(int index);
 
 
142
                _UCXXEXPORT ~ios_base() { }
 
 
144
                enum event { erase_event, imbue_event, copyfmt_event };
 
 
146
                typedef void (*event_callback)(event, ios_base&, int index);
 
 
147
//              void register_callback(event_call_back fn, int index);
 
 
149
                //We are going to wrap stdio so we don't need implementation of the following:
 
 
150
                inline static bool sync_with_stdio(bool = true) { return true; }
 
 
153
                _UCXXEXPORT ios_base() : mLocale(), mformat(dec | skipws ), mstate(goodbit), 
 
 
154
                        mmode(), mdir(), mprecision(6), mwidth(0)
 
 
155
#ifdef __UCLIBCXX_SUPPORT_CDIR__
 
 
166
                streamsize mprecision;
 
 
168
#ifdef __UCLIBCXX_SUPPORT_CDIR__
 
 
174
        //ios_base manipulators
 
 
177
        inline ios_base& boolalpha  (ios_base& str){
 
 
178
                str.setf(ios_base::boolalpha);
 
 
181
        inline ios_base& noboolalpha(ios_base& str){
 
 
182
                str.unsetf(ios_base::boolalpha);
 
 
185
        inline ios_base& showbase   (ios_base& str){
 
 
186
                str.setf(ios_base::showbase);
 
 
189
        inline ios_base& noshowbase (ios_base& str){
 
 
190
                str.unsetf(ios_base::showbase);
 
 
193
        inline ios_base& showpoint  (ios_base& str){
 
 
194
                str.setf(ios_base::showpoint);
 
 
197
        inline ios_base& noshowpoint(ios_base& str){
 
 
198
                str.unsetf(ios_base::showpoint);
 
 
201
        inline ios_base& showpos    (ios_base& str){
 
 
202
                str.setf(ios_base::showpos);
 
 
205
        inline ios_base& noshowpos  (ios_base& str){
 
 
206
                str.unsetf(ios_base::showpos);
 
 
209
        inline ios_base& skipws     (ios_base& str){
 
 
210
                str.setf(ios_base::skipws);
 
 
213
        inline ios_base& noskipws   (ios_base& str){
 
 
214
                str.unsetf(ios_base::skipws);
 
 
217
        inline ios_base& uppercase  (ios_base& str){
 
 
218
                str.setf(ios_base::uppercase);
 
 
221
        inline ios_base& nouppercase(ios_base& str){
 
 
222
                str.unsetf(ios_base::uppercase);
 
 
226
        inline ios_base& unitbuf    (ios_base& str){
 
 
227
                str.setf(ios_base::unitbuf);
 
 
230
        inline ios_base& nounitbuf  (ios_base& str){
 
 
231
                str.unsetf(ios_base::unitbuf);
 
 
234
        inline ios_base& internal   (ios_base& str){
 
 
235
                str.setf(ios_base::internal, ios_base::adjustfield);
 
 
238
        inline ios_base& left       (ios_base& str){
 
 
239
                str.setf(ios_base::left, ios_base::adjustfield);
 
 
242
        inline ios_base& right      (ios_base& str){
 
 
243
                str.setf(ios_base::right, ios_base::adjustfield);
 
 
247
        inline ios_base& dec        (ios_base& str){
 
 
248
                str.setf(ios_base::dec, ios_base::basefield);
 
 
251
        inline ios_base& hex        (ios_base& str){
 
 
252
                str.setf(ios_base::hex, ios_base::basefield);
 
 
255
        inline ios_base& oct        (ios_base& str){
 
 
256
                str.setf(ios_base::oct, ios_base::basefield);
 
 
260
        inline ios_base& fixed      (ios_base& str){
 
 
261
                str.setf(ios_base::fixed, ios_base::floatfield);
 
 
264
        inline ios_base& scientific (ios_base& str){
 
 
265
                str.setf(ios_base::scientific, ios_base::floatfield);
 
 
270
        //basic_ios class definition
 
 
273
        template <class charT, class traits > class _UCXXEXPORT basic_ios
 
 
278
                typedef charT char_type;
 
 
279
                typedef typename traits::int_type int_type;
 
 
280
                typedef typename traits::pos_type pos_type;
 
 
281
                typedef typename traits::off_type off_type;
 
 
282
                typedef traits traits_type;
 
 
284
                _UCXXEXPORT operator void*() const{
 
 
288
                        return (void *)(1);     //Must return a non-NULL pointer (though it can be *any* pointer)
 
 
291
                _UCXXEXPORT bool operator!() const{
 
 
294
                _UCXXEXPORT iostate rdstate() const{
 
 
297
                _UCXXEXPORT void clear(iostate state = goodbit){
 
 
301
                                mstate = state|ios_base::badbit;
 
 
304
                _UCXXEXPORT void setstate(iostate state) {
 
 
305
                        clear(rdstate()  | state);
 
 
306
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
 
 
307
                        if(rdstate() & throw_mask){
 
 
313
                _UCXXEXPORT bool good() const{
 
 
314
                        return (rdstate() == 0);
 
 
316
                _UCXXEXPORT bool eof()  const{
 
 
317
                        if(rdstate() & eofbit){
 
 
322
                _UCXXEXPORT bool fail() const{
 
 
323
                        if( mstate & (failbit | badbit) ){
 
 
329
                _UCXXEXPORT bool bad()  const{
 
 
336
                _UCXXEXPORT iostate exceptions() const{
 
 
339
                _UCXXEXPORT void exceptions(iostate except){
 
 
343
                explicit _UCXXEXPORT basic_ios(basic_streambuf<charT,traits>* sb) : fill_char(' '), mtied(0), mstreambuf(0){
 
 
347
                basic_ios() : mtied(0), mstreambuf(0){ }
 
 
349
                virtual _UCXXEXPORT ~basic_ios(){
 
 
352
                _UCXXEXPORT basic_ostream<charT,traits>* tie() const{
 
 
355
                _UCXXEXPORT basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr){
 
 
356
                        basic_ostream<charT,traits>* retval= mtied;
 
 
360
                _UCXXEXPORT basic_streambuf<charT,traits>* rdbuf() const{
 
 
363
                _UCXXEXPORT basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb){
 
 
364
                        basic_streambuf<charT,traits>* retval = mstreambuf;
 
 
368
                _UCXXEXPORT basic_ios& copyfmt(const basic_ios& rhs);
 
 
369
                _UCXXEXPORT char_type fill() const{
 
 
372
                _UCXXEXPORT char_type fill(char_type ch){
 
 
373
                        char_type temp = fill_char;
 
 
378
                _UCXXEXPORT locale imbue(const locale& loc){
 
 
379
                        return ios_base::imbue(loc);
 
 
381
                _UCXXEXPORT char narrow(char_type c, char dfault) const;
 
 
382
                _UCXXEXPORT char_type widen(char c) const;
 
 
386
                basic_ostream<charT,traits>* mtied;
 
 
387
                basic_streambuf<charT,traits>* mstreambuf;
 
 
389
                _UCXXEXPORT basic_ios(const basic_ios<charT,traits> &){ }
 
 
390
                _UCXXEXPORT basic_ios<charT,traits> & operator=(const basic_ios<charT,traits> &){ return *this; }
 
 
391
                _UCXXEXPORT void init(basic_streambuf<charT,traits>* sb){
 
 
392
                        ios_base::mformat = skipws|dec;
 
 
395
                        throw_mask = goodbit;
 
 
399
#ifdef __UCLIBCXX_EXPAND_IOS_CHAR__
 
 
400
#ifndef __UCLIBCXX_COMPILE_IOS__
 
 
402
        template <> _UCXXEXPORT void basic_ios<char, char_traits<char> >::clear(iostate state);
 
 
403
        template <> _UCXXEXPORT void basic_ios<char, char_traits<char> >::setstate(iostate state);
 
 
409
        template <class charT, class traits>
 
 
410
                inline char basic_ios<charT, traits>::narrow(char_type c, char dfault) const
 
 
416
                inline char basic_ios<char, char_traits<char> >::narrow(char_type c, char) const
 
 
421
#ifdef __UCLIBCXX_HAS_WCHAR__
 
 
424
                inline char basic_ios<wchar_t, char_traits<wchar_t> >::narrow(char_type c, char dfault) const
 
 
426
                char retval = wctob (c);
 
 
433
#endif  //__UCLIBCXX_HAS_WCHAR__
 
 
435
        template <class charT, class traits> 
 
 
436
                inline typename basic_ios<charT, traits>::char_type
 
 
437
                basic_ios<charT, traits>::widen(char c) const
 
 
443
                inline basic_ios<char, char_traits<char> >::char_type
 
 
444
                basic_ios<char, char_traits<char> >::widen(char c) const
 
 
449
#ifdef __UCLIBCXX_HAS_WCHAR__
 
 
452
                inline basic_ios<wchar_t, char_traits<wchar_t> >::char_type
 
 
453
                basic_ios<wchar_t, char_traits<wchar_t> >::widen(char c) const
 
 
458
#endif //__UCLIBCXX_HAS_WCHAR__
 
 
461
        template <class stateT> class _UCXXEXPORT fpos{
 
 
463
                _UCXXEXPORT fpos(stateT s){
 
 
466
                _UCXXEXPORT stateT state() const{
 
 
469
                _UCXXEXPORT void state(stateT s){
 
 
472
                _UCXXEXPORT bool operator==(const fpos &rhs){
 
 
475
                _UCXXEXPORT bool operator!=(const fpos &rhs){
 
 
478
                _UCXXEXPORT fpos & operator+(const streamoff & o){
 
 
482
                _UCXXEXPORT fpos & operator-(const streamoff & o){
 
 
486
                _UCXXEXPORT streamoff operator-(const fpos & rhs){
 
 
498
#pragma GCC visibility pop