aboutsummaryrefslogtreecommitdiff
path: root/src/stable/fmt.h
blob: 15d8efcb2cb6aaf09688b2259138cf4e6bb0bd05 (plain)
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
#ifndef BU_FMT_H
#define BU_FMT_H

namespace Bu
{
	typedef struct Fmt
	{
		enum Alignment
		{
			Left	= 0,
			Center	= 1,
			Right	= 2
		};
		Fmt() :
			uMinWidth( 0 ),
			cFillChar(' '),
			uRadix( 10 ),
			uAlign( Right ),
			bPlus( false ),
			bCaps( true ),
			bTokenize( true )
		{
		}

		Fmt( unsigned int uMinWidth, unsigned int uRadix=10,
				Alignment a=Right, bool bPlus=false, bool bCaps=true,
				char cFill=' ') :
			uMinWidth( uMinWidth ),
			cFillChar(cFill),
			uRadix( uRadix ),
			uAlign( a ),
			bPlus( bPlus ),
			bCaps( bCaps ),
			bTokenize( true )
		{
		}
		Fmt( unsigned int uMinWidth, Alignment a,
				unsigned int uRadix=10, bool bPlus=false, bool bCaps=true,
				char cFill=' ') :
			uMinWidth( uMinWidth ),
			cFillChar(cFill),
			uRadix( uRadix ),
			uAlign( a ),
			bPlus( bPlus ),
			bCaps( bCaps ),
			bTokenize( true )
		{
		}

		static Fmt hex( unsigned int uWidth=0, bool bCaps=true )
		{
			return Fmt( uWidth, 16, Right, false, bCaps, '0' );
		}
		
		static Fmt oct( unsigned int uWidth=0 )
		{
			return Fmt( uWidth, 8, Right, false, false, '0' );
		}

		static Fmt bin( unsigned int uWidth=0 )
		{
			return Fmt( uWidth, 1, Right, false, false, '0' );
		}

		static Fmt ptr( bool bCaps=true )
		{
			return Fmt( sizeof(ptrdiff_t)*2, 16, Right, false, bCaps, '0' );
		}

		Fmt &width( unsigned int uWidth );
		Fmt &fill( char cFill='0' );
		Fmt &radix( unsigned int uRadix );
		Fmt &align( Alignment eAlign );
		Fmt &plus( bool bPlus=true );
		Fmt &caps( bool bCaps=true );
		Fmt &tokenize( bool bTokenize=true );

		Fmt &left();
		Fmt &right();
		Fmt &center();

		unsigned char uMinWidth;
		char cFillChar;
		unsigned short uRadix : 6;
		unsigned short uAlign : 2;
		unsigned short bPlus : 1;
		unsigned short bCaps : 1;
		unsigned short bTokenize : 1;
	} Fmt;
};

#endif