In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

bindings_hints.hpp 1.87 KB
Newer Older
Nikola Dinev's avatar
Nikola Dinev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "EDFHandler.h"
#include "MHDHandler.h"

#include <pybind11/pybind11.h>

#include <functional>

namespace elsa
{
    template <typename Class>
    struct ClassHints {
    };

    template <class Return, class... Args>
    using CustomMethod = std::pair<bool, std::function<Return(Args...)>>;

    namespace py = pybind11;

    struct EDFHints : public ClassHints<EDF> {
        constexpr static std::tuple ignoreMethods = {"read"};

        template <typename type_, typename... options>
        static void addCustomMethods(py::class_<type_, options...>& c)
        {
            c.def_static(
                 "readf", [](std::string filename) { return EDF::read<float>(filename); },
                 py::return_value_policy::move)
                .def_static(
                    "readd", [](std::string filename) { return EDF::read<double>(filename); },
                    py::return_value_policy::move)
                .def_static(
                    "readl", [](std::string filename) { return EDF::read<index_t>(filename); },
                    py::return_value_policy::move);
        }
    };

    struct MHDHints : public ClassHints<MHD> {
        constexpr static std::tuple ignoreMethods = {"read"};

        template <typename type_, typename... options>
        static void addCustomMethods(py::class_<type_, options...>& c)
        {
            c.def_static(
                 "readf", [](std::string filename) { return MHD::read<float>(filename); },
                 py::return_value_policy::move)
                .def_static(
                    "readd", [](std::string filename) { return MHD::read<double>(filename); },
                    py::return_value_policy::move)
                .def_static(
                    "readl", [](std::string filename) { return MHD::read<index_t>(filename); },
                    py::return_value_policy::move);
        }
    };
} // namespace elsa