/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock

« back to all changes in this revision

Viewing changes to src/utility/ios.cpp

  • Committer: edam
  • Date: 2012-02-25 01:31:43 UTC
  • Revision ID: tim@ed.am-20120225013143-9fet2y2d3fjlrwez
added ulibc

Show diffs side-by-side

added added

removed removed

 
1
/*      Copyright (C) 2004 Garrett A. Kajmowicz
 
2
 
 
3
        This file is part of the uClibc++ Library.
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
18
*/
 
19
 
 
20
#define __UCLIBCXX_COMPILE_IOS__ 1
 
21
 
 
22
#include <ios>
 
23
#include <ostream>
 
24
#include <istream>
 
25
#include <cstdio>
 
26
#ifdef ARDUINO
 
27
#include <HardwareSerial.h>
 
28
#include <serstream>
 
29
#else
 
30
#include <fstream>
 
31
#endif
 
32
 
 
33
namespace std{
 
34
 
 
35
#ifdef __UCLIBCXX_SUPPORT_CDIR__
 
36
        _UCXXLOCAL int ios_base::Init::init_cnt = 0;    //Needed to ensure the static value is created
 
37
 
 
38
//Create buffers first
 
39
#ifdef __UCLIBCXX_SUPPORT_COUT__
 
40
        _UCXXEXPORT filebuf _cout_filebuf;
 
41
#endif
 
42
#ifdef __UCLIBCXX_SUPPORT_CIN__
 
43
        _UCXXEXPORT filebuf _cin_filebuf;
 
44
#endif
 
45
#ifdef __UCLIBCXX_SUPPORT_CERR__
 
46
        _UCXXEXPORT filebuf _cerr_filebuf;
 
47
#endif
 
48
#ifdef __UCLIBCXX_SUPPORT_CLOG__
 
49
        _UCXXEXPORT filebuf _clog_filebuf;
 
50
#endif
 
51
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
 
52
        _UCXXEXPORT wfilebuf _wcout_filebuf;
 
53
#endif
 
54
#ifdef __UCLIBCXX_SUPPORT_WCIN__
 
55
        _UCXXEXPORT wfilebuf _wcin_filebuf;
 
56
#endif
 
57
#ifdef __UCLIBCXX_SUPPORT_WCERR__
 
58
        _UCXXEXPORT wfilebuf _wcerr_filebuf;
 
59
#endif
 
60
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
 
61
        _UCXXEXPORT wfilebuf _wclog_filebuf;
 
62
#endif
 
63
 
 
64
 
 
65
 
 
66
//Then create streams
 
67
#ifdef __UCLIBCXX_SUPPORT_COUT__
 
68
        _UCXXEXPORT ostream cout(&_cout_filebuf);
 
69
#endif
 
70
#ifdef __UCLIBCXX_SUPPORT_CIN__
 
71
        _UCXXEXPORT istream cin(&_cin_filebuf);
 
72
#endif
 
73
#ifdef __UCLIBCXX_SUPPORT_CERR__
 
74
        _UCXXEXPORT ostream cerr(&_cerr_filebuf);
 
75
#endif
 
76
#ifdef __UCLIBCXX_SUPPORT_CLOG__
 
77
        _UCXXEXPORT ostream clog(&_clog_filebuf);
 
78
#endif
 
79
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
 
80
        _UCXXEXPORT wostream wcout(&_wcout_filebuf);
 
81
#endif
 
82
#ifdef __UCLIBCXX_SUPPORT_WCIN__
 
83
        _UCXXEXPORT wistream wcin(&_wcin_filebuf);
 
84
#endif
 
85
#ifdef __UCLIBCXX_SUPPORT_WCERR__
 
86
        _UCXXEXPORT wostream wcerr(&_wcerr_filebuf);
 
87
#endif
 
88
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
 
89
        _UCXXEXPORT wostream wclog(&_wclog_filebuf);
 
90
#endif
 
91
 
 
92
 
 
93
#ifdef __UCLIBCXX_SUPPORT_COUT__
 
94
        _UCXXEXPORT ohserialstream cout(Serial);
 
95
#endif
 
96
#ifdef __UCLIBCXX_SUPPORT_CIN__
 
97
        _UCXXEXPORT ihserialstream cin(Serial);
 
98
#endif
 
99
#ifdef __UCLIBCXX_SUPPORT_CERR__
 
100
        _UCXXEXPORT ohserialstream cerr(Serial);
 
101
#endif
 
102
#ifdef __UCLIBCXX_SUPPORT_CLOG__
 
103
        _UCXXEXPORT ohserialstream clog(Serial);
 
104
#endif
 
105
 
 
106
        _UCXXEXPORT ios_base::Init::Init(){
 
107
                if(init_cnt == 0){      //Need to construct cout et al
 
108
 
 
109
#ifndef ARDUINO
 
110
 
 
111
#ifdef __UCLIBCXX_SUPPORT_COUT__
 
112
                        _cout_filebuf.fp = stdout;
 
113
                        _cout_filebuf.openedFor = ios_base::out;
 
114
#endif
 
115
#ifdef __UCLIBCXX_SUPPORT_CERR__
 
116
                        _cerr_filebuf.fp = stderr;
 
117
                        _cerr_filebuf.openedFor = ios_base::out;
 
118
                        cerr.mformat |= ios_base::unitbuf;
 
119
#endif
 
120
#ifdef __UCLIBCXX_SUPPORT_CLOG__
 
121
                        _clog_filebuf.fp = stderr;
 
122
                        _clog_filebuf.openedFor = ios_base::out;
 
123
#endif
 
124
#ifdef __UCLIBCXX_SUPPORT_CIN__
 
125
                        _cin_filebuf.fp = stdin;
 
126
                        _cin_filebuf.openedFor = ios_base::in;
 
127
 
 
128
#ifdef __UCLIBCXX_SUPPORT_COUT__
 
129
                        cin.tie(&cout);
 
130
#endif
 
131
 
 
132
#endif
 
133
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
 
134
                        _wcout_filebuf.fp = stdout;
 
135
                        _wcout_filebuf.openedFor = ios_base::out;
 
136
#endif
 
137
#ifdef __UCLIBCXX_SUPPORT_WCERR__
 
138
                        _wcerr_filebuf.fp = stderr;
 
139
                        _wcerr_filebuf.openedFor = ios_base::out;
 
140
                        wcerr.mformat |= ios_base::unitbuf;
 
141
#endif
 
142
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
 
143
                        _wclog_filebuf.fp = stderr;
 
144
                        _wclog_filebuf.openedFor = ios_base::out;
 
145
#endif
 
146
#ifdef __UCLIBCXX_SUPPORT_WCIN__
 
147
                        _wcin_filebuf.fp = stdin;
 
148
                        _wcin_filebuf.openedFor = ios_base::in;
 
149
 
 
150
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
 
151
                        wcin.tie(&wcout);
 
152
#endif
 
153
 
 
154
#endif // not Arduino
 
155
 
 
156
#endif // not CDIR 
 
157
                }
 
158
                init_cnt++;
 
159
        }
 
160
 
 
161
        _UCXXEXPORT ios_base::Init::~Init(){
 
162
                --init_cnt;
 
163
                if(init_cnt==0){
 
164
 
 
165
                }
 
166
        }
 
167
#endif
 
168
 
 
169
 
 
170
#ifdef __UCLIBCXX_EXPAND_IOS_CHAR__
 
171
 
 
172
        template _UCXXEXPORT void basic_ios<char, char_traits<char> >::clear(iostate state);
 
173
        template _UCXXEXPORT void basic_ios<char, char_traits<char> >::setstate(iostate state);
 
174
 
 
175
#endif
 
176
 
 
177
 
 
178
        _UCXXEXPORT ios_base::fmtflags ios_base::flags(fmtflags fmtfl){
 
179
                fmtflags temp = mformat;
 
180
                mformat = fmtfl;
 
181
                return temp;
 
182
        }
 
183
 
 
184
        _UCXXEXPORT ios_base::fmtflags ios_base::setf(fmtflags fmtfl){
 
185
                return flags(flags() | fmtfl);
 
186
        }
 
187
 
 
188
        _UCXXEXPORT ios_base::fmtflags ios_base::setf(fmtflags fmtfl, fmtflags mask ){
 
189
                return flags( (flags()& ~mask) | (fmtfl & mask));
 
190
        }
 
191
 
 
192
        _UCXXEXPORT streamsize ios_base::precision(streamsize prec){
 
193
                streamsize temp = mprecision;
 
194
                mprecision = prec;
 
195
                return temp;
 
196
        }
 
197
        _UCXXEXPORT streamsize ios_base::width(streamsize wide){
 
198
                streamsize temp = mwidth;
 
199
                mwidth = wide;
 
200
                return temp;
 
201
        }
 
202
 
 
203
        _UCXXEXPORT locale ios_base::imbue(const locale& loc){
 
204
                locale retval = mLocale;
 
205
                mLocale = loc;
 
206
                return retval;
 
207
        }       
 
208
 
 
209
}
 
210
 
 
211
 
 
212