MCPcopy Create free account
hub / github.com/MITK/MITK / InitPropertyKeyPath

Function InitPropertyKeyPath

Wrapping/Python/mitk/PropertyKeyPath.cpp:21–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19namespace py = pybind11;
20
21void InitPropertyKeyPath(py::module_& m)
22{
23 py::class_<mitk::PropertyKeyPath>(m, "PropertyKeyPath",
24 R"(Structured representation of a hierarchical property key.
25
26MITK property keys are dot-separated (e.g. ``"DICOM.PatientName"``,
27``"sequence.[2].label"``). ``PropertyKeyPath`` is the typed, manipulable
28form: nodes carry an element name and an optional selection (a specific
29index, ``[*]`` wildcard, or none).
30
31Supports ``pathlib.Path``-style ``/`` concatenation and ``[]`` indexing for
32selections. Convert to/from MITK property name strings via
33:py:meth:`from_string` and ``str(path)``.
34
35Examples:
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 {

Callers 1

PYBIND11_MODULEFunction · 0.85

Calls 10

backMethod · 0.80
frontMethod · 0.80
AddElementMethod · 0.80
GetNodesMethod · 0.45
IsEmptyMethod · 0.45
sizeMethod · 0.45
AddNodeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected