// // Copyright 2020 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // #include "property_tree_python.hpp" #include #include #include #include #include namespace py = pybind11; template void export_property(py::module& m, const std::string& type_str) { const std::string classname = std::string("property__") + type_str; py::class_>(m, classname.c_str()) .def("get", &uhd::property::get) .def("get_desired", &uhd::property::get_desired) .def("set", &uhd::property::set) .def("set_coerced", &uhd::property::set_coerced); } void export_property_tree(py::module& m) { using property_tree = uhd::property_tree; using fs_path = uhd::fs_path; py::class_(m, "fs_path") // Constructors .def(py::init<>()) .def(py::init()); py::implicitly_convertible(); // Per type we want to expose, add one line here, and one accessor below export_property(m, "int"); export_property(m, "double"); export_property(m, "str"); export_property(m, "bool"); export_property(m, "device_addr"); py::class_(m, "property_tree") .def("subtree", &property_tree::subtree, py::arg("path")) .def("exists", &property_tree::exists, py::arg("path")) .def("list", &property_tree::list, py::arg("path")) // One line per type .def( "access_int", &property_tree::access, py::return_value_policy::reference) .def("access_double", &property_tree::access, py::return_value_policy::reference) .def("access_str", &property_tree::access, py::return_value_policy::reference) .def("access_bool", &property_tree::access, py::return_value_policy::reference) .def("access_device_addr", &property_tree::access, py::return_value_policy::reference) // End of types ; }