| 633 | } |
| 634 | |
| 635 | void ObjectIdentifier::Component::set(Py::Object& pyobj, const Py::Object& value) const |
| 636 | { |
| 637 | if (isSimple()) { |
| 638 | if (PyObject_SetAttrString(*pyobj, getName().c_str(), *value) == -1) { |
| 639 | Base::PyException::throwException(); |
| 640 | } |
| 641 | } |
| 642 | else if (isArray()) { |
| 643 | if (pyobj.isMapping()) { |
| 644 | Py::Mapping(pyobj).setItem(Py::Long(begin), value); |
| 645 | } |
| 646 | else { |
| 647 | Py::Sequence(pyobj).setItem(begin, value); |
| 648 | } |
| 649 | } |
| 650 | else if (isMap()) { |
| 651 | Py::Mapping(pyobj).setItem(getName(), value); |
| 652 | } |
| 653 | else { |
| 654 | assert(isRange()); |
| 655 | constexpr int max = std::numeric_limits<int>::max(); |
| 656 | Py::Object slice(PySlice_New(Py::Long(begin).ptr(), |
| 657 | end != max ? Py::Long(end).ptr() : nullptr, |
| 658 | step != 1 ? Py::Long(step).ptr() : nullptr), |
| 659 | true); |
| 660 | if (PyObject_SetItem(pyobj.ptr(), slice.ptr(), value.ptr()) < 0) { |
| 661 | Base::PyException::throwException(); |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | void ObjectIdentifier::Component::del(Py::Object& pyobj) const |
| 667 | { |