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
|
#include "../nbt.internal.h"
#include "nbt.h"
#define NBT__RETURN1(_r) return _r
#define NBT__RETURN0() return
#define NBT__CHECK(_tag, _ret) NBT__CHECK_TYPE(_tag, NBT_TAG_COMPOUND, NBT__RETURN1, _ret)
#define NBT__CHECK0(_tag) NBT__CHECK_TYPE(_tag, NBT_TAG_COMPOUND, NBT__RETURN0)
nbt_size_t nbt_compound_length(nbt_tag_t *compound)
{
NBT__CHECK(compound, (nbt_size_t)-1);
return nbt__ht_length(compound->value.nbt_compound.hash);
}
nbt_tag_t *nbt_compound_find(nbt_tag_t *compound, const char *key)
{
NBT__CHECK(compound, NULL);
bool found = false;
nbt_tag_t *tag = nbt__ht_get(compound->value.nbt_compound.hash, key, &found);
if (!found) return NULL;
return tag;
}
nbt_tag_t *nbt_compound_findn(nbt_tag_t *compound, const char *key, nbt_size_t keylen)
{
NBT__CHECK(compound, NULL);
bool found = false;
nbt_tag_t *tag = nbt__ht_getn(compound->value.nbt_compound.hash, key, keylen, &found);
if (!found) return NULL;
return tag;
}
/* returns NBT_TAG_END if there is no value present */
nbt_type_t nbt_compound_type(nbt_tag_t *compound, const char *key)
{
nbt_tag_t *tag = nbt_compound_find(compound, key);
if (!tag) return NBT_TAG_END;
return nbt_tag_type(tag);
}
nbt_type_t nbt_compound_typen(nbt_tag_t *compound, const char *key, nbt_size_t keylen)
{
nbt_tag_t *tag = nbt_compound_findn(compound, key, keylen);
if (!tag) return NBT_TAG_END;
return nbt_tag_type(tag);
}
int nbt_compound_put(nbt_tag_t *compound, const char *key, nbt_tag_t *value)
{
NBT__CHECK(compound, -1);
if (!value) return -1;
if (nbt__ht_put(compound->value.nbt_compound.hash, key, value) < 0) return -1;
nbt_incref(value);
return 0;
}
int nbt_compound_putn(nbt_tag_t *compound, const char *key, nbt_size_t sz, nbt_tag_t *value)
{
NBT__CHECK(compound, -1);
if (!value) return -1;
if (nbt__ht_putn(compound->value.nbt_compound.hash, key, sz, value) < 0)
return -1;
nbt_incref(value);
return 0;
}
int nbt_compound_remove(nbt_tag_t *compound, const char *key)
{
NBT__CHECK(compound, -1);
return nbt__ht_remove(compound->value.nbt_compound.hash, key);
}
int nbt_compound_removen(nbt_tag_t *compound, const char *key, nbt_size_t sz)
{
NBT__CHECK(compound, -1);
return nbt__ht_removen(compound->value.nbt_compound.hash, key, sz);
}
nbt_tag_t *nbt_compound_pop(nbt_tag_t *compound, const char *key)
{
NBT__CHECK(compound, NULL);
return nbt__ht_pop(compound->value.nbt_compound.hash, key, NULL); /* TODO: use found pointer*/
}
nbt_tag_t *nbt_compound_popn(nbt_tag_t *compound, const char *key, nbt_size_t sz)
{
NBT__CHECK(compound, NULL);
return nbt__ht_popn(compound->value.nbt_compound.hash, key, sz, NULL);
}
void nbt_compound_clear(nbt_tag_t *compound)
{
NBT__CHECK0(compound);
nbt__ht_clear(compound->value.nbt_compound.hash);
}
int nbt_compound_merge(nbt_tag_t *target, nbt_tag_t *srccomp)
{
/* TODO */
return -1;
}
|