-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathColumns.inl
More file actions
101 lines (92 loc) · 2.69 KB
/
Copy pathColumns.inl
File metadata and controls
101 lines (92 loc) · 2.69 KB
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
93
94
95
96
97
98
99
100
101
#include <cstdio>
#include <string>
#include <vector>
#ifdef _UNICODE
#define tstring wstring
#else
#define tstring string
#endif
#define ELLIPSES TEXT("\xe2\x80\xa6")
void ColPrintField(const DWORD Val, const DWORD Width) { _tprintf(TEXT("%*u "), Width, Val); }
void ColPrintField(const LONG Val, const DWORD Width) { _tprintf(TEXT("%*d "), Width, Val); }
void ColPrintField(const VOID* Val, const DWORD Width) { _tprintf(TEXT("0x%*p "), Width - 2, Val); }
void ColPrintField(const HANDLE Val, const DWORD Width){ _tprintf(TEXT("0x%0*X "), Width - 2, (UINT) (INT_PTR) Val); }
//void ColPrintField(LPCTSTR Val, const DWORD Width) { Width == 0 ? _tprintf(TEXT("%s "), Val) : _tprintf(TEXT("%-*.*s "), Width, Width, Val); }
void ColPrintField(LPCTSTR Val, const DWORD Width)
{
if (Width == 0)
_tprintf(TEXT("%s "), Val);
else if ((DWORD) lstrlen(Val) > Width)
_tprintf(TEXT("%-*.*s") ELLIPSES TEXT(" "), Width - 1, Width - 1, Val);
else
_tprintf(TEXT("%-*s "), Width, Val);
}
template <class T>
struct Column
{
typedef void (*PrintCol)(const T& v, const DWORD Width);
TCHAR id;
LPCTSTR Name;
LPCTSTR Desc;
DWORD Width;
PrintCol Print;
};
template <class T, size_t N>
const T* GetCol(TCHAR id, const T (&cols)[N])
{
for (const T& c : cols)
{
if (c.id == id)
return &c;
}
return nullptr;
}
template <class T, size_t N>
void ColPrintDescription(const T (&cols)[N])
{
for (const T& col : cols)
{
_tprintf(TEXT(" %c - %s\t%s\n"), col.id, col.Name, col.Desc);
}
}
template <class T, size_t N>
std::vector<const T*> ColParseFormat(const std::tstring& format, const T (&cols)[N])
{
std::vector<const T*> printcols;
for (const TCHAR c : format)
{
const T* col = GetCol(c, cols);
if (col)
printcols.push_back(col);
}
return printcols;
}
template <class T>
void ColPrintHeader(const std::vector<const Column<T>*>& printcols)
{
for (const Column<T>* col : printcols)
{
_tprintf(TEXT("%-*s "), col->Width, col->Name);
}
_tprintf(TEXT("\n"));
for (const Column<T>* col : printcols)
{
const LPCTSTR str = TEXT("====================================================================");
#if 0
fwrite(str, sizeof(TCHAR), col->Width, tstdout); // TODO support wstdout
_tprintf(TEXT(" "));
#else
_tprintf(TEXT("%*.*s "), col->Width, col->Width, str);
#endif
}
_tprintf(TEXT("\n"));
}
template <class T>
void ColPrintRow(const std::vector<const Column<T>*>& printcols, const T& val)
{
for (const Column<T>* col : printcols)
{
col->Print(val, col->Width);
}
_tprintf(TEXT("\n"));
}