minimal export of Table

This commit is contained in:
Joachim Schoeberl 2021-05-30 22:15:21 +02:00
parent 9389ecdf62
commit 7c4f1cf53a
2 changed files with 28 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <pybind11/stl.h>
#include "array.hpp"
#include "table.hpp"
#include "archive.hpp"
#include "flags.hpp"
#include "ngcore_api.hpp"
@ -60,6 +61,23 @@ template <typename Type> struct type_caster<ngcore::Array<Type>>
: ngcore_list_caster<ngcore::Array<Type>, Type> { };
/*
template <typename Type> struct type_caster<std::shared_ptr<ngcore::Table<Type>>>
{
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent)
{
std::cout << "handle called with type src = " << typeid(src).name() << std::endl;
return handle(); // what so ever
}
PYBIND11_TYPE_CASTER(Type, _("Table[") + make_caster<Type>::name + _("]"));
};
*/
} // namespace detail
} // namespace pybind11
////////////////////////////////////////////////////////////////////////////////
@ -240,6 +258,14 @@ namespace ngcore
;
}
template <typename T>
void ExportTable (py::module &m)
{
py::class_<ngcore::Table<T>, std::shared_ptr<ngcore::Table<T>>> (m, ("Table+"+GetPyName<T>()).c_str())
;
}
void NGCORE_API SetFlag(Flags &flags, std::string s, py::object value);
// Parse python kwargs to flags
Flags NGCORE_API CreateFlagsFromKwArgs(const py::kwargs& kwargs, py::object pyclass = py::none(),

View File

@ -19,6 +19,8 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
ExportArray<size_t>(m);
ExportArray<double>(m);
ExportTable<int>(m);
py::class_<BitArray, shared_ptr<BitArray>> (m, "BitArray")
.def(py::init([] (size_t n) { return make_shared<BitArray>(n); }),py::arg("n"))
.def(py::init([] (const BitArray& a) { return make_shared<BitArray>(a); } ), py::arg("ba"))