/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*	Copyright (C) 2004 Garrett A. Kajmowicz

	This file is part of the uClibc++ Library.

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#define __UCLIBCXX_COMPILE_IOS__ 1

#include <ios>
#include <ostream>
#include <istream>
#include <cstdio>
#ifdef ARDUINO
#include <HardwareSerial.h>
#include <serstream>
#else
#include <fstream>
#endif

namespace std{

#ifdef __UCLIBCXX_SUPPORT_CDIR__
	_UCXXLOCAL int ios_base::Init::init_cnt = 0;	//Needed to ensure the static value is created

//Create buffers first
#ifdef __UCLIBCXX_SUPPORT_COUT__
	_UCXXEXPORT filebuf _cout_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_CIN__
	_UCXXEXPORT filebuf _cin_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_CERR__
	_UCXXEXPORT filebuf _cerr_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_CLOG__
	_UCXXEXPORT filebuf _clog_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
	_UCXXEXPORT wfilebuf _wcout_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCIN__
	_UCXXEXPORT wfilebuf _wcin_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCERR__
	_UCXXEXPORT wfilebuf _wcerr_filebuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
	_UCXXEXPORT wfilebuf _wclog_filebuf;
#endif



//Then create streams
#ifdef __UCLIBCXX_SUPPORT_COUT__
	_UCXXEXPORT ostream cout(&_cout_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_CIN__
	_UCXXEXPORT istream cin(&_cin_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_CERR__
	_UCXXEXPORT ostream cerr(&_cerr_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_CLOG__
	_UCXXEXPORT ostream clog(&_clog_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
	_UCXXEXPORT wostream wcout(&_wcout_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_WCIN__
	_UCXXEXPORT wistream wcin(&_wcin_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_WCERR__
	_UCXXEXPORT wostream wcerr(&_wcerr_filebuf);
#endif
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
	_UCXXEXPORT wostream wclog(&_wclog_filebuf);
#endif


#ifdef __UCLIBCXX_SUPPORT_COUT__
	_UCXXEXPORT ohserialstream cout(Serial);
#endif
#ifdef __UCLIBCXX_SUPPORT_CIN__
	_UCXXEXPORT ihserialstream cin(Serial);
#endif
#ifdef __UCLIBCXX_SUPPORT_CERR__
	_UCXXEXPORT ohserialstream cerr(Serial);
#endif
#ifdef __UCLIBCXX_SUPPORT_CLOG__
	_UCXXEXPORT ohserialstream clog(Serial);
#endif

	_UCXXEXPORT ios_base::Init::Init(){
		if(init_cnt == 0){	//Need to construct cout et al

#ifndef ARDUINO

#ifdef __UCLIBCXX_SUPPORT_COUT__
			_cout_filebuf.fp = stdout;
			_cout_filebuf.openedFor = ios_base::out;
#endif
#ifdef __UCLIBCXX_SUPPORT_CERR__
			_cerr_filebuf.fp = stderr;
			_cerr_filebuf.openedFor = ios_base::out;
			cerr.mformat |= ios_base::unitbuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_CLOG__
			_clog_filebuf.fp = stderr;
			_clog_filebuf.openedFor = ios_base::out;
#endif
#ifdef __UCLIBCXX_SUPPORT_CIN__
			_cin_filebuf.fp = stdin;
			_cin_filebuf.openedFor = ios_base::in;

#ifdef __UCLIBCXX_SUPPORT_COUT__
			cin.tie(&cout);
#endif

#endif
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
			_wcout_filebuf.fp = stdout;
			_wcout_filebuf.openedFor = ios_base::out;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCERR__
			_wcerr_filebuf.fp = stderr;
			_wcerr_filebuf.openedFor = ios_base::out;
			wcerr.mformat |= ios_base::unitbuf;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
			_wclog_filebuf.fp = stderr;
			_wclog_filebuf.openedFor = ios_base::out;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCIN__
			_wcin_filebuf.fp = stdin;
			_wcin_filebuf.openedFor = ios_base::in;

#ifdef __UCLIBCXX_SUPPORT_WCOUT__
			wcin.tie(&wcout);
#endif

#endif // not Arduino

#endif // not CDIR 
		}
		init_cnt++;
	}

	_UCXXEXPORT ios_base::Init::~Init(){
		--init_cnt;
		if(init_cnt==0){

		}
	}
#endif


#ifdef __UCLIBCXX_EXPAND_IOS_CHAR__

	template _UCXXEXPORT void basic_ios<char, char_traits<char> >::clear(iostate state);
	template _UCXXEXPORT void basic_ios<char, char_traits<char> >::setstate(iostate state);

#endif


	_UCXXEXPORT ios_base::fmtflags ios_base::flags(fmtflags fmtfl){
		fmtflags temp = mformat;
		mformat = fmtfl;
		return temp;
	}

	_UCXXEXPORT ios_base::fmtflags ios_base::setf(fmtflags fmtfl){
		return flags(flags() | fmtfl);
	}

	_UCXXEXPORT ios_base::fmtflags ios_base::setf(fmtflags fmtfl, fmtflags mask ){
		return flags( (flags()& ~mask) | (fmtfl & mask));
	}

	_UCXXEXPORT streamsize ios_base::precision(streamsize prec){
		streamsize temp = mprecision;
		mprecision = prec;
		return temp;
	}
	_UCXXEXPORT streamsize ios_base::width(streamsize wide){
		streamsize temp = mwidth;
		mwidth = wide;
		return temp;
	}

	_UCXXEXPORT locale ios_base::imbue(const locale& loc){
		locale retval = mLocale;
		mLocale = loc;
		return retval;
	}	

}