enum
struct Test
{
int
number;
char
name[
4
];
}
public
void
OnPluginStart()
{
StringMap map =
new
StringMap();
map.SetValue(
"hp"
,
150
);
if
(!map.SetValue(
"hp"
,
200
,
false
)) {
PrintToServer(
"Ключ \"hp\" уже существует"
);
}
map.SetArray(
"rgb"
, {
255
,
100
,
200
},
3
);
Test t;
t.number =
12345
;
strcopy(t.name, sizeof(t.name),
"Cat"
);
map.SetArray(
"test"
, t, sizeof(t));
map.SetString(
"game"
,
"CS:S"
);
int
hp;
if
(map.GetValue(
"hp"
, hp)) {
PrintToServer(
"hp = %d"
, hp);
}
int
rgb[
3
];
if
(map.GetArray(
"rgb"
, rgb, sizeof(rgb))) {
PrintToServer(
"rgb = %d %d %d"
, rgb[
0
], rgb[
1
], rgb[
2
]);
}
t.number =
0
;
t.name[
0
] =
0
;
if
(map.GetArray(
"test"
, t, sizeof(t))) {
PrintToServer(
"Test::number = %d, Test::name = %s"
, t.number, t.name);
}
any a[
1
];
if
(map.GetArray(
"test"
, a, sizeof(a))) {
PrintToServer(
"Test::number = %d"
, a[
0
]);
}
int
bytes;
char
game[
16
];
if
(map.GetString(
"game"
, game, sizeof(game), bytes)) {
PrintToServer(
"game = %s, bytes = %d"
, game, bytes);
}
PrintToServer(
"Ключей в map: %d"
, map.Size);
if
(map.Remove(
"hp"
)) {
PrintToServer(
"Ключ \"hp\" удалён. Осталось ключей: %d"
, map.Size);
}
StringMapSnapshot snapshot = map.Snapshot();
if
(snapshot)
{
int
snapshotLength = snapshot.Length;
PrintToServer(
"snapshot.Length = %d"
, snapshotLength);
for
(
int
index =
0
, keyBufferSize; index < snapshotLength; index++)
{
keyBufferSize = snapshot.KeyBufferSize(index);
char
[] key =
new
char
[keyBufferSize];
bytes = snapshot.GetKey(index, key, keyBufferSize);
PrintToServer(
"Ключ: \"%s\", keyBufferSize: %d, bytes = %d."
,
key, keyBufferSize, bytes);
}
delete
snapshot;
}
delete
map;
}