aboutsummaryrefslogtreecommitdiff
path: root/src/stable/fmt.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/fmt.h
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/fmt.h')
-rw-r--r--src/stable/fmt.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/stable/fmt.h b/src/stable/fmt.h
new file mode 100644
index 0000000..15d8efc
--- /dev/null
+++ b/src/stable/fmt.h
@@ -0,0 +1,92 @@
1#ifndef BU_FMT_H
2#define BU_FMT_H
3
4namespace Bu
5{
6 typedef struct Fmt
7 {
8 enum Alignment
9 {
10 Left = 0,
11 Center = 1,
12 Right = 2
13 };
14 Fmt() :
15 uMinWidth( 0 ),
16 cFillChar(' '),
17 uRadix( 10 ),
18 uAlign( Right ),
19 bPlus( false ),
20 bCaps( true ),
21 bTokenize( true )
22 {
23 }
24
25 Fmt( unsigned int uMinWidth, unsigned int uRadix=10,
26 Alignment a=Right, bool bPlus=false, bool bCaps=true,
27 char cFill=' ') :
28 uMinWidth( uMinWidth ),
29 cFillChar(cFill),
30 uRadix( uRadix ),
31 uAlign( a ),
32 bPlus( bPlus ),
33 bCaps( bCaps ),
34 bTokenize( true )
35 {
36 }
37 Fmt( unsigned int uMinWidth, Alignment a,
38 unsigned int uRadix=10, bool bPlus=false, bool bCaps=true,
39 char cFill=' ') :
40 uMinWidth( uMinWidth ),
41 cFillChar(cFill),
42 uRadix( uRadix ),
43 uAlign( a ),
44 bPlus( bPlus ),
45 bCaps( bCaps ),
46 bTokenize( true )
47 {
48 }
49
50 static Fmt hex( unsigned int uWidth=0, bool bCaps=true )
51 {
52 return Fmt( uWidth, 16, Right, false, bCaps, '0' );
53 }
54
55 static Fmt oct( unsigned int uWidth=0 )
56 {
57 return Fmt( uWidth, 8, Right, false, false, '0' );
58 }
59
60 static Fmt bin( unsigned int uWidth=0 )
61 {
62 return Fmt( uWidth, 1, Right, false, false, '0' );
63 }
64
65 static Fmt ptr( bool bCaps=true )
66 {
67 return Fmt( sizeof(ptrdiff_t)*2, 16, Right, false, bCaps, '0' );
68 }
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 Fmt &tokenize( bool bTokenize=true );
77
78 Fmt &left();
79 Fmt &right();
80 Fmt &center();
81
82 unsigned char uMinWidth;
83 char cFillChar;
84 unsigned short uRadix : 6;
85 unsigned short uAlign : 2;
86 unsigned short bPlus : 1;
87 unsigned short bCaps : 1;
88 unsigned short bTokenize : 1;
89 } Fmt;
90};
91
92#endif