diff --git a/wrapper/cccorelib/src/ScalarField.cpp b/wrapper/cccorelib/src/ScalarField.cpp index 614dfa3..0938e5a 100644 --- a/wrapper/cccorelib/src/ScalarField.cpp +++ b/wrapper/cccorelib/src/ScalarField.cpp @@ -41,6 +41,7 @@ class ScalarFieldView explicit ScalarFieldView(CCCoreLib::ScalarField &field, const py::slice &slice) : ScalarFieldView(field) { + applySlicing(slice); } py::object get_item(const py::object &index) @@ -67,6 +68,8 @@ class ScalarFieldView } return result; } + + throw py::index_error("Invalid index type"); } void set_item(const py::object &index, const py::object &value) @@ -132,6 +135,10 @@ class ScalarFieldView } } + size_t len() const { + return m_len; + } + void applySlicing(const py::slice &slice) { size_t start, stop, step, len = 0; @@ -156,7 +163,10 @@ class ScalarFieldView void define_ScalarField(py::module &cccorelib) { - py::class_(cccorelib, "ScalarFieldView").def("__getitem__", &ScalarFieldView::get_item); + py::class_(cccorelib, "ScalarFieldView") + .def("__len__", &ScalarFieldView::len) + .def("__getitem__", &ScalarFieldView::get_item, py::return_value_policy::reference_internal) + .def("__setitem__", &ScalarFieldView::set_item); py::class_>(cccorelib, "ScalarField", @@ -394,6 +404,7 @@ void define_ScalarField(py::module &cccorelib) .def("__setitem__", [](CCCoreLib::ScalarField &self, const py::object &index, const py::object &value) { return ScalarFieldView(self).set_item(index, value); }) + .def("__len__", &CCCoreLib::ScalarField::currentSize) .def("__repr__", [](const CCCoreLib::ScalarField &self) { return std::string(""; });