/** * Reimplemented from UMLWidget::updateTextItemGroups() to * calculate the texts and also show/hide the texts based on current * state. */ void NodeWidget::updateTextItemGroups() { TextItemGroup *grp = textItemGroupAt(GroupIndex); grp->setTextItemCount(NodeWidget::TextItemCount); if(umlObject()) { UMLNode *node = static_cast<UMLNode*>(umlObject()); TextItem *stereo = grp->textItemAt(NodeWidget::StereoItemIndex); stereo->setText(node->stereotype(true)); stereo->setBold(true); stereo->setExplicitVisibility(!node->stereotype(false).isEmpty()); TextItem *nameItem = grp->textItemAt(NodeWidget::NameItemIndex); QString nameText = name(); bool underline = false; if(isInstance()) { nameText.prepend(':'); nameText.prepend(instanceName()); underline = true; } nameItem->setBold(true); nameItem->setUnderline(underline); nameItem->setText(nameText); } UMLWidget::updateTextItemGroups(); }
void Vm::callMethod(const SObject &instance, const SObject &funcName) { if (instance->getType() == Type::MODULE) { Vm::callModule(instance, funcName); return; } auto clsObj = std::dynamic_pointer_cast<ClassObject>(instance); assert(clsObj != nullptr); auto clsCo = clsObj->getCodeObject(); auto fnObj = clsCo->getValue(funcName->toString()); assert(fnObj != nullptr && "No function with such name!"); auto fn = std::dynamic_pointer_cast<FunctionObject>(fnObj); auto fnCo = fn->getCodeObject(clsCo); if (fn->isInit()) { assert(!clsObj->isInstance()); auto initCo = std::make_shared<CodeObject>(*clsCo); fnCo->setParent(initCo); } else { assert(clsObj->isInstance()); } pushCodeObject(fnCo); }
Formattable *toFormattableArray(PyObject *arg, int *len, classid id, PyTypeObject *type) { if (PySequence_Check(arg)) { *len = PySequence_Size(arg); Formattable *array = new Formattable[*len + 1]; for (int i = 0; i < *len; i++) { PyObject *obj = PySequence_GetItem(arg, i); if (isInstance(obj, id, type)) { array[i] = *(Formattable *) ((t_uobject *) obj)->object; Py_DECREF(obj); } else { Formattable *f = toFormattable(obj); if (f) { array[i] = *f; delete f; Py_DECREF(obj); } else { Py_DECREF(obj); delete[] array; return NULL; } } } return array; } return NULL; }
void verifyType(boost::python::object obj, const std::string& typeName) { if (!isInstance(obj, typeName)) throw ExcType(); }
static CMPIStatus __rft_returnInstance(const CMPIResult * result, const CMPIInstance * instance) { int size,isInst=isInstance(instance); void *ptr; NativeResult *r = (NativeResult*) result; int releaseInstance=0; CMPIStatus st={CMPI_RC_OK,NULL}; _SFCB_ENTER(TRACE_PROVIDERDRV, "__rft_returnInstance"); if (r->qs) { int irc; if (r->qs->where) { r->qs->propSrc.data=(CMPIInstance *)instance; irc=r->qs->where->ft->evaluate(r->qs->where,&r->qs->propSrc); if (irc==1) { if (r->qs->allProps==0) { instance= r->qs->ft->cloneAndFilter(r->qs,(CMPIInstance *)instance,CMGetObjectPath(instance, NULL),r->qs->keys); releaseInstance=1; } } else CMReturn(CMPI_RC_OK); } else { if (r->qs->allProps==0) { instance=r->qs->ft->cloneAndFilter(r->qs,(CMPIInstance *)instance,CMGetObjectPath(instance,NULL), r->qs->keys); releaseInstance=1; } } } if (r->legacy) { CMPIValue v; CMPIStatus rc; _SFCB_TRACE(1,("--- Legacy Mode")); if(isInst) { v.inst = CMClone(instance,NULL); memLinkInstance(v.inst); } else v.inst = (CMPIInstance *) instance; rc=returnData(result, &v, CMPI_instance); if (releaseInstance) instance->ft->release((CMPIInstance*)instance); _SFCB_RETURN(rc); } if (isInst) { size=getInstanceSerializedSize(instance); ptr=nextResultBufferPos(r, MSG_SEG_INSTANCE, (unsigned long)size); _SFCB_TRACE(1,("--- Moving instance %d",size)); getSerializedInstance(instance,ptr); /* memcpy inst to ptr */ } else { size=getConstClassSerializedSize((CMPIConstClass*)instance); ptr=nextResultBufferPos(r, MSG_SEG_CONSTCLASS, (unsigned long)size); _SFCB_TRACE(1,("--- Moving class %d",size)); getSerializedConstClass((CMPIConstClass*)instance,ptr); } if (releaseInstance) instance->ft->release((CMPIInstance*)instance); _SFCB_RETURN(st); }
int _parseArgs(PyObject **args, int count, const char *types, va_list list) #endif { if (count != strlen(types)) return -1; #else int _parseArgs(PyObject **args, int count, const char *types, ...) { va_list list; if (count != (int) strlen(types)) return -1; va_start(list, types); #endif if (PyErr_Occurred()) return -1; for (int i = 0; i < count; i++) { #ifdef PYPY_VERSION PyObject *arg = PyTuple_GetItem(args, i); #else PyObject *arg = args[i]; #endif switch (types[i]) { case 'c': /* string */ case 'k': /* string and size */ case 'C': /* string, not to be unpacked */ if (PyBytes_Check(arg)) break; return -1; case 's': /* string or unicode, to UnicodeString ref */ case 'u': /* string or unicode, to new UnicodeString ptr */ case 'n': /* string or unicode, to utf8 charsArg */ case 'f': /* string or unicode filename, to charsArg */ if (PyBytes_Check(arg) || PyUnicode_Check(arg)) break; return -1; case 'S': /* string, unicode or UnicodeString */ case 'W': /* string, unicode or UnicodeString, to save */ if (PyBytes_Check(arg) || PyUnicode_Check(arg) || isUnicodeString(arg)) break; return -1; case 'T': /* array of string, unicode or UnicodeString */ if (PySequence_Check(arg)) { if (PySequence_Length(arg) > 0) { PyObject *obj = PySequence_GetItem(arg, 0); int ok = (PyBytes_Check(obj) || PyUnicode_Check(obj) || isUnicodeString(obj)); Py_DECREF(obj); if (ok) break; } else break; } return -1; case 'U': /* UnicodeString */ case 'V': /* UnicodeString and raw arg object */ if (isUnicodeString(arg)) break; return -1; case 'K': /* python object of any type */ break; case 'M': /* python callable */ { if (PyCallable_Check(arg)) break; return -1; } case 'O': /* python object of given type */ { PyTypeObject *type = va_arg(list, PyTypeObject *); if (PyObject_TypeCheck(arg, type)) break; return -1; } case 'P': /* wrapped ICU object */ case 'p': /* wrapped ICU object, to save */ { classid id = va_arg(list, classid); PyTypeObject *type = va_arg(list, PyTypeObject *); if (isInstance(arg, id, type)) break; return -1; } case 'Q': /* array of wrapped ICU object pointers */ case 'R': /* array of wrapped ICU objects */ { classid id = va_arg(list, classid); PyTypeObject *type = va_arg(list, PyTypeObject *); if (PySequence_Check(arg)) { if (PySequence_Length(arg) > 0) { PyObject *obj = PySequence_GetItem(arg, 0); int ok = isInstance(obj, id, type); Py_DECREF(obj); if (ok) break; } else break; } return -1; } case 'D': /* date as UDate float or datetime */ if (isDate(arg)) break; return -1; case 'E': /* date as datetime */ if (isDateExact(arg)) break; return -1; case 'a': /* byte */ if (PyBytes_Check(arg) && (PyBytes_Size(arg) == 1)) break; return -1; case 'B': /* boolean, strict */ if (arg == Py_True || arg == Py_False) break; return -1; case 'b': /* boolean */ break; case 'i': /* int */ if (PyInt_Check(arg)) break; return -1; case 'd': /* double */ if (PyFloat_Check(arg) || PyInt_Check(arg) || PyLong_Check(arg)) break; return -1; case 'F': /* array of double */ if (PySequence_Check(arg)) { if (PySequence_Length(arg) > 0) { PyObject *obj = PySequence_GetItem(arg, 0); int ok = (PyFloat_Check(obj) || PyInt_Check(obj) || PyLong_Check(obj)); Py_DECREF(obj); if (ok) break; } else break; } return -1; case 'G': /* array of bool */ if (PySequence_Check(arg)) break; return -1; case 'L': /* PY_LONG_LONG */ if (PyLong_Check(arg) || PyInt_Check(arg)) break; return -1; default: return -1; } } for (int j = 0; j < count; j++) { #ifdef PYPY_VERSION PyObject *arg = PyTuple_GetItem(args, j); #else PyObject *arg = args[j]; #endif switch (types[j]) { case 'A': /* previous Python arg object */ { PyObject **obj = va_arg(list, PyObject **); #ifdef PYPY_VERSION *obj = PyTuple_GetItem(args, j - 1); #else *obj = args[j - 1]; #endif break; } case 'c': /* string */ { char **c = va_arg(list, char **); *c = PyBytes_AS_STRING(arg); break; } case 'k': /* string and size */ { char **c = va_arg(list, char **); int *l = va_arg(list, int *); *c = PyBytes_AS_STRING(arg); *l = PyBytes_GET_SIZE(arg); break; } case 'C': /* string, not to be unpacked */ { PyObject **obj = va_arg(list, PyObject **); *obj = arg; break; } case 's': /* string or unicode, to UnicodeString ref */ { UnicodeString *u = va_arg(list, UnicodeString *); try { PyObject_AsUnicodeString(arg, *u); } catch (ICUException e) { e.reportError(); return -1; } break; } case 'u': /* string or unicode, to new UnicodeString ptr */ { UnicodeString **u = va_arg(list, UnicodeString **); try { *u = PyObject_AsUnicodeString(arg); } catch (ICUException e) { e.reportError(); return -1; } break; } case 'n': /* string or unicode, to utf8 charsArg */ { charsArg *p = va_arg(list, charsArg *); if (PyUnicode_Check(arg)) { PyObject *bytes = PyUnicode_AsUTF8String(arg); if (bytes == NULL) return -1; p->own(bytes); } else { p->borrow(arg); } break; } case 'f': /* string or unicode filename, to charsArg */ { charsArg *p = va_arg(list, charsArg *); if (PyUnicode_Check(arg)) { #if PY_MAJOR_VERSION >= 3 PyObject *bytes = PyUnicode_EncodeFSDefault(arg); #else // TODO: Figure out fs encoding in a reasonable way PyObject *bytes = PyUnicode_AsUTF8String(arg); #endif if (bytes == NULL) return -1; p->own(bytes); } else { p->borrow(arg); } break; } case 'S': /* string, unicode or UnicodeString */ { UnicodeString **u = va_arg(list, UnicodeString **); UnicodeString *_u = va_arg(list, UnicodeString *); if (PyObject_TypeCheck(arg, &UObjectType_)) *u = (UnicodeString *) ((t_uobject *) arg)->object; else { try { PyObject_AsUnicodeString(arg, *_u); *u = _u; } catch (ICUException e) { e.reportError(); return -1; } } break; } case 'W': /* string, unicode or UnicodeString, to save */ { UnicodeString **u = va_arg(list, UnicodeString **); PyObject **obj = va_arg(list, PyObject **); if (PyObject_TypeCheck(arg, &UObjectType_)) { *u = (UnicodeString *) ((t_uobject *) arg)->object; Py_INCREF(arg); Py_XDECREF(*obj); *obj = arg; } else { try { *u = PyObject_AsUnicodeString(arg); Py_XDECREF(*obj); *obj = wrap_UnicodeString(*u, T_OWNED); } catch (ICUException e) { e.reportError(); return -1; } } break; } case 'T': /* array of string, unicode or UnicodeString */ { UnicodeString **array = va_arg(list, UnicodeString **); int *len = va_arg(list, int *); *array = toUnicodeStringArray(arg, len); if (!*array) return -1; break; } case 'U': /* UnicodeString */ { UnicodeString **u = va_arg(list, UnicodeString **); *u = (UnicodeString *) ((t_uobject *) arg)->object; break; } case 'V': /* UnicodeString and raw arg object */ { UnicodeString **u = va_arg(list, UnicodeString **); PyObject **obj = va_arg(list, PyObject **); *u = (UnicodeString *) ((t_uobject *) arg)->object; *obj = arg; break; } case 'K': /* python object of any type */ case 'M': /* python callable */ case 'O': /* python object of given type */ { PyObject **obj = va_arg(list, PyObject **); *obj = arg; break; } case 'P': /* wrapped ICU object */ { UObject **obj = va_arg(list, UObject **); *obj = ((t_uobject *) arg)->object; break; } case 'p': /* wrapped ICU object, to save */ { UObject **obj = va_arg(list, UObject **); PyObject **pyobj = va_arg(list, PyObject **); *obj = ((t_uobject *) arg)->object; Py_INCREF(arg); Py_XDECREF(*pyobj); *pyobj = arg; break; } case 'Q': /* array of wrapped ICU object pointers */ { UObject ***array = va_arg(list, UObject ***); int *len = va_arg(list, int *); classid id = va_arg(list, classid); PyTypeObject *type = va_arg(list, PyTypeObject *); *array = pl2cpa(arg, len, id, type); if (!*array) return -1; break; } case 'R': /* array of wrapped ICU objects */ { typedef UObject *(*convFn)(PyObject *, int *, classid, PyTypeObject *); UObject **array = va_arg(list, UObject **); int *len = va_arg(list, int *); classid id = va_arg(list, classid); PyTypeObject *type = va_arg(list, PyTypeObject *); convFn fn = va_arg(list, convFn); *array = fn(arg, len, id, type); if (!*array) return -1; break; } case 'D': /* date as UDate float or datetime */ case 'E': /* date as datetime */ { UDate *d = va_arg(list, UDate *); *d = PyObject_AsUDate(arg); break; } case 'a': /* byte */ { unsigned char *a = va_arg(list, unsigned char *); *a = (unsigned char) PyBytes_AS_STRING(arg)[0]; break; } case 'B': /* boolean, strict */ case 'b': /* boolean */ { int *b = va_arg(list, int *); *b = PyObject_IsTrue(arg); break; } case 'i': /* int */ { int *n = va_arg(list, int *); #if PY_MAJOR_VERSION >= 3 if ((*n = PyLong_AsLong(arg)) == -1 && PyErr_Occurred()) return -1; #else *n = PyInt_AsLong(arg); #endif break; } case 'd': /* double */ { double *d = va_arg(list, double *); if (PyFloat_Check(arg)) *d = PyFloat_AsDouble(arg); #if PY_MAJOR_VERSION < 3 else if (PyInt_Check(arg)) *d = (double) PyInt_AsLong(arg); #endif else *d = PyLong_AsDouble(arg); break; } case 'F': /* array of double */ { double **array = va_arg(list, double **); int *len = va_arg(list, int *); *array = toDoubleArray(arg, len); if (!*array) return -1; break; } case 'G': /* array of UBool */ { UBool **array = va_arg(list, UBool **); int *len = va_arg(list, int *); *array = toUBoolArray(arg, len); if (!*array) return -1; break; } case 'L': /* PY_LONG_LONG */ { PY_LONG_LONG *l = va_arg(list, PY_LONG_LONG *); *l = PyLong_AsLongLong(arg); break; } default: return -1; } } return 0; }