Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Dec 1, 2024
1 parent 92c0acc commit 5ac3f00
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wrapper/cccorelib/src/ScalarField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -156,7 +163,10 @@ class ScalarFieldView

void define_ScalarField(py::module &cccorelib)
{
py::class_<ScalarFieldView>(cccorelib, "ScalarFieldView").def("__getitem__", &ScalarFieldView::get_item);
py::class_<ScalarFieldView>(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, CCShareable, CCShareableHolder<CCCoreLib::ScalarField>>(cccorelib,
"ScalarField",
Expand Down Expand Up @@ -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("<ScalarField(name=") + self.getName() + ")>"; });
Expand Down

0 comments on commit 5ac3f00

Please sign in to comment.