diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-02-11 22:51:25 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-02-11 22:51:25 +0000 |
commit | 3f958097632256329cdbaf2219e2ba15325e9c52 (patch) | |
tree | e7616f7db3709d68ae51d6da0ef8ce44600bd33f /src/formatter.h | |
parent | f4b191f0ea396b58465bfba40749977780a3af58 (diff) | |
download | libbu++-3f958097632256329cdbaf2219e2ba15325e9c52.tar.gz libbu++-3f958097632256329cdbaf2219e2ba15325e9c52.tar.bz2 libbu++-3f958097632256329cdbaf2219e2ba15325e9c52.tar.xz libbu++-3f958097632256329cdbaf2219e2ba15325e9c52.zip |
Hey, formatter, awesome, and look at that...I'm adding uuid support.
Diffstat (limited to 'src/formatter.h')
-rw-r--r-- | src/formatter.h | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/src/formatter.h b/src/formatter.h index 168f48f..4bab505 100644 --- a/src/formatter.h +++ b/src/formatter.h | |||
@@ -21,28 +21,65 @@ namespace Bu | |||
21 | }; | 21 | }; |
22 | Fmt() : | 22 | Fmt() : |
23 | uMinWidth( 0 ), | 23 | uMinWidth( 0 ), |
24 | cFillChar(' '), | ||
24 | uRadix( 10 ), | 25 | uRadix( 10 ), |
25 | uAlign( Right ), | 26 | uAlign( Right ), |
26 | bPlus( false ), | 27 | bPlus( false ), |
27 | bCaps( false ) | 28 | bCaps( true ) |
28 | { | 29 | { |
29 | } | 30 | } |
30 | 31 | ||
31 | Fmt( unsigned int uMinWidth, unsigned int uRadix=10, | 32 | Fmt( unsigned int uMinWidth, unsigned int uRadix=10, |
32 | Alignment a=Right, bool bPlus=false ) : | 33 | Alignment a=Right, bool bPlus=false, bool bCaps=true, |
34 | char cFill=' ') : | ||
33 | uMinWidth( uMinWidth ), | 35 | uMinWidth( uMinWidth ), |
36 | cFillChar(cFill), | ||
34 | uRadix( uRadix ), | 37 | uRadix( uRadix ), |
35 | uAlign( a ), | 38 | uAlign( a ), |
36 | bPlus( bPlus ), | 39 | bPlus( bPlus ), |
37 | bCaps( false ) | 40 | bCaps( bCaps ) |
38 | { | 41 | { |
39 | } | 42 | } |
43 | Fmt( unsigned int uMinWidth, Alignment a=Right, | ||
44 | unsigned int uRadix=10, bool bPlus=false, bool bCaps=true, | ||
45 | char cFill=' ') : | ||
46 | uMinWidth( uMinWidth ), | ||
47 | cFillChar(cFill), | ||
48 | uRadix( uRadix ), | ||
49 | uAlign( a ), | ||
50 | bPlus( bPlus ), | ||
51 | bCaps( bCaps ) | ||
52 | { | ||
53 | } | ||
54 | |||
55 | static Fmt hex( unsigned int uWidth=0, bool bCaps=true ) | ||
56 | { | ||
57 | return Fmt( uWidth, 16, Right, false, bCaps, '0' ); | ||
58 | } | ||
59 | |||
60 | static Fmt oct( unsigned int uWidth=0, bool bCaps=true ) | ||
61 | { | ||
62 | return Fmt( uWidth, 8, Right, false, bCaps, '0' ); | ||
63 | } | ||
40 | 64 | ||
41 | unsigned int uMinWidth : 8; | 65 | static Fmt ptr( bool bCaps=true ) |
42 | unsigned int uRadix : 6; | 66 | { |
43 | unsigned int uAlign : 2; | 67 | return Fmt( sizeof(ptrdiff_t)*2, 16, Right, false, bCaps, '0' ); |
44 | unsigned int bPlus : 1; | 68 | } |
45 | unsigned int bCaps : 1; | 69 | |
70 | Fmt &width( unsigned int uWidth ); | ||
71 | Fmt &fill( char cFill='0' ); | ||
72 | Fmt &radix( unsigned int uRadix ); | ||
73 | Fmt &align( Alignment eAlign ); | ||
74 | Fmt &plus( bool bPlus=true ); | ||
75 | Fmt &caps( bool bCaps=true ); | ||
76 | |||
77 | unsigned char uMinWidth; | ||
78 | char cFillChar; | ||
79 | unsigned short uRadix : 6; | ||
80 | unsigned short uAlign : 2; | ||
81 | unsigned short bPlus : 1; | ||
82 | unsigned short bCaps : 1; | ||
46 | } Fmt; | 83 | } Fmt; |
47 | 84 | ||
48 | void write( const Bu::FString &sStr ); | 85 | void write( const Bu::FString &sStr ); |
@@ -125,6 +162,13 @@ namespace Bu | |||
125 | usedFormat(); | 162 | usedFormat(); |
126 | } | 163 | } |
127 | 164 | ||
165 | template<typename type> | ||
166 | void ffmt( type /*f*/ ) | ||
167 | { | ||
168 | writeAligned("**make floats work**"); | ||
169 | usedFormat(); | ||
170 | } | ||
171 | |||
128 | enum Special | 172 | enum Special |
129 | { | 173 | { |
130 | nl | 174 | nl |
@@ -153,6 +197,17 @@ namespace Bu | |||
153 | Formatter &operator<<( Formatter &rOut, unsigned long i ); | 197 | Formatter &operator<<( Formatter &rOut, unsigned long i ); |
154 | Formatter &operator<<( Formatter &rOut, signed long long i ); | 198 | Formatter &operator<<( Formatter &rOut, signed long long i ); |
155 | Formatter &operator<<( Formatter &rOut, unsigned long long i ); | 199 | Formatter &operator<<( Formatter &rOut, unsigned long long i ); |
200 | Formatter &operator<<( Formatter &rOut, float f ); | ||
201 | Formatter &operator<<( Formatter &rOut, double f ); | ||
202 | Formatter &operator<<( Formatter &rOut, long double f ); | ||
203 | Formatter &operator<<( Formatter &rOut, bool b ); | ||
204 | |||
205 | template<typename type> | ||
206 | Formatter &operator<<( Formatter &rOut, type *p ) | ||
207 | { | ||
208 | rOut << (ptrdiff_t)(p); | ||
209 | return rOut; | ||
210 | } | ||
156 | }; | 211 | }; |
157 | 212 | ||
158 | #endif | 213 | #endif |