Skip to content

Decouple C++ Implementations from Python Bindings #47

@wgledbe

Description

@wgledbe

It would be unbelievably nice to use the core objects in other projects without being married to the Python bindings.

A potential refactor could look something like:

// Current
template<class Stuff>
struct Thing {
  // Blah...

  static void Build(py::module& m, const char* name) {
    auto obj = py::class_<Thing<Stuff>>(m, name);

    // more stuff

    Base::DenseBaseBuild(obj);
};

static void BuildThings(py::module& m) {
  Thing<Wow>::Build(m, "ThingWow");
  Thing<Fake>::Build(m, "ThingFake");
}

becomes

// Proposed
#include "Thing.h"
#include "BuildDenseBase.h"

template<class Stuff>
static void BuildThing(py::module& m, const char* name) {
  auto obj = py::class_<Thing<Stuff>>(m, name);

  // You already know

  BuildDenseBase<Thing<Stuff>>(obj);
}

static void BuildThings(py::module& m) {
  BuildThing<Wow>(m, "ThingWow");
  BuildThing<Fake>(m, "ThingFake");
}

This way, you'd have a totally separate folder (I like calling it bind) that only contains a bunch of these BuildWhatever functions. The core implementations wouldn't know about the bindings at all.
Really just flipping it all inside-out.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions