Commit 884d0bdf authored by Jason Rhinelander's avatar Jason Rhinelander

Trampoline methods should be public; _added/_removed were missing

parent 8e8b0e3d
......@@ -17,6 +17,11 @@ void bind_members(py::module &m) {
// templated type casting, but really aren't that useful in Python since types are dynamic
.def("depends_on", &Member::dependsOn, "Records a dependency with the member's simulation; typically invoked in the _added() method.")
.def("depends_weakly_on", &Member::dependsWeaklyOn, "Records a weak dependency with the member's simulation; typically invoked in the _added() method.")
// NB: the following descriptions about the default doing nothing is true from the Python
// side; from the C++ side, added() and removed() handle creating/destroying optimizer glue
// classes to convert duck typing into the appropriate eris interface implementations.
.def("_added", &PyMember<>::added, "Called immediately after the member has been added to the simulation, to perform any simulation-dependent initialization. The default implementation does nothing.")
.def("_removed", &PyMember<>::removed, "Called immediately after the member has been removed from the simulation. The `.id` and `.simulation` attributes are still available, but the simulation itself no longer references this member. The default implementation does nothing.")
;
py::implicitly_convertible<Member, eris_id_t>();
......
......@@ -17,17 +17,18 @@ namespace pyeris { namespace core {
template <class Base = Member>
class PyMember : public Base {
public:
// Inherit constructors
using Base::Base;
virtual void added() override {
OptimizerGlue::applyGlue(this->simulation(), this->sharedSelf(), py::cast(this));
PYBIND11_OVERLOAD(void, Base, added);
PYBIND11_OVERLOAD_NAME(void, Base, "_added", added);
}
virtual void removed() override {
/* Simulation takes a reference during add(), we release it during member.removed() */
py::cast(this).dec_ref();
PYBIND11_OVERLOAD(void, Base, removed);
PYBIND11_OVERLOAD_NAME(void, Base, "_added", removed);
}
virtual void weakDepRemoved(SharedMember<Member> removed, eris_id_t old_id) override {
PYBIND11_OVERLOAD_NAME(void, Base, "weak_dep_removed", weakDepRemoved, removed, old_id);
......@@ -36,12 +37,14 @@ class PyMember : public Base {
template <class Base = Agent>
class PyAgent : public PyMember<Base> {
public:
// Inherit constructors
using PyMember<Base>::PyMember;
};
template <class Base = Good>
class PyGood : public PyMember<Base> {
public:
// Inherit constructors
using PyMember<Base>::PyMember;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment