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
|
/*
* SPDX-FileCopyrightText: All Contributors to the PyTango project
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "common_header.h"
#include "convertors/type_casters.h"
#include "pyutils.h"
template <typename ListType, typename ItemType>
void bindGroupReplyList(py::module &m, const char *py_name) {
py::class_<ListType>(m, py_name, py::dynamic_attr())
.def(py::init<>())
.def("has_failed", &ListType::has_failed)
.def("reset", &ListType::reset)
.def("push_back", &ListType::push_back)
// .def("__len__", &ListType::size)
// I do not understand it, but if I just directly bind __len__ to size ,
// I get recursion error, so have to do the following:
.def("__len__", [](ListType &self) -> std::size_t {
return self.size();
})
.def(
"__getitem__", [](ListType &self, std::size_t i) -> ItemType & {
if(i >= self.size()) {
throw py::index_error("Index out of range");
}
return self[i];
},
py::return_value_policy::reference_internal);
}
void export_group_reply_list(py::module &m) {
bindGroupReplyList<Tango::GroupReplyList, Tango::GroupReply>(m, "GroupReplyList");
bindGroupReplyList<Tango::GroupCmdReplyList, Tango::GroupCmdReply>(m, "GroupCmdReplyList");
bindGroupReplyList<Tango::GroupAttrReplyList, Tango::GroupAttrReply>(m, "GroupAttrReplyList");
fix_dynamic_attr_dealloc<Tango::GroupReplyList>();
fix_dynamic_attr_dealloc<Tango::GroupCmdReplyList>();
fix_dynamic_attr_dealloc<Tango::GroupAttrReplyList>();
}
|