forked from Wend4r/mms2-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcat.cpp
More file actions
159 lines (112 loc) · 4.88 KB
/
Copy pathconcat.cpp
File metadata and controls
159 lines (112 loc) · 4.88 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* vim: set ts=4 sw=4 tw=99 noet :
* ======================================================
* Metamod:Source {project}
* Written by {name of author} ({fullname}).
* ======================================================
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <concat.hpp>
ConcatLineString::ConcatLineString(const Base &aInit)
: Base(aInit)
{
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey) const
{
const auto vecConcat = Base::GetKeyValueConcat(pszKey);
return sMessage.AppendConcat(vecConcat.size(), vecConcat.data(), NULL);
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, bool bValue) const
{
return AppendToBuffer(sMessage, pszKey, bValue ? "true" : "false");
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, int iValue) const
{
char sValue[12];
V_snprintf(sValue, sizeof(sValue), "%i", iValue);
return AppendToBuffer(sMessage, pszKey, sValue);
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, float flValue) const
{
char sValue[21];
V_snprintf(sValue, sizeof(sValue), "%f", flValue);
return AppendToBuffer(sMessage, pszKey, sValue);
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, double dblValue) const
{
char sValue[32];
V_snprintf(sValue, sizeof(sValue), "%lf", dblValue);
return AppendToBuffer(sMessage, pszKey, sValue);
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, const char *pszValue) const
{
const auto vecConcat = Base::GetKeyValueConcat(pszKey, pszValue);
return sMessage.AppendConcat(vecConcat.size(), vecConcat.data(), NULL);
}
const char *ConcatLineString::AppendToBuffer(CBufferString &sMessage, const char *pszKey, std::vector<const char *> vecValues) const
{
const auto vecConcat = Base::GetKeyValueConcat(pszKey, vecValues);
return sMessage.AppendConcat(vecConcat.size(), vecConcat.data(), NULL);
}
const char *ConcatLineString::AppendBytesToBuffer(CBufferString &sMessage, const char *pszKey, const byte *pData, size_t nLength) const
{
std::vector<const char *> vecValues;
vecValues.reserve(nLength);
constexpr size_t nDepthSize = 4;
char *psDataSet = new char[nLength * nDepthSize];
for(int n = 0; n < nLength; n++)
{
auto *psByte = &psDataSet[n * nDepthSize];
V_snprintf(psByte, nDepthSize, "%02X ", pData[n]);
vecValues.push_back(psByte);
}
auto *pResult = AppendToBuffer(sMessage, pszKey, vecValues);
delete[] psDataSet;
return pResult;
}
const char *ConcatLineString::AppendHandleToBuffer(CBufferString &sMessage, const char *pszKey, uint32 uHandle) const
{
char sHandle[21];
V_snprintf(sHandle, sizeof(sHandle), "%u", uHandle);
return AppendToBuffer(sMessage, pszKey, sHandle);
}
const char *ConcatLineString::AppendHandleToBuffer(CBufferString &sMessage, const char *pszKey, uint64 uHandle) const
{
char sHandle[21];
V_snprintf(sHandle, sizeof(sHandle), "%llu", uHandle);
return AppendToBuffer(sMessage, pszKey, sHandle);
}
const char *ConcatLineString::AppendHandleToBuffer(CBufferString &sMessage, const char *pszKey, const void *pHandle) const
{
return AppendHandleToBuffer(sMessage, pszKey, (uint64)pHandle);
}
const char *ConcatLineString::AppendPointerToBuffer(CBufferString &sMessage, const char *pszKey, const void *pValue) const
{
char sPointer[22];
V_snprintf(sPointer, sizeof(sPointer), "%p", pValue);
return AppendToBuffer(sMessage, pszKey, sPointer);
}
const char *ConcatLineString::AppendStringToBuffer(CBufferString &sMessage, const char *pszKey, const char *pszValue) const
{
const auto vecConcat = Base::GetKeyValueConcatString(pszKey, pszValue);
return sMessage.AppendConcat(vecConcat.size(), vecConcat.data(), NULL);
}
int ConcatLineString::AppendToVector(CUtlVector<const char *> vecMessage, const char *pszKey, const char *pszValue) const
{
const auto vecConcat = Base::GetKeyValueConcat(pszKey, pszValue);
return vecMessage.AddMultipleToTail(vecConcat.size(), vecConcat.data());
}
int ConcatLineString::AppendStringToVector(CUtlVector<const char *> vecMessage, const char *pszKey, const char *pszValue) const
{
const auto vecConcat = Base::GetKeyValueConcatString(pszKey, pszValue);
return vecMessage.AddMultipleToTail(vecConcat.size(), vecConcat.data());
}