MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / get

Method get

src/App/Expression.cpp:745–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745Py::Object Expression::Component::get(const Expression *owner, const Py::Object &pyobj) const {
746 try {
747 if(!e1 && !e2 && !e3)
748 return comp.get(pyobj);
749 if(!comp.isRange() && !e2 && !e3) {
750 auto index = e1->getPyValue();
751 Py::Object res;
752 if(pyobj.isMapping())
753 res = Py::Mapping(pyobj).getItem(index);
754 else {
755 Py_ssize_t i = PyNumber_AsSsize_t(index.ptr(), PyExc_IndexError);
756 if(PyErr_Occurred())
757 throw Py::Exception();
758 res = Py::Sequence(pyobj).getItem(i);
759 }
760 if(!res.ptr())
761 throw Py::Exception();
762 return res;
763 }else{
764 Py::Object v1,v2,v3;
765 if(e1) v1 = e1->getPyValue();
766 if(e2) v2 = e2->getPyValue();
767 if(e3) v3 = e3->getPyValue();
768 PyObject *s = PySlice_New(e1?v1.ptr():nullptr,
769 e2?v2.ptr():nullptr,
770 e3?v3.ptr():nullptr);
771 if(!s)
772 throw Py::Exception();
773 Py::Object slice(s,true);
774 PyObject *res = PyObject_GetItem(pyobj.ptr(),slice.ptr());
775 if(!res)
776 throw Py::Exception();
777 return Py::asObject(res);
778 }
779 }catch(Py::Exception &) {
780 EXPR_PY_THROW(owner);
781 }
782 return Py::Object();
783}
784
785void Expression::Component::set(const Expression *owner, Py::Object &pyobj, const Py::Object &value) const
786{

Callers 15

syncCopyOnChangeMethod · 0.45
beforeSaveMethod · 0.45
saveMethod · 0.45
restoreMethod · 0.45
eraseMethod · 0.45
findMethod · 0.45
findAllMethod · 0.45
addChildElementsMethod · 0.45
installTranslatorImplFunction · 0.45
removeTranslatorsImplFunction · 0.45

Calls 6

SequenceClass · 0.85
ExceptionClass · 0.70
ObjectClass · 0.70
getPyValueMethod · 0.45
getItemMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected