本文整理汇总了C++中PyList_SET_ITEM函数的典型用法代码示例。如果您正苦于以下问题:C++ PyList_SET_ITEM函数的具体用法?C++ PyList_SET_ITEM怎么用?C++ PyList_SET_ITEM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyList_SET_ITEM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PyList_New
PyObject *eStreamServer::getConnectedClients()
{
ePyObject ret;
int idx = 0;
int cnt = clients.size();
ret = PyList_New(cnt);
for (eSmartPtrList<eStreamClient>::iterator it = clients.begin(); it != clients.end(); ++it)
{
ePyObject tuple = PyTuple_New(3);
PyTuple_SET_ITEM(tuple, 0, PyString_FromString((char *)it->getRemoteHost().c_str()));
PyTuple_SET_ITEM(tuple, 1, PyString_FromString((char *)it->getServiceref().c_str()));
PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->isUsingEncoder()));
PyList_SET_ITEM(ret, idx++, tuple);
}
return ret;
}
示例2: while
static PyObject *t_locale_getISOLanguages(PyTypeObject *type)
{
const char *const *languages = Locale::getISOLanguages();
PyObject *list;
int len = 0;
while (languages[len] != NULL) len += 1;
list = PyList_New(len);
for (int i = 0; i < len; i++) {
PyObject *str = PyString_FromString(languages[i]);
PyList_SET_ITEM(list, i, str);
}
return list;
}
示例3: WM_operatortype_iter
static PyObject *pyop_dir(PyObject *UNUSED(self))
{
GHashIterator iter;
PyObject *list;
int i;
WM_operatortype_iter(&iter);
list = PyList_New(BLI_ghash_size(iter.gh));
for (i = 0; !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter), i++) {
wmOperatorType *ot = BLI_ghashIterator_getValue(&iter);
PyList_SET_ITEM(list, i, PyUnicode_FromString(ot->idname));
}
return list;
}
示例4: PyList_New
PyObject *eServiceEvent::getComponentData() const
{
ePyObject ret = PyList_New(m_component_data.size());
int cnt=0;
for (std::list<eComponentData>::const_iterator it(m_component_data.begin()); it != m_component_data.end(); ++it)
{
ePyObject tuple = PyTuple_New(5);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(it->m_componentTag));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(it->m_componentType));
PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(it->m_streamContent));
PyTuple_SET_ITEM(tuple, 3, PyString_FromString(it->m_iso639LanguageCode.c_str()));
PyTuple_SET_ITEM(tuple, 4, PyString_FromString(it->m_text.c_str()));
PyList_SET_ITEM(ret, cnt++, tuple);
}
return ret;
}
示例5: PyList_New
PyObject *PyMAPIObject_FromSPropValueArray(SPropValue *pv, ULONG nvalues)
{
PyObject *ret = PyList_New(nvalues);
if (!ret)
return NULL;
ULONG i;
for (i=0;i<nvalues;i++) {
PyObject *sub = PyMAPIObject_FromSPropValue(pv+i);
if (!sub) {
Py_DECREF(ret);
return NULL;
}
PyList_SET_ITEM(ret, i, sub);
}
return ret;
}
示例6: Py_LOCAL
Py_LOCAL(PyObject *) avl_tree_repr(avl_tree_Object * self)
{
PyObject *result = NULL;
avl_size_t len;
int rc;
len = avl_size(self->tree);
rc = Py_ReprEnter((PyObject *) self);
if (rc != 0)
return rc > 0 ? PyString_FromString("[...]") : NULL;
if (len == 0) {
result = PyString_FromString("[]");
goto finish;
}
{
avl_iterator iter;
PyObject *list, *ob;
Py_ssize_t i = 0;
iter = avl_iterator_new(self->tree, AVL_ITERATOR_INI_PRE);
if (iter == NULL)
goto finish;
list = PyList_New(len);
if (list == NULL)
goto finish;
do {
ob = objectAt(avl_iterator_next(iter));
Py_INCREF(ob);
PyList_SET_ITEM(list, i, ob);
++i;
} while (--len);
avl_iterator_kill(iter);
result = PyObject_Repr(list);
list->ob_type->tp_dealloc(list);
}
finish:
Py_ReprLeave((PyObject *) self);
return result;
}
示例7: PY_DEF
PY_DEF(pyketama_Continuum_get_points, self, args) {
PyObject *ret = NULL;
pyketama_Continuum *pkc = (pyketama_Continuum *)self;
if (pkc->cont->data->array) {
int i;
mcs (*mcsarr)[pkc->cont->data->numpoints] = &pkc->cont->data->array;
ret = PyList_New(pkc->cont->data->numpoints);
for (i = 0; i < pkc->cont->data->numpoints; i++) {
PyList_SET_ITEM(ret, i,
Py_BuildValue("Is", (*mcsarr)[i].point, (*mcsarr)[i].ip));
}
}
return ret;
}
示例8: hash
static PyObject * hash(PyObject * self, PyObject * args)
{
PyArrayObject * desc;
PyObject * out_list;
int cnt = 0;
// get reference to the numpy.ndarray that OpenCV stores the descriptor matrix in
if(!PyArg_ParseTuple(args, "O!", &PyArray_Type, &desc))
{
PyErr_SetString(lsh_error, "Invalid arguments.");
return NULL;
}
// get a pointer to the input matrix (must be contiguous!!!!!)
unsigned char * arr = (unsigned char *)PyArray_DATA(desc);
// get the dimensions of the input matrix
npy_intp * dims = PyArray_DIMS(desc);
// allocate output
out_list = PyList_New(dims[0] * NUMBER_OF_TABLES);
if(!out_list)
{
PyErr_SetString(lsh_error, "Failed to allocate list.");
return NULL;
}
// for each feature...
for(int i = 0; i < dims[0]; i++)
{
// for each table...
for(int tb = 0; tb < NUMBER_OF_TABLES; tb++)
{
// hash the feature
size_t key_raw = get_key(tb, arr);
// store in the output
PyObject * key = PyInt_FromSize_t(key_raw);
PyList_SET_ITEM(out_list, cnt, key);
cnt++;
}
// move to the next feature
arr += FEATURE_SIZE;
}
return out_list;
}
示例9: PyList_New
ULONG PyGMAPIAdviseSink::OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications )
{
PY_GATEWAY_METHOD;
PyObject *arg = PyList_New(cNotif);
if (!arg)
return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify");
ULONG i;
for (i=0;i<cNotif;i++) {
PyObject *sub = PyObject_FromNOTIFICATION(lpNotifications+i);
if (!sub) {
Py_DECREF(arg);
return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify");
}
PyList_SET_ITEM(arg, i, sub);
}
return InvokeViaPolicy("OnNotify", NULL, "(N)", arg);
}
示例10: callback_dualtree2
static void callback_dualtree2(void* v, int ind1, int ind2, double dist2) {
struct dualtree_results2* dt = v;
PyObject* lst;
if (dt->permute) {
ind1 = kdtree_permute(dt->kd1, ind1);
ind2 = kdtree_permute(dt->kd2, ind2);
}
lst = PyList_GET_ITEM(dt->indlist, ind1);
if (!lst) {
lst = PyList_New(1);
// SetItem steals a ref -- that's what we want.
PyList_SetItem(dt->indlist, ind1, lst);
PyList_SET_ITEM(lst, 0, PyInt_FromLong(ind2));
} else {
PyList_Append(lst, PyInt_FromLong(ind2));
}
}
示例11: launcharray2python
static PyObject*
launcharray2python(launch_data_t data)
{
size_t count = launch_data_array_get_count(data);
size_t i;
PyObject* result = PyList_New(count);
for (i = 0; i < 0; i ++) {
launch_data_t v = launch_data_array_get_index(data, i);
PyList_SET_ITEM(result, i, launch2python(data));
}
if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
return result;
}
示例12: Py_INCREF
// return Python list of values for this label. Return None if this label
// has no values (e.g. Atom labels), or NULL on error.
static PyObject *getvalues(GeometryMol *g) {
if (!g->has_value()) {
Py_INCREF(Py_None);
return Py_None;
}
ResizeArray<float> gValues(1024);
if (!g->calculate_all(gValues)) {
PyErr_SetString(PyExc_ValueError, (char *)"Invalid label");
return NULL;
}
const int n = gValues.num();
PyObject *newlist = PyList_New(n);
for (int i=0; i<n; i++) {
PyList_SET_ITEM(newlist, i, PyFloat_FromDouble(gValues[i]));
}
return newlist;
}
示例13: PyList_New
/**
* Creates a Python list from a Mantid vector
* @param values :: A reference to the MantidVec
* @returns A standard Python list object
*/
PyObject * MantidVecHelper::createPythonList(const MantidVec & values)
{
const Py_ssize_t nVals = static_cast<Py_ssize_t>(values.size());
PyObject * pyValues = PyList_New(nVals);
if( !pyValues )
{
throw std::runtime_error("Cannot create Python list from Mantid vector.");
}
MantidVec::const_iterator iend = values.end();
Py_ssize_t index(0);
for( MantidVec::const_iterator itr = values.begin(); itr != iend; ++itr )
{
PyList_SET_ITEM(pyValues, index, PyFloat_FromDouble((*itr)));
++index;
}
return pyValues;
}
示例14: psutil_get_cmdline
/*
* returns a Python list representing the arguments for the process
* with given pid or NULL on error.
*/
PyObject *
psutil_get_cmdline(long pid) {
PyObject *ret = NULL;
WCHAR *data = NULL;
SIZE_T size;
PyObject *py_retlist = NULL;
PyObject *py_unicode = NULL;
LPWSTR *szArglist = NULL;
int nArgs, i;
if (psutil_get_process_data(pid, KIND_CMDLINE, &data, &size) != 0)
goto out;
// attempt to parse the command line using Win32 API
szArglist = CommandLineToArgvW(data, &nArgs);
if (szArglist == NULL) {
PyErr_SetFromWindowsErr(0);
goto out;
}
// arglist parsed as array of UNICODE_STRING, so convert each to
// Python string object and add to arg list
py_retlist = PyList_New(nArgs);
if (py_retlist == NULL)
goto out;
for (i = 0; i < nArgs; i++) {
py_unicode = PyUnicode_FromWideChar(szArglist[i],
wcslen(szArglist[i]));
if (py_unicode == NULL)
goto out;
PyList_SET_ITEM(py_retlist, i, py_unicode);
py_unicode = NULL;
}
ret = py_retlist;
py_retlist = NULL;
out:
LocalFree(szArglist);
free(data);
Py_XDECREF(py_unicode);
Py_XDECREF(py_retlist);
return ret;
}
示例15: getEntities
PyObject* EntityGarbages<T>::pyValues()
{
ENTITYS_MAP& entities = getEntities();
PyObject* pyList = PyList_New(entities.size());
int i = 0;
ENTITYS_MAP::const_iterator iter = entities.begin();
while (iter != entities.end())
{
Py_INCREF(iter->second);
PyList_SET_ITEM(pyList, i, iter->second);
i++;
iter++;
}
return pyList;
}