本文整理汇总了C++中Sequence::getValues方法的典型用法代码示例。如果您正苦于以下问题:C++ Sequence::getValues方法的具体用法?C++ Sequence::getValues怎么用?C++ Sequence::getValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequence
的用法示例。
在下文中一共展示了Sequence::getValues方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: seq_ass_item
//-------------------------------------------------------------------------------------
int Sequence::seq_ass_item(PyObject* self, Py_ssize_t index, PyObject* value)
{
Sequence* seq = static_cast<Sequence*>(self);
std::vector<PyObject*>& values = seq->getValues();
if (uint32(index) >= values.size())
{
PyErr_SetString(PyExc_IndexError, "Sequence assignment index out of range");
PyErr_PrintEx(0);
return -1;
}
if(value)
{
// 检查类别是否正确
if(seq->isSameItemType(value))
{
values[index] = seq->createNewItemFromObj(value);
}
else
{
PyErr_SetString(PyExc_IndexError, "Sequence set to type is error!");
PyErr_PrintEx(0);
return -1;
}
}
else
{
values.erase(values.begin() + index);
}
return 0;
}
示例2: seq_slice
//-------------------------------------------------------------------------------------
PyObject* Sequence::seq_slice(PyObject* self, Py_ssize_t startIndex, Py_ssize_t endIndex)
{
if (startIndex < 0)
startIndex = 0;
Sequence* seq = static_cast<Sequence*>(self);
std::vector<PyObject*>& values = seq->getValues();
if (endIndex > int(values.size()))
endIndex = values.size();
if (endIndex < startIndex)
endIndex = startIndex;
int length = endIndex - startIndex;
if (length == int(values.size()))
{
Py_INCREF(seq);
return seq;
}
PyObject* pyRet = PyList_New(length);
for (int i = startIndex; i < endIndex; ++i)
{
Py_INCREF(values[i]);
PyList_SET_ITEM(pyRet, i - startIndex, values[i]);
}
return pyRet;
}
示例3: seq_inplace_concat
//-------------------------------------------------------------------------------------
PyObject* Sequence::seq_inplace_concat(PyObject* self, PyObject* oterSeq)
{
if (!PySequence_Check(oterSeq))
{
PyErr_SetString(PyExc_TypeError, "Sequence:Argument to += must be a sequence");
PyErr_PrintEx(0);
return NULL;
}
Sequence* seq = static_cast<Sequence*>(self);
std::vector<PyObject*>& values = seq->getValues();
int szA = values.size();
int szB = PySequence_Size(oterSeq);
if (szB == 0)
{
Py_INCREF(seq);
return seq;
}
// 检查类型是否正确
for (int i = 0; i < szB; ++i)
{
PyObject * pyVal = PySequence_GetItem(oterSeq, i);
bool ok = seq->isSameItemType(pyVal);
Py_DECREF(pyVal);
if (!ok)
{
PyErr_Format(PyExc_TypeError, "Array elements must be set to type %s (appending with +=)", "sss");
PyErr_PrintEx(0);
return NULL;
}
}
// 先让vector分配好内存
values.insert(values.end(), szB, (PyObject*)NULL);
for (int i = 0; i < szB; ++i)
{
PyObject* pyTemp = PySequence_GetItem(oterSeq, i);
if(pyTemp == NULL){
PyErr_Format(PyExc_TypeError, "Sequence::seq_inplace_concat::PySequence_GetItem %d is NULL.", i);
PyErr_PrintEx(0);
}
values[szA + i] = pyTemp;
}
return seq;
}
示例4: seq_inplace_repeat
//-------------------------------------------------------------------------------------
PyObject* Sequence::seq_inplace_repeat(PyObject* self, Py_ssize_t n)
{
Sequence* seq = static_cast<Sequence*>(self);
if(n == 1)
{
Py_INCREF(seq);
return seq;
}
std::vector<PyObject*>& values = seq->getValues();
int sz = values.size();
if (n <= 0)
{
for(size_t j = 0; j < values.size(); ++j)
{
Py_DECREF(values[j]);
}
values.clear();
}
else
{
values.insert(values.end(), (n - 1)*sz, (PyObject*)NULL);
for(int i = 1; i < n; ++i)
{
for(int j = 0; j < sz; ++j)
{
Py_INCREF(&*values[j]);
values[i * sz + j] = &*values[j];
}
}
}
return seq;
}
示例5: seq_ass_slice
//-------------------------------------------------------------------------------------
int Sequence::seq_ass_slice(PyObject* self, Py_ssize_t index1, Py_ssize_t index2, PyObject* oterSeq)
{
Sequence* seq = static_cast<Sequence*>(self);
std::vector<PyObject*>& values = seq->getValues();
// 是否是删除元素
if (!oterSeq)
{
if (index1 < index2)
values.erase(values.begin() + index1, values.begin() + index2);
return 0;
}
// oterSeq必须是一个 sequence
if (!PySequence_Check(oterSeq))
{
PyErr_Format(PyExc_TypeError, "Sequence slices can only be assigned to a sequence");
PyErr_PrintEx(0);
return -1;
}
if (oterSeq == seq)
{
PyErr_Format(PyExc_TypeError, "Sequence does not support assignment of itself to a slice of itself");
PyErr_PrintEx(0);
return -1;
}
int sz = values.size();
int osz = PySequence_Size(oterSeq);
// 保证index不会越界
if (index1 > sz) index1 = sz;
if (index1 < 0) index1 = 0;
if (index2 > sz) index2 = sz;
if (index2 < 0) index2 = 0;
// 检查一下 看看有无错误类别
for (int i = 0; i < osz; ++i)
{
PyObject* pyVal = PySequence_GetItem(oterSeq, i);
bool ok = seq->isSameItemType(pyVal);
Py_DECREF(pyVal);
if (!ok)
{
PyErr_Format(PyExc_TypeError, "Array elements must be set to type %s (setting slice %d-%d)", "ss", index1, index2);
PyErr_PrintEx(0);
return -1;
}
}
if (index1 < index2)
values.erase(values.begin() + index1, values.begin() + index2);
// 先让vector分配好内存
values.insert(values.begin() + index1, osz, (PyObject*)NULL);
for(int i = 0; i < osz; ++i)
{
PyObject* pyTemp = PySequence_GetItem(oterSeq, i);
if(pyTemp == NULL)
{
PyErr_Format(PyExc_TypeError, "Sequence::seq_ass_slice::PySequence_GetItem %d is NULL.", i);
PyErr_PrintEx(0);
}
values[index1 + i] = seq->createNewItemFromObj(pyTemp);
Py_DECREF(pyTemp);
}
return 0;
}