/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
57 by edam
added ulibc
1
/*	Copyright (C) 2004 Garrett A. Kajmowicz
2
3
	This file is part of the uClibc++ Library.
4
	This library is free software; you can redistribute it and/or
5
	modify it under the terms of the GNU Lesser General Public
6
	License as published by the Free Software Foundation; either
7
	version 2.1 of the License, or (at your option) any later version.
8
9
	This library is distributed in the hope that it will be useful,
10
	but WITHOUT ANY WARRANTY; without even the implied warranty of
11
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
	Lesser General Public License for more details.
13
14
	You should have received a copy of the GNU Lesser General Public
15
	License along with this library; if not, write to the Free Software
16
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
*/
18
19
#include <basic_definitions>
20
#include <string.h>
21
#include <exception>
22
#include <memory>
23
24
#ifdef __UCLIBCXX_HAS_WCHAR__
25
#include <cwchar>
26
#include <cwctype>
27
#endif
28
29
#ifndef __HEADER_CHAR_TRAITS
30
#define __HEADER_CHAR_TRAITS 1
31
32
namespace std{
33
	/* Inlining all wrapped function calls to shrink the amount of code generated*/	
34
	//Typedefs to use for stuff
35
	typedef signed int char_traits_off_type;
36
37
	//Generic char_traits
38
	template<class charT> struct _UCXXEXPORT char_traits { };
39
40
	//Specialize for char
41
	template<> struct _UCXXEXPORT char_traits<char> {
42
		typedef char char_type;
43
		typedef short int int_type;
44
		typedef char_traits_off_type off_type;
45
		typedef char_traits_off_type pos_type;
46
		typedef char state_type;
47
		
48
		inline static void assign(char_type & c, const char_type & d) { c = d; }
49
50
		static bool eq(const char_type& c1, const char_type& c2);
51
52
		static char_type to_char_type(const int_type & i);
53
54
		inline static int_type to_int_type(const char_type & c){
55
			return (short int)(unsigned char)c;
56
		}
57
58
		inline static bool eq_int_type(const int_type & a, const int_type & b){
59
			if(a==b){
60
				return true;
61
			}
62
			return false;
63
		}
64
65
66
		inline static bool lt(const char_type& c1, const char_type& c2){
67
			if(strncmp(&c1, &c2, 1) < 0){
68
				return true;
69
			}
70
			return false;
71
		}
72
73
		inline static char_type* move(char_type* s1, const char_type* s2, size_t n){
74
			return (char*) memmove(s1, s2, n);
75
		}
76
77
		inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){
78
			for(unsigned long int i=0; i< n; ++i){
79
				assign(s1[i], s2[i]);
80
			}
81
			return s1 + n;
82
		}
83
84
		inline static char_type* assign(char_type* s, size_t n, char_type a){
85
			return (char *)memset(s, a, n);
86
		}
87
88
		inline static int compare(const char_type* s1, const char_type* s2, size_t n){
89
			return strncmp(s1, s2, n);
90
		}
91
92
		inline static size_t length(const char_type* s){
93
			return strlen(s);
94
		}
95
96
		static const char_type* find(const char_type* s, int n, const char_type& a);
97
98
		inline static char_type eos() { return 0; }
99
		inline static int_type eof() { return -1; }
100
		inline static int_type not_eof(const int_type & i) {
101
			if(i == -1){
102
				return 0;
103
			} else {
104
				return i;
105
			}
106
		}
107
		static state_type get_state(pos_type p){
108
			p = p;
109
			state_type a;
110
			return a;
111
		}
112
	};
113
114
115
#ifdef __UCLIBCXX_HAS_WCHAR__
116
	template<> struct _UCXXEXPORT char_traits<wchar_t> {
117
		typedef wchar_t char_type;
118
		typedef wint_t int_type;
119
		typedef char_traits_off_type off_type;
120
		typedef char_traits_off_type pos_type;
121
		typedef mbstate_t state_type;
122
123
		static void assign(char_type & c, const char_type & d){ c=d; }
124
125
		static char_type to_char_type(const int_type & i){
126
			return i;
127
		}
128
129
		static int_type to_int_type(const char_type & c){
130
			return c;
131
		}
132
133
		inline static bool eq_int_type(const int_type & a, const int_type & b){
134
			if(a==b){
135
				return true;
136
			}
137
			return false;
138
		}
139
140
		inline static bool eq(const char_type& c1, const char_type& c2){
141
			if(wcsncmp(&c1, &c2, 1) == 0){
142
				return true;
143
			}
144
			return false;
145
		}
146
147
		inline static bool lt(const char_type& c1, const char_type& c2){
148
			if(wcsncmp(&c1, &c2, 1) < 0){
149
				return true;
150
			}
151
			return false;
152
		}
153
154
		inline static char_type* move(char_type* s1, const char_type* s2, size_t n){
155
			return (char_type*) memmove(s1, s2, n * sizeof(char_type));
156
		}
157
158
		inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){
159
			for(unsigned long int i=0; i< n; ++i){
160
				assign(s1[i], s2[i]);
161
			}
162
			return s1 + n;
163
		}
164
165
		inline static char_type* assign(char_type* s, size_t n, char_type a){
166
			return (char_type *)memset(s, a, n);	/*FIXME*/
167
		}
168
169
		inline static int compare(const char_type* s1, const char_type* s2, size_t n){
170
			return wcsncmp(s1, s2, n);
171
		}
172
173
		inline static size_t length(const char_type* s){
174
			return wcslen(s);
175
		}
176
177
		static const char_type* find(const char_type* s, int n, const char_type& a);
178
179
		inline static char_type eos() { return 0; }
180
		inline static int_type eof() { return WEOF; }
181
		inline static int_type not_eof(const int_type & i) {
182
			if(i == WEOF){
183
				return (int_type)0;
184
			} else {
185
				return i;
186
			}
187
		}
188
		static state_type get_state(pos_type){
189
			state_type a;
190
			return a;
191
		}
192
	};
193
#endif
194
195
}
196
197
#endif
198