Skip to content

Commit f101b10

Browse files
Switch to smart holder (#141)
1 parent ff5c058 commit f101b10

File tree

10 files changed

+20
-23
lines changed

10 files changed

+20
-23
lines changed

src/amulet/nbt/nbt_encoding/binary/bnbt.py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace NBT {
2929

3030
void init_bnbt(py::module& m)
3131
{
32-
py::class_<Amulet::NBT::ReadOffset> ReadOffset(m, "ReadOffset");
32+
py::classh<Amulet::NBT::ReadOffset> ReadOffset(m, "ReadOffset");
3333
ReadOffset.def(
3434
py::init<const size_t>(),
3535
py::arg("offset") = 0);

src/amulet/nbt/string_encoding/encoding.py.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace py = pybind11;
1212

1313
void init_encoding(py::module& m)
1414
{
15-
py::class_<Amulet::NBT::StringEncoding> StringEncoding(m, "StringEncoding");
15+
py::classh<Amulet::NBT::StringEncoding> StringEncoding(m, "StringEncoding");
1616
StringEncoding.def(
1717
"encode",
1818
[](const Amulet::NBT::StringEncoding& self, py::bytes data) -> py::bytes {
@@ -32,7 +32,7 @@ void init_encoding(py::module& m)
3232
m.attr("utf8_escape_encoding") = utf8_escape_encoding;
3333
m.attr("mutf8_encoding") = mutf8_encoding;
3434

35-
py::class_<Amulet::NBT::EncodingPreset> EncodingPreset(m, "EncodingPreset");
35+
py::classh<Amulet::NBT::EncodingPreset> EncodingPreset(m, "EncodingPreset");
3636
EncodingPreset.def_readonly(
3737
"compressed",
3838
&Amulet::NBT::EncodingPreset::compressed);

src/amulet/nbt/tag/abc.py.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void init_abc(py::module& m)
2525
py::object mutf8_encoding = m.attr("mutf8_encoding");
2626
py::object java_encoding = m.attr("java_encoding");
2727

28-
py::class_<Amulet::NBT::AbstractBaseTag> AbstractBaseTag(m, "AbstractBaseTag",
28+
py::classh<Amulet::NBT::AbstractBaseTag> AbstractBaseTag(m, "AbstractBaseTag",
2929
"Abstract Base Class for all tag classes");
3030
AbstractBaseTag.def_property_readonly_static(
3131
"tag_id",
@@ -131,14 +131,14 @@ void init_abc(py::module& m)
131131
abstract_method<const Amulet::NBT::AbstractBaseTag&>,
132132
"A string representation of the object.");
133133

134-
py::class_<Amulet::NBT::AbstractBaseImmutableTag, Amulet::NBT::AbstractBaseTag> AbstractBaseImmutableTag(m, "AbstractBaseImmutableTag",
134+
py::classh<Amulet::NBT::AbstractBaseImmutableTag, Amulet::NBT::AbstractBaseTag> AbstractBaseImmutableTag(m, "AbstractBaseImmutableTag",
135135
"Abstract Base Class for all tag classes");
136136
AbstractBaseImmutableTag.def(
137137
"__hash__",
138138
abstract_method<const Amulet::NBT::AbstractBaseImmutableTag&>,
139139
"A hash of the data in the class.");
140140

141-
py::class_<Amulet::NBT::AbstractBaseNumericTag, Amulet::NBT::AbstractBaseImmutableTag> AbstractBaseNumericTag(m, "AbstractBaseNumericTag",
141+
py::classh<Amulet::NBT::AbstractBaseNumericTag, Amulet::NBT::AbstractBaseImmutableTag> AbstractBaseNumericTag(m, "AbstractBaseNumericTag",
142142
"Abstract Base Class for all numeric tag classes");
143143
AbstractBaseNumericTag.def(
144144
"__int__",
@@ -153,7 +153,7 @@ void init_abc(py::module& m)
153153
abstract_method<const Amulet::NBT::AbstractBaseNumericTag&>,
154154
"Get a python bool representation of the class.");
155155

156-
py::class_<Amulet::NBT::AbstractBaseIntTag, Amulet::NBT::AbstractBaseNumericTag> AbstractBaseIntTag(m, "AbstractBaseIntTag",
156+
py::classh<Amulet::NBT::AbstractBaseIntTag, Amulet::NBT::AbstractBaseNumericTag> AbstractBaseIntTag(m, "AbstractBaseIntTag",
157157
"Abstract Base Class for all int tag classes");
158158
AbstractBaseIntTag.def_property_readonly(
159159
"py_int",
@@ -162,7 +162,7 @@ void init_abc(py::module& m)
162162
"\n"
163163
"The returned data is immutable so changes will not mirror the instance.");
164164

165-
py::class_<Amulet::NBT::AbstractBaseFloatTag, Amulet::NBT::AbstractBaseNumericTag> AbstractBaseFloatTag(m, "AbstractBaseFloatTag",
165+
py::classh<Amulet::NBT::AbstractBaseFloatTag, Amulet::NBT::AbstractBaseNumericTag> AbstractBaseFloatTag(m, "AbstractBaseFloatTag",
166166
"Abstract Base Class for all float tag classes.");
167167
AbstractBaseFloatTag.def_property_readonly(
168168
"py_float",
@@ -171,10 +171,10 @@ void init_abc(py::module& m)
171171
"\n"
172172
"The returned data is immutable so changes will not mirror the instance.");
173173

174-
py::class_<Amulet::NBT::AbstractBaseMutableTag, Amulet::NBT::AbstractBaseTag> AbstractBaseMutableTag(m, "AbstractBaseMutableTag",
174+
py::classh<Amulet::NBT::AbstractBaseMutableTag, Amulet::NBT::AbstractBaseTag> AbstractBaseMutableTag(m, "AbstractBaseMutableTag",
175175
"Abstract Base Class for all mutable tags.");
176176
AbstractBaseMutableTag.attr("__hash__") = py::none();
177177

178-
py::class_<Amulet::NBT::AbstractBaseArrayTag, Amulet::NBT::AbstractBaseMutableTag> AbstractBaseArrayTag(m, "AbstractBaseArrayTag",
178+
py::classh<Amulet::NBT::AbstractBaseArrayTag, Amulet::NBT::AbstractBaseMutableTag> AbstractBaseArrayTag(m, "AbstractBaseArrayTag",
179179
"Abstract Base Class for all array tag classes.");
180180
}

src/amulet/nbt/tag/array.py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
namespace py = pybind11;
2626

2727
#define PyArray(CLSNAME, ELEMENTCLS, BITCOUNT, TAGID) \
28-
py::class_<Amulet::NBT::CLSNAME, std::shared_ptr<Amulet::NBT::CLSNAME>> CLSNAME(m, #CLSNAME, AbstractBaseArrayTag, py::buffer_protocol(), \
28+
py::classh<Amulet::NBT::CLSNAME> CLSNAME(m, #CLSNAME, AbstractBaseArrayTag, py::buffer_protocol(), \
2929
"This class stores a fixed size signed " #BITCOUNT " bit vector."); \
3030
CLSNAME.def_property_readonly_static("tag_id", [](py::object) { return TAGID; }); \
3131
CLSNAME.def( \

src/amulet/nbt/tag/compound.py.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ T new_tag()
9191

9292
void init_compound(py::module& m)
9393
{
94-
py::class_<Amulet::NBT::CompoundTagIterator> CompoundTagIterator(m, "CompoundTagIterator");
94+
py::classh<Amulet::NBT::CompoundTagIterator> CompoundTagIterator(m, "CompoundTagIterator");
9595
CompoundTagIterator.def(
9696
"__next__",
9797
[](Amulet::NBT::CompoundTagIterator& self) -> py::object {
@@ -117,8 +117,7 @@ void init_compound(py::module& m)
117117
py::object mutf8_encoding = m.attr("mutf8_encoding");
118118
py::object java_encoding = m.attr("java_encoding");
119119

120-
// py::class_<Amulet::NBT::CompoundTag, Amulet::NBT::AbstractBaseMutableTag, std::shared_ptr<Amulet::NBT::CompoundTag>> CompoundTag(m, "CompoundTag",
121-
py::class_<Amulet::NBT::CompoundTag, std::shared_ptr<Amulet::NBT::CompoundTag>> CompoundTag(m, "CompoundTag", AbstractBaseMutableTag,
120+
py::classh<Amulet::NBT::CompoundTag> CompoundTag(m, "CompoundTag", AbstractBaseMutableTag,
122121
"A Python wrapper around a C++ unordered map.\n"
123122
"\n"
124123
"Note that this class is not thread safe and inherits all the limitations of a C++ unordered_map.");

src/amulet/nbt/tag/float.py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace py = pybind11;
1919

2020
#define PyFloat(NATIVE, CLSNAME, PRECISION, TAGID) \
21-
py::class_<Amulet::NBT::CLSNAME, Amulet::NBT::AbstractBaseFloatTag> CLSNAME(m, #CLSNAME, \
21+
py::classh<Amulet::NBT::CLSNAME, Amulet::NBT::AbstractBaseFloatTag> CLSNAME(m, #CLSNAME, \
2222
"A " #PRECISION " precision float class."); \
2323
CLSNAME.def_property_readonly_static("tag_id", [](py::object) { return TAGID; }); \
2424
CLSNAME.def( \

src/amulet/nbt/tag/int.py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace py = pybind11;
1919

2020
#define PyInt(NATIVE, CLSNAME, BYTEWIDTH, BITPOW, SIGNBIT, MAGBITS, TAGID) \
21-
py::class_<Amulet::NBT::CLSNAME, Amulet::NBT::AbstractBaseIntTag> CLSNAME(m, #CLSNAME, \
21+
py::classh<Amulet::NBT::CLSNAME, Amulet::NBT::AbstractBaseIntTag> CLSNAME(m, #CLSNAME, \
2222
"A " #BYTEWIDTH " byte integer class.\n" \
2323
"\n" \
2424
"Can Store numbers between -(2^" #BITPOW ") and (2^" #BITPOW " - 1)"); \

src/amulet/nbt/tag/list.py.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void ListTag_del_slice(std::vector<tagT>& self, const py::slice& slice)
151151

152152
void init_list(py::module& m)
153153
{
154-
py::class_<Amulet::NBT::ListTagIterator, std::shared_ptr<Amulet::NBT::ListTagIterator>> ListTagIterator(m, "ListTagIterator");
154+
py::classh<Amulet::NBT::ListTagIterator> ListTagIterator(m, "ListTagIterator");
155155
ListTagIterator.def(
156156
"__next__",
157157
[](Amulet::NBT::ListTagIterator& self) {
@@ -170,9 +170,7 @@ void init_list(py::module& m)
170170
py::object java_encoding = m.attr("java_encoding");
171171
py::object AbstractBaseMutableTag = m.attr("AbstractBaseMutableTag");
172172

173-
// py::class_<Amulet::NBT::ListTag, Amulet::NBT::AbstractBaseMutableTag, std::shared_ptr<Amulet::NBT::ListTag>> ListTag(m, "ListTag",
174-
py::class_<Amulet::NBT::ListTag, std::shared_ptr<Amulet::NBT::ListTag>> ListTag(m, "ListTag", AbstractBaseMutableTag,
175-
// py::class_<Amulet::NBT::ListTag, std::shared_ptr<Amulet::NBT::ListTag>> ListTag(m, "ListTag",
173+
py::classh<Amulet::NBT::ListTag> ListTag(m, "ListTag", AbstractBaseMutableTag,
176174
"A Python wrapper around a C++ vector.\n"
177175
"\n"
178176
"All contained data must be of the same NBT data type.");

src/amulet/nbt/tag/named_tag.py.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void init_named_tag(py::module& m)
5555
py::object mutf8_encoding = m.attr("mutf8_encoding");
5656
py::object java_encoding = m.attr("java_encoding");
5757

58-
py::class_<AmuletPy::NamedTagIterator> NamedTagIterator(m, "NamedTagIterator");
58+
py::classh<AmuletPy::NamedTagIterator> NamedTagIterator(m, "NamedTagIterator");
5959
NamedTagIterator.def(
6060
"__next__",
6161
&AmuletPy::NamedTagIterator::next);
@@ -65,7 +65,7 @@ void init_named_tag(py::module& m)
6565
return self;
6666
});
6767

68-
py::class_<Amulet::NBT::NamedTag, std::shared_ptr<Amulet::NBT::NamedTag>> NamedTag(m, "NamedTag");
68+
py::classh<Amulet::NBT::NamedTag> NamedTag(m, "NamedTag");
6969
NamedTag.def(
7070
py::init([](std::variant<std::monostate, Amulet::NBT::TagNode> value, std::string name) {
7171
return std::visit([&name](auto&& tag) {

src/amulet/nbt/tag/string.py.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void init_string(py::module& m)
2424
py::object mutf8_encoding = m.attr("mutf8_encoding");
2525
py::object java_encoding = m.attr("java_encoding");
2626

27-
py::class_<Amulet::NBT::StringTag, Amulet::NBT::AbstractBaseImmutableTag> StringTag(m, "StringTag",
27+
py::classh<Amulet::NBT::StringTag, Amulet::NBT::AbstractBaseImmutableTag> StringTag(m, "StringTag",
2828
"A class that behaves like a string.");
2929
StringTag.def_property_readonly_static("tag_id", [](py::object) { return 8; });
3030
StringTag.def(

0 commit comments

Comments
 (0)