aboutsummaryrefslogtreecommitdiff
path: root/src/formatter.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/formatter.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/formatter.h b/src/formatter.h
index aec5c5d..3f51e8e 100644
--- a/src/formatter.h
+++ b/src/formatter.h
@@ -103,6 +103,7 @@ namespace Bu
103 void writeAligned( const Bu::FString &sStr ); 103 void writeAligned( const Bu::FString &sStr );
104 void writeAligned( const char *sStr, int iLen ); 104 void writeAligned( const char *sStr, int iLen );
105 105
106 void read( void *sStr, int iLen );
106 Bu::FString readToken(); 107 Bu::FString readToken();
107 108
108 void incIndent(); 109 void incIndent();
@@ -199,6 +200,63 @@ namespace Bu
199 writeAligned( fTmp ); 200 writeAligned( fTmp );
200 usedFormat(); 201 usedFormat();
201 } 202 }
203
204 template<typename type>
205 void iparse( type &i, const Bu::FString &sBuf )
206 {
207 if( !sBuf )
208 return;
209 if( sBuf[0] != '+' && sBuf[0] != '-' &&
210 (sBuf[0] < '0' && sBuf[0] > '9') )
211 return;
212 int j = 1;
213 int iMax = sBuf.getSize();
214 for(; j < iMax && (sBuf[j] >= '0' && sBuf[j] <= '9'); j++ ) { }
215 i = 0;
216 type iPos = 1;
217 for(j--; j >= 0; j-- )
218 {
219 if( sBuf[j] == '+' || sBuf[j] == '-' )
220 continue;
221 i += (sBuf[j]-'0')*iPos;
222 iPos *= fLast.uRadix;
223 }
224 if( sBuf[0] == '-' )
225 i = -i;
226
227 usedFormat();
228 }
229
230 template<typename type>
231 void uparse( type &i, const Bu::FString &sBuf )
232 {
233 if( !sBuf )
234 return;
235 if( sBuf[0] != '+' &&
236 (sBuf[0] < '0' && sBuf[0] > '9') )
237 return;
238 int j = 1;
239 int iMax = sBuf.getSize();
240 for(; j < iMax && (sBuf[j] >= '0' && sBuf[j] <= '9'); j++ ) { }
241 i = 0;
242 type iPos = 1;
243 for(j--; j >= 0; j-- )
244 {
245 if( sBuf[j] == '+' )
246 continue;
247 i += (sBuf[j]-'0')*iPos;
248 iPos *= fLast.uRadix;
249 }
250
251 usedFormat();
252 }
253
254 template<typename type>
255 void fparse( type &f, const Bu::FString &sBuf )
256 {
257 sscanf( sBuf.getStr(), "%f", &f );
258 usedFormat();
259 }
202 260
203 enum Special 261 enum Special
204 { 262 {
@@ -243,6 +301,21 @@ namespace Bu
243 Formatter &operator<<( Formatter &f, bool b ); 301 Formatter &operator<<( Formatter &f, bool b );
244 302
245 Formatter &operator>>( Formatter &f, Bu::FString &sStr ); 303 Formatter &operator>>( Formatter &f, Bu::FString &sStr );
304 Formatter &operator>>( Formatter &f, signed char &c );
305 Formatter &operator>>( Formatter &f, char &c );
306 Formatter &operator>>( Formatter &f, unsigned char &c );
307 Formatter &operator>>( Formatter &f, signed short &i );
308 Formatter &operator>>( Formatter &f, unsigned short &i );
309 Formatter &operator>>( Formatter &f, signed int &i );
310 Formatter &operator>>( Formatter &f, unsigned int &i );
311 Formatter &operator>>( Formatter &f, signed long &i );
312 Formatter &operator>>( Formatter &f, unsigned long &i );
313 Formatter &operator>>( Formatter &f, signed long long &i );
314 Formatter &operator>>( Formatter &f, unsigned long long &i );
315 Formatter &operator>>( Formatter &f, float &flt );
316 Formatter &operator>>( Formatter &f, double &flt );
317 Formatter &operator>>( Formatter &f, long double &flt );
318 Formatter &operator>>( Formatter &f, bool &b );
246 319
247 template<typename type> 320 template<typename type>
248 Formatter &operator<<( Formatter &f, const type *p ) 321 Formatter &operator<<( Formatter &f, const type *p )