本文整理汇总了C++中base::Type::isBad方法的典型用法代码示例。如果您正苦于以下问题:C++ Type::isBad方法的具体用法?C++ Type::isBad怎么用?C++ Type::isBad使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类base::Type
的用法示例。
在下文中一共展示了Type::isBad方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isObjectTypeOf
PyObject* SelectionObjectPy::isObjectTypeOf(PyObject * args)
{
char* type;
if (!PyArg_ParseTuple(args, "s", &type))
return 0;
Base::Type id = Base::Type::fromName(type);
if (id.isBad()) {
PyErr_SetString(PyExc_TypeError, "Not a valid type");
return 0;
}
bool ok = getSelectionObjectPtr()->isObjectTypeOf(id);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}
示例2: hasExtension
PyObject* ExtensionContainerPy::hasExtension(PyObject *args) {
char *type;
if (!PyArg_ParseTuple(args, "s", &type))
return NULL; // NULL triggers exception
//get the extension type asked for
Base::Type extension = Base::Type::fromName(type);
if(extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
std::stringstream str;
str << "No extension found of type '" << type << "'" << std::ends;
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
}
bool val = false;
if (getExtensionContainerPtr()->hasExtension(extension)) {
val = true;
}
return PyBool_FromLong(val ? 1 : 0);
}
示例3: addExtension
PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
char *typeId;
PyObject* proxy;
if (!PyArg_ParseTuple(args, "sO", &typeId, &proxy))
return NULL;
//get the extension type asked for
Base::Type extension = Base::Type::fromName(typeId);
if (extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
std::stringstream str;
str << "No extension found of type '" << typeId << "'" << std::ends;
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
}
//register the extension
App::Extension* ext = static_cast<App::Extension*>(extension.createInstance());
//check if this really is a python extension!
if (!ext->isPythonExtension()) {
delete ext;
std::stringstream str;
str << "Extension is not a python addable version: '" << typeId << "'" << std::ends;
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
}
ext->initExtension(getExtensionContainerPtr());
//set the proxy to allow python overrides
App::Property* pp = ext->extensionGetPropertyByName("ExtensionProxy");
if (!pp) {
std::stringstream str;
str << "Accessing the proxy property failed!" << std::ends;
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
}
static_cast<PropertyPythonObject*>(pp)->setPyObject(proxy);
// The PyTypeObject is shared by all instances of this type and therefore
// we have to add new methods only once.
PyObject* obj = ext->getExtensionPyObject();
PyMethodDef* meth = reinterpret_cast<PyMethodDef*>(obj->ob_type->tp_methods);
PyTypeObject *type = this->ob_type;
PyObject *dict = type->tp_dict;
// make sure to do the initialization only once
if (meth->ml_name) {
PyObject* item = PyDict_GetItemString(dict, meth->ml_name);
if (item == NULL) {
// Note: this adds the methods to the type object to make sure
// it appears in the call tips. The function will not be bound
// to an instance
Py_INCREF(dict);
while (meth->ml_name) {
PyObject *func;
func = PyCFunction_New(meth, 0);
if (func == NULL)
break;
if (PyDict_SetItemString(dict, meth->ml_name, func) < 0)
break;
Py_DECREF(func);
++meth;
}
Py_DECREF(dict);
}
}
Py_DECREF(obj);
Py_Return;
}