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


C++ PyBool_Check函数代码示例

本文整理汇总了C++中PyBool_Check函数的典型用法代码示例。如果您正苦于以下问题:C++ PyBool_Check函数的具体用法?C++ PyBool_Check怎么用?C++ PyBool_Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PyBool_Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PythonException

// =============================================================================
int * Epetra_NumPyIntVector::getArray(const Epetra_BlockMap & blockMap,
				      PyObject * pyObject)
{
  // Only build the tmp_array if it does not already exist
  if (!tmp_array)
  {
    // Default dimensions
    npy_intp defaultDims[ ] = { blockMap.NumMyPoints() };

    // PyObject argument is a bool
    if (PyBool_Check(pyObject))
    {
      tmp_array = (PyArrayObject *)
	PyArray_SimpleNew(1,defaultDims,NPY_INT);
    }
    // PyObject argument is not a bool ... try to build a contiguous
    // PyArrayObject from it
    else
    {
      tmp_array = (PyArrayObject *)
	PyArray_ContiguousFromObject(pyObject,NPY_INT,0,0);
    }
    // If any PyArray factory functions fail, clean up and throw a
    // PythonException
    if (!tmp_array)
    {
      cleanup();
      throw PythonException();
    }
    int  nd = PyArray_NDIM(tmp_array);
    npy_intp arraySize = PyArray_MultiplyList(PyArray_DIMS(tmp_array),nd);
    if (arraySize != defaultDims[0])
    {
      PyArrayObject * myArray = (PyArrayObject *)
	PyArray_SimpleNew(1,defaultDims,NPY_INT);
      if (!myArray)
      {
	cleanup();
	throw PythonException();
      }
      int * myData  = (int *) PyArray_DATA(myArray);
      int * tmpData = (int *) PyArray_DATA(tmp_array);
      for (int i=0; i<defaultDims[0]; i++)
      {
	myData[i] = tmpData[i];
      }
      Py_XDECREF(tmp_array);
      tmp_array = myArray;
    }
  }
  return (int*)(PyArray_DATA(tmp_array));
}
开发者ID:00liujj,项目名称:trilinos,代码行数:53,代码来源:Epetra_NumPyIntVector.cpp

示例2: get_slot

      static unaryfunc* get_slot(PyObject* obj)
      {
          PyNumberMethods* number_methods = obj->ob_type->tp_as_number;
          if (number_methods == 0)
              return 0;

          return (
#if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT)
          !PyBool_Check(obj) &&
#endif
          (PyInt_Check(obj) || PyLong_Check(obj)))
              ? &py_object_identity : 0;
      }
开发者ID:RossBille,项目名称:vim-config,代码行数:13,代码来源:builtin_converters.cpp

示例3: pshoutobj_set_bool

static int pshoutobj_set_bool(ShoutObjectAttr* attr, ShoutObject* self, PyObject* v) {
  long val;
  pshout_set_shout_int set_shout;

  if (!PyBool_Check(v)) {
    PyErr_SetString(PyExc_TypeError, "Boolean argument required");
    return -1;
  }

  val = (v == Py_True) ? 1 : 0;
  set_shout = (pshout_set_shout_int)attr->set_shout;
  return set_shout(self->conn, val);
}
开发者ID:csakoda,项目名称:python-shout,代码行数:13,代码来源:shout.c

示例4: pySetOptimized

//-------------------------------------------------------------------------------------
int VolatileInfo::pySetOptimized(PyObject *value)
{
	if (!PyBool_Check(value))
	{
		PyErr_Format(PyExc_AssertionError, "%s: set pitch value is not bool!\n",
			scriptName());
		PyErr_PrintEx(0);
		return 0;
	}

	optimized_ = value == Py_True;
	return 0;
}
开发者ID:BombShen,项目名称:kbengine,代码行数:14,代码来源:volatileinfo.cpp

示例5: Image_setDepth

// set depth
int Image_setDepth (PyImage * self, PyObject * value, void * closure)
{
	// check parameter, report failure
	if (value == NULL || !PyBool_Check(value))
	{
		PyErr_SetString(PyExc_TypeError, "The value must be a bool");
		return -1;
	}
	// set scale
	if (self->m_image != NULL) self->m_image->setDepth(value == Py_True);
	// success
	return 0;
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:14,代码来源:ImageBase.cpp

示例6: VideoFFmpeg_setDeinterlace

// set flip
static int VideoFFmpeg_setDeinterlace(PyImage *self, PyObject *value, void *closure)
{
	// check parameter, report failure
	if (value == NULL || !PyBool_Check(value))
	{
		PyErr_SetString(PyExc_TypeError, "The value must be a bool");
		return -1;
	}
	// set deinterlace
	getFFmpeg(self)->setDeinterlace(value == Py_True);
	// success
	return 0;
}
开发者ID:Ichthyostega,项目名称:blender,代码行数:14,代码来源:VideoFFmpeg.cpp

示例7: range_index

static PyObject *
range_index(rangeobject *r, PyObject *ob)
{
    PyObject *idx, *tmp;
    int contains;
    PyObject *format_tuple, *err_string;
    static PyObject *err_format = NULL;

    if (!PyLong_CheckExact(ob) && !PyBool_Check(ob)) {
        Py_ssize_t index;
        index = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_INDEX);
        if (index == -1)
            return NULL;
        return PyLong_FromSsize_t(index);
    }

    contains = range_contains_long(r, ob);
    if (contains == -1)
        return NULL;

    if (!contains)
        goto value_error;

    tmp = PyNumber_Subtract(ob, r->start);
    if (tmp == NULL)
        return NULL;

    /* idx = (ob - r.start) // r.step */
    idx = PyNumber_FloorDivide(tmp, r->step);
    Py_DECREF(tmp);
    return idx;

value_error:

    /* object is not in the range */
    if (err_format == NULL) {
        err_format = PyUnicode_FromString("%r is not in range");
        if (err_format == NULL)
            return NULL;
    }
    format_tuple = PyTuple_Pack(1, ob);
    if (format_tuple == NULL)
        return NULL;
    err_string = PyUnicode_Format(err_format, format_tuple);
    Py_DECREF(format_tuple);
    if (err_string == NULL)
        return NULL;
    PyErr_SetObject(PyExc_ValueError, err_string);
    Py_DECREF(err_string);
    return NULL;
}
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:51,代码来源:rangeobject.c

示例8: intersection

static PyObject*
intersection(PygtsSegment *self, PyObject *args)
{
  PyObject *t_,*boundary_=NULL;
  PygtsTriangle *t;
  gboolean boundary=TRUE;
  GtsVertex *v;
  PygtsObject *vertex;

  SELF_CHECK

  /* Parse the args */
  if(! PyArg_ParseTuple(args, "O|O", &t_, &boundary_) ) {
    return NULL;
  }

  /* Convert to PygtsObjects */
  if(!pygts_triangle_check(t_)) {
    PyErr_SetString(PyExc_TypeError,"expected a Triangle and boolean");
    return NULL;
  }
  t = PYGTS_TRIANGLE(t_);

  if( boundary_ != NULL ) {
    if(PyBool_Check(boundary_)==FALSE) {
      PyErr_SetString(PyExc_TypeError,"expected a Triangle and boolean");
      return NULL;
    }
    if( boundary_ == Py_False ){  /* Default TRUE */
      boundary = FALSE;
    }
  }

  v = GTS_VERTEX( gts_segment_triangle_intersection(
		      PYGTS_SEGMENT_AS_GTS_SEGMENT(self),
		      PYGTS_TRIANGLE_AS_GTS_TRIANGLE(t),
		      boundary,
		      GTS_POINT_CLASS(gts_vertex_class())) );

  if( v == NULL ) {
    Py_INCREF(Py_None);
    return Py_None;
  }

  if( (vertex = pygts_vertex_new(v)) == NULL ) {
    return NULL;
  }

  return (PyObject *)vertex;
}
开发者ID:Azeko2xo,项目名称:woodem,代码行数:50,代码来源:segment.cpp

示例9: x11_frame_output_cb

static void x11_frame_output_cb(void *data, int video_width, int video_height,
                double video_pixel_aspect, int *dest_x, int *dest_y,
                int *dest_width, int *dest_height,
                double *dest_pixel_aspect, int *win_x, int *win_y) 
{
    x11_vo_user_data *user_data = (x11_vo_user_data *)data;
    PyObject *args, *result;
    PyGILState_STATE gstate;
    int success = 0;

    if (user_data->frame_output_callback && Py_IsInitialized()) {
        gstate = PyGILState_Ensure();
        args = Py_BuildValue("(iid)", video_width, video_height, video_pixel_aspect);
        result = PyEval_CallObject(user_data->frame_output_callback, args);
        Py_DECREF(args);
        if (result) {
            if (PyBool_Check(result) || result == Py_None) {
                // Probably WeakCallback returning False because we're on shutdown.
                success = 0;
            } else if (!PyArg_ParseTuple(result, "(ii)(ii)(ii)d", dest_x, dest_y, win_x, win_y,
                                         dest_width, dest_height, dest_pixel_aspect)) {
                // FIXME: find a way to propagate this back to the main thread.
                printf("EXCEPTION: frame_output_cb returned bad arguments (%s).\n", result->ob_type->tp_name);
                PyErr_Print();
            } else {
                success = 1;
                user_data->last_width = *dest_width;
                user_data->last_height = *dest_height;
                user_data->last_aspect = *dest_pixel_aspect; 
            }
            Py_DECREF(result);
        } else {
            // FIXME: find a way to propagate this back to the main thread.
            printf("EXCEPTION in frame_output_cb!\n");
            PyErr_Print();
        }

        PyGILState_Release(gstate);
    }

    if (!success) {
        // Call to python space failed, but we need to set some sane defaults
        // here, or else xine does ugly things.  So we'll use the last values.
        *dest_x = *dest_y = *win_x = *win_y = 0;
        *dest_width = user_data->last_width;
        *dest_height = user_data->last_height;
        *dest_pixel_aspect = user_data->last_aspect;
    }
}
开发者ID:clones,项目名称:kaa,代码行数:49,代码来源:x11.c

示例10: switch

bool FunctionParameter::check(PyObject* obj) {
  switch (type_) {
    case ParameterType::TENSOR: {
      return THPVariable_Check(obj);
    }
    case ParameterType::SCALAR:
    case ParameterType::DOUBLE: {
      // NOTE: we don't currently accept most NumPy types as Scalars. np.float64
      // is okay because it's a subclass of PyFloat. We may want to change this
      // in the future.
      if (THPUtils_checkDouble(obj)) {
        return true;
      }
      if (THPVariable_Check(obj)) {
        auto& var = ((THPVariable*)obj)->cdata;
        return !var.requires_grad() && var.dim() == 0;
      }
      return false;
    }
    case ParameterType::INT64: {
      if (THPUtils_checkLong(obj)) {
        return true;
      }
      if (THPVariable_Check(obj)) {
        auto& var = ((THPVariable*)obj)->cdata;
        return at::isIntegralType(var.type().scalarType()) && !var.requires_grad() && var.dim() == 0;
      }
      return false;
    }
    case ParameterType::TENSOR_LIST: return PyTuple_Check(obj) || PyList_Check(obj);
    case ParameterType::INT_LIST: {
      if (PyTuple_Check(obj) || PyList_Check(obj)) {
        return true;
      }
      // if a size is specified (e.g. IntList[2]) we also allow passing a single int
      return size > 0 && THPUtils_checkLong(obj);
    }
    case ParameterType::GENERATOR: return THPGenerator_Check(obj);
    case ParameterType::BOOL: return PyBool_Check(obj);
    case ParameterType::STORAGE: return isStorage(obj);
    case ParameterType::PYOBJECT: return true;
    case ParameterType::SCALARTYPE: return THPDtype_Check(obj);
    case ParameterType::LAYOUT: return THPLayout_Check(obj);
    case ParameterType::DEVICE:
      return THPUtils_checkLong(obj) || THPUtils_checkString(obj) || THPDevice_Check(obj);
    case ParameterType::STRING: return THPUtils_checkString(obj);
    default: throw std::runtime_error("unknown parameter type");
  }
}
开发者ID:xiongyw,项目名称:pytorch,代码行数:49,代码来源:python_arg_parser.cpp

示例11: ids_core_Camera_setcontinuous_capture

static int ids_core_Camera_setcontinuous_capture(ids_core_Camera *self,
                                                 PyObject *value, void *closure) {
    int ret;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'continuous_capture'");
        return -1;
    }

    if (!PyBool_Check(value)) {
        PyErr_SetString(PyExc_TypeError, "Attribute 'continuous_capture' must be boolean");
        return -1;
    }

    /* Enable continuous capture */
    if (value == Py_True) {
        ret = is_CaptureVideo(self->handle, IS_DONT_WAIT);
        switch (ret) {
        case IS_SUCCESS:
            break;
        case IS_TIMED_OUT:
            PyErr_SetString(PyExc_IOError, "Continuous capture start timed out.");
            return -1;
        case IS_NO_ACTIVE_IMG_MEM:
            PyErr_SetString(PyExc_IOError, "No image memory available.");
            return -1;
        default:
            raise_general_error(self, ret);
            return -1;
        }
    }
    /* Disable continuous capture */
    else if (value == Py_False) {
        ret = is_StopLiveVideo(self->handle, IS_FORCE_VIDEO_STOP);
        switch (ret) {
        case IS_SUCCESS:
            break;
        default:
            raise_general_error(self, ret);
            return -1;
        }
    }
    else {
        PyErr_SetString(PyExc_ValueError, "Unknown boolean value");
        return -1;
    }

    return 0;
}
开发者ID:hftsai256,项目名称:ids,代码行数:49,代码来源:ids_core_Camera_attributes.c

示例12: SymList_computeDistanceAngles

/* computeDistance */
PyObject *
SymList_computeDistanceAngles(PyObject * obj, PyObject *args, PyObject *kwargs)
{
	double rot1, tilt1, psi1, rot2, tilt2, psi2;
    PyObject *pyProjdirMode = Py_False;
    PyObject *pyCheckMirrors = Py_False;
    PyObject *pyObjectRotation = Py_False;

    if (PyArg_ParseTuple(args, "dddddd|OOO", &rot1, &tilt1, &psi1, &rot2, &tilt2, &psi2,
                         &pyProjdirMode,
                         &pyCheckMirrors,
                         &pyObjectRotation))
    {
        try
        {
            bool projdir_mode    = false;
            bool check_mirrors   = false;
            bool object_rotation = false;
            if (PyBool_Check(pyProjdirMode))
                projdir_mode = (pyProjdirMode == Py_True);
            if (PyBool_Check(pyCheckMirrors))
                check_mirrors = (pyCheckMirrors == Py_True);
            if (PyBool_Check(pyObjectRotation))
                object_rotation = (pyObjectRotation == Py_True);
            SymListObject *self = (SymListObject*) obj;
            double dist=self->symlist->computeDistance(rot1,tilt1,psi1,rot2,tilt2,psi2,
            		projdir_mode,check_mirrors,object_rotation);
            return PyFloat_FromDouble(dist);
        }
        catch (XmippError &xe)
        {
            PyErr_SetString(PyXmippError, xe.msg.c_str());
        }
    }
    return NULL;
}
开发者ID:coocoky,项目名称:scipion,代码行数:37,代码来源:python_symmetry.cpp

示例13: printf

Visitor::Result PythonVisitor::processNodeTopDown(simulation::Node* node)
{
    PyObject *res=PyObject_CallMethod(m_PyVisitor,const_cast<char*>("processNodeTopDown"),const_cast<char*>("(O)"),SP_BUILD_PYSPTR(node));
    if (!res)
    {
        printf("<SofaPython> exception\n");
        PyErr_Print();
        return Visitor::RESULT_PRUNE;
    }

    if (PyBool_Check(res))
        return Visitor::RESULT_CONTINUE;

    return Visitor::RESULT_PRUNE;
}
开发者ID:mhdsedighi,项目名称:SOFA,代码行数:15,代码来源:PythonVisitor.cpp

示例14: use

//-----------------------------------------------------------------------------
// Variable_TypeByValue()
//   Return a variable type given a Python object or NULL if the Python
// object does not have a corresponding variable type.
//-----------------------------------------------------------------------------
static udt_VariableType *Variable_TypeByValue(
    PyObject* value,                    // Python type
    SQLUINTEGER* size)                  // size to use (OUT)
{
    if (value == Py_None) {
        *size = 1;
        return &ceString_VariableType;
    }
    if (ceString_Check(value)) {
        *size = ceString_GetSize(value);
        return &ceString_VariableType;
    }
#if PY_MAJOR_VERSION < 3
    if (PyUnicode_Check(value)) {
        *size = PyUnicode_GET_SIZE(value);
        return &vt_Unicode;
    }
#endif
    if (ceBinary_Check(value)) {
        udt_StringBuffer temp;
        if (StringBuffer_FromBinary(&temp, value) < 0)
            return NULL;
        *size = temp.size;
        StringBuffer_Clear(&temp);
        return &vt_Binary;
    }
    if (PyBool_Check(value))
        return &vt_Bit;
    if (PyInt_Check(value))
        return &vt_Integer;
    if (PyLong_Check(value))
        return &vt_BigInteger;
    if (PyFloat_Check(value))
        return &vt_Double;
    if (Py_TYPE(value) == (PyTypeObject*) g_DecimalType)
        return &vt_Decimal;
    if (PyTime_Check(value))
        return &vt_Time;
    if (PyDateTime_Check(value))
        return &vt_Timestamp;
    if (PyDate_Check(value))
        return &vt_Timestamp;

    PyErr_Format(g_NotSupportedErrorException,
            "Variable_TypeByValue(): unhandled data type %s",
            Py_TYPE(value)->tp_name);
    return NULL;
}
开发者ID:JoyceYL,项目名称:coolblue-ceodbc,代码行数:53,代码来源:Variable.c

示例15: PySequence_Fast_GET_ITEM

/**
 * Return a string for the array type to check the map for.
 * @param object :: Python object to check if it's an array
 * @return :: A string as the array type.
 */
const std::string PropertyWithValueFactory::isArray(PyObject *const object) {
  if (PyList_Check(object) || PyTuple_Check(object)) {
    // If we are dealing with an empty list/tuple, then we cannot deduce the
    // ArrayType. We need to throw at this point.
    if (PySequence_Size(object) < 1) {
      throw std::runtime_error(
          "Cannot have a sequence type of length zero in a mapping type.");
    }

    PyObject *item = PySequence_Fast_GET_ITEM(object, 0);
    // Boolean can be cast to int, so check first.
    if (PyBool_Check(item)) {
      throw std::runtime_error(
          "Unable to support extracting arrays of booleans.");
    }
    if (PyLong_Check(item)) {
      return std::string("LongIntArray");
    }
#if PY_MAJOR_VERSION < 3
    // In python 2 ints & longs are separate
    if (PyInt_Check(item)) {
      return std::string("IntArray");
    }
#endif
    if (PyFloat_Check(item)) {
      return std::string("FloatArray");
    }
#if PY_MAJOR_VERSION >= 3
    if (PyUnicode_Check(item)) {
      return std::string("StringArray");
    }
#endif
    if (PyBytes_Check(item)) {
      return std::string("StringArray");
    }
    // If we get here, we've found a sequence and we can't interpret the item
    // type.
    std::ostringstream os;
    os << "Cannot create PropertyWithValue from Python type "
       << object->ob_type->tp_name << " containing items of type "
       << item->ob_type
       << ". No converter registered in PropertyWithValueFactory.";

    throw std::invalid_argument(os.str());
  } else {
    return std::string("");
  }
}
开发者ID:DanNixon,项目名称:mantid,代码行数:53,代码来源:PropertyWithValueFactory.cpp


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