forked from pig4210/xlib
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmsg.cpp
More file actions
Latest commit
144 lines (122 loc) · 2.59 KB
/
Copy pathxmsg.cpp
File metadata and controls
144 lines (122 loc) · 2.59 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include"xmsg.h"
#include<stdio.h>
#include<stdarg.h>
#include"ws_s.h"
usingnamespacestd;
#pragma warning(push)
#pragma warning(disable:4127) //warning C4127: 条件表达式是常量
xmsg& xmsg::prt(constchar* const fmt,...)
{
va_list ap;
va_start(ap,fmt);
while(true)
{
if(capacity() - size() <= 1)
{
reserve(capacity() + 0x10);
}
constsize_t rst = capacity() - size();
#ifdef FOR_RING0
char* lpend = end();
#else
char* lpend = const_cast<char*>(end()._Ptr);
#endif
#if defined(FOR_RING0) && !defined(_WIN64)
//目前WIN7以下Ring0只能使用不安全的函数,否则编译出现链接错误
constsize_t rt = _vsnprintf(lpend,rst,fmt,ap); //数据不足,返回-1
#else
constsize_t rt = _vsnprintf_s(lpend, rst, rst - 1, fmt, ap);
#endif
if(rt < rst)
{
append(lpend, rt);
break;
}
reserve(capacity() + 0x10);
}
va_end(ap);
return *this;
}
#pragma warning(pop)
xmsg& xmsg::operator<<(constchar& v)
{
returnprt("%c",v);
}
xmsg& xmsg::operator<<(constunsignedchar& v)
{
returnprt("%02X",v);
}
xmsg& xmsg::operator<<(constshort& v)
{
returnprt("%hd",v);
}
xmsg& xmsg::operator<<(constunsignedshort& v)
{
returnprt("%04X",v);
}
xmsg& xmsg::operator<<(constint& v)
{
returnprt("%d",v);
}
xmsg& xmsg::operator<<(constunsignedint& v)
{
returnprt("%08X",v);
}
xmsg& xmsg::operator<<(const __int64& v)
{
returnprt("%lld", v);
}
xmsg& xmsg::operator<<(constunsigned __int64& v)
{
returnprt("%08X%08X", (int)(v >> 32), (int)v);
}
xmsg& xmsg::operator<<(constchar* v)
{
returnprt("%s", v);
}
xmsg& xmsg::operator<<(constunsignedchar* v)
{
returnprt("%s", v);
}
xmsg& xmsg::operator<<(constbool& v)
{
constchar* const tmp = v ? ":true." : ":false.";
returnthis->operator <<(tmp);
}
xmsg& xmsg::operator<<(constwchar_t& v)
{
wchar_t tmpws[2] = { v, L'\0' };
returnprt("%s", ws2s(tmpws).c_str());
}
xmsg& xmsg::operator<<(constwchar_t* v)
{
returnprt("%s", ws2s(v).c_str());
}
xmsg& xmsg::operator<<(constfloat& v)
{
returnprt("%f", v);
}
xmsg& xmsg::operator<<(constdouble& v)
{
returnprt("%f", v);
}
xmsg& xmsg::operator<<(constvoid* v)
{
returnprt("%p",v);
}
xmsg& xmsg::operator<<(const string& v)
{
returnprt("%s", v.c_str());
}
xmsg& xmsg::operator<<(const wstring& v)
{
returnthis->operator<<(v.c_str());
}
xmsg& xmsg::operator<<(const xutf8& v)
{
returnthis->operator<<(utf82ws(v));
}
xmsg& xmsg::operator<<(xmsg& (*pfn)(xmsg&))
{
returnpfn(*this);
}