当前位置: 首页>>代码示例>>C++>>正文


C++ Type::isBad方法代码示例

本文整理汇总了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));
}
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:15,代码来源:SelectionObjectPyImp.cpp

示例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);
}
开发者ID:abdullahtahiriyo,项目名称:FreeCAD_sf_master,代码行数:21,代码来源:ExtensionContainerPyImp.cpp

示例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;
}
开发者ID:abdullahtahiriyo,项目名称:FreeCAD_sf_master,代码行数:70,代码来源:ExtensionContainerPyImp.cpp


注:本文中的base::Type::isBad方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。