From 76f606f01fbac40dd676dd8243e1b6ac0ec655e5 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Fri, 13 Apr 2018 18:26:42 +0200
Subject: [PATCH] Python bindings with pybind11 as submodule

---
 .gitmodules    |  3 +++
 pybind11       |  1 +
 src/python.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 pybind11
 create mode 100644 src/python.cpp

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..a90eb861
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "pybind11"]
+	path = pybind11
+	url = https://github.com/pybind/pybind11.git
diff --git a/pybind11 b/pybind11
new file mode 160000
index 00000000..8fbb5594
--- /dev/null
+++ b/pybind11
@@ -0,0 +1 @@
+Subproject commit 8fbb5594fdf02eea6024d7b0c5eef3891d7366ab
diff --git a/src/python.cpp b/src/python.cpp
new file mode 100644
index 00000000..34d24a19
--- /dev/null
+++ b/src/python.cpp
@@ -0,0 +1,44 @@
+/*
+ * python.cpp
+ * 
+ * Copyright 2018 Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
+ * 
+ * This file is part of ngC.
+ * 
+ * ngC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * ngC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+#include <pybind11/pybind11.h>
+#include "ParticleID.hpp"
+
+/* 
+ * to compile, cd to ngc/build and
+ *     g++ -shared -fPIC -std=c++14 -I /usr/include/python3.5/ \
+ *     -I ../pybind11/include/  -I ../include \
+ *     -o example`python3-config --extension-suffix` ../src/python.cpp
+ * then open a python3 shell and import example
+ */
+
+PYBIND11_MODULE(example, m) {
+    m.doc() = "pybind11 example plugin"; // optional module docstring
+        
+    pybind11::enum_<ngc::ParticleID>(m, "ParticleID")
+        .value("gamma", ngc::ParticleID::GAMMA)
+        .value("positron", ngc::ParticleID::POSITRON)
+        .value("electron", ngc::ParticleID::ELECTRON)
+        .value("mu_p", ngc::ParticleID::MU_P)
+        .value("mu_m", ngc::ParticleID::MU_M);
+        // to be continued...
+}
-- 
GitLab