Exemple #1
0
//-------------------------------------------------------------------------------------
PyObject* FixedArray::__py_count(PyObject* self, PyObject* args, PyObject* kwargs)
{
	FixedArray* ary = static_cast<FixedArray*>(self);
	PyObject* pyItem = PyTuple_GetItem(args, 0);
	int count = 0, cur;
	for (uint32 i = 0; (cur = ary->findFrom(i, &*pyItem)) >= 0; i = cur + 1)
		++count;
	return PyLong_FromLong(count);	
}
Exemple #2
0
//-------------------------------------------------------------------------------------
PyObject* FixedArray::__py_index(PyObject* self, PyObject* args, PyObject* kwargs)
{
	FixedArray* ary = static_cast<FixedArray*>(self);
	PyObject* pyItem = PyTuple_GetItem(args, 0);
	int index = ary->findFrom(0, &*pyItem);
	if (index == -1)
	{
		PyErr_SetString(PyExc_ValueError, "FixedArray::index: value not found");
		return NULL;
	}
	return PyLong_FromLong(index);
}
Exemple #3
0
//-------------------------------------------------------------------------------------
PyObject* FixedArray::__py_remove(PyObject* self, PyObject* args, PyObject* kwargs)
{
	FixedArray* ary = static_cast<FixedArray*>(self);
	PyObject* pyItem = PyTuple_GetItem(args, 0);
	int index = ary->findFrom(0, &*pyItem);
	if (index == -1)
	{
		PyErr_SetString(PyExc_ValueError, "FixedArray.remove: value not found");
		return PyLong_FromLong(-1);
	}

	PyObject* pyTuple = PyTuple_New(0);
	return PyBool_FromLong(seq_ass_slice(self, index, index + 1, &*pyTuple) == 0);
}