| 19 | namespace py = pybind11; |
| 20 | |
| 21 | void InitPropertyKeyPath(py::module_& m) |
| 22 | { |
| 23 | py::class_<mitk::PropertyKeyPath>(m, "PropertyKeyPath", |
| 24 | R"(Structured representation of a hierarchical property key. |
| 25 | |
| 26 | MITK property keys are dot-separated (e.g. ``"DICOM.PatientName"``, |
| 27 | ``"sequence.[2].label"``). ``PropertyKeyPath`` is the typed, manipulable |
| 28 | form: nodes carry an element name and an optional selection (a specific |
| 29 | index, ``[*]`` wildcard, or none). |
| 30 | |
| 31 | Supports ``pathlib.Path``-style ``/`` concatenation and ``[]`` indexing for |
| 32 | selections. Convert to/from MITK property name strings via |
| 33 | :py:meth:`from_string` and ``str(path)``. |
| 34 | |
| 35 | Examples: |
| 36 | >>> p = mitk.PropertyKeyPath("DICOM") / "PatientName" |
| 37 | >>> str(p) |
| 38 | 'DICOM.PatientName' |
| 39 | >>> p = mitk.PropertyKeyPath("seq")[2] |
| 40 | >>> str(p) |
| 41 | 'seq.[2]' |
| 42 | )") |
| 43 | .def(py::init<>(), "Construct an empty path.") |
| 44 | |
| 45 | // Construction from string |
| 46 | .def_static("from_string", |
| 47 | [](const std::string& propertyName) |
| 48 | { return mitk::PropertyNameToPropertyKeyPath(propertyName); }, |
| 49 | py::arg("property_name"), |
| 50 | "Parse a property name string into a PropertyKeyPath.") |
| 51 | |
| 52 | // Construction from single element |
| 53 | .def(py::init([](const std::string& element) |
| 54 | { return mitk::PropertyKeyPath({element}); }), |
| 55 | py::arg("element"), |
| 56 | "Create a PropertyKeyPath with a single element.") |
| 57 | |
| 58 | // Properties |
| 59 | .def_property_readonly("is_explicit", &mitk::PropertyKeyPath::IsExplicit, |
| 60 | "True if the path has no wildcards.") |
| 61 | .def_property_readonly("is_empty", &mitk::PropertyKeyPath::IsEmpty, |
| 62 | "True if the path has no nodes.") |
| 63 | .def("__len__", &mitk::PropertyKeyPath::GetSize, |
| 64 | "Return the number of nodes in the path.") |
| 65 | |
| 66 | // String conversion |
| 67 | .def("__str__", |
| 68 | [](const mitk::PropertyKeyPath& self) |
| 69 | { return mitk::PropertyKeyPathToPropertyName(self); }, |
| 70 | "Return the property name string representation.") |
| 71 | .def("__repr__", |
| 72 | [](const mitk::PropertyKeyPath& self) |
| 73 | { return "<mitk.PropertyKeyPath: " + mitk::PropertyKeyPathToPropertyName(self) + ">"; }) |
| 74 | |
| 75 | // Equality comparison |
| 76 | .def("__eq__", |
| 77 | [](const mitk::PropertyKeyPath& self, const py::object& other) |
| 78 | { |
no test coverage detected