[TD]Simplify Cosmetic List & PyObject handling

This commit is contained in:
wandererfan
2020-05-11 15:30:29 -04:00
committed by WandererFan
parent 303bf40f09
commit eaf2f0e8a4
13 changed files with 92 additions and 88 deletions

View File

@@ -63,14 +63,12 @@ PropertyCosmeticEdgeList::PropertyCosmeticEdgeList()
PropertyCosmeticEdgeList::~PropertyCosmeticEdgeList()
{
for (std::vector<CosmeticEdge*>::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it)
if (*it) delete *it;
}
void PropertyCosmeticEdgeList::setSize(int newSize)
{
for (unsigned int i = newSize; i < _lValueList.size(); i++)
delete _lValueList[i];
// for (unsigned int i = newSize; i < _lValueList.size(); i++)
// delete _lValueList[i];
_lValueList.resize(newSize);
}
@@ -79,15 +77,14 @@ int PropertyCosmeticEdgeList::getSize(void) const
return static_cast<int>(_lValueList.size());
}
void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue)
//_lValueList is not const. so why do we pass a const paramter?
void PropertyCosmeticEdgeList::setValue(CosmeticEdge* lValue)
{
if (lValue) {
aboutToSetValue();
CosmeticEdge* newVal = lValue->clone();
for (unsigned int i = 0; i < _lValueList.size(); i++)
delete _lValueList[i];
_lValueList.resize(1);
_lValueList[0] = newVal;
_lValueList[0] = lValue;
hasSetValue();
}
}
@@ -95,13 +92,9 @@ void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue)
void PropertyCosmeticEdgeList::setValues(const std::vector<CosmeticEdge*>& lValue)
{
aboutToSetValue();
std::vector<CosmeticEdge*> oldVals(_lValueList);
_lValueList.resize(lValue.size());
// copy all objects
for (unsigned int i = 0; i < lValue.size(); i++)
_lValueList[i] = lValue[i]->clone();
for (unsigned int i = 0; i < oldVals.size(); i++)
delete oldVals[i];
_lValueList[i] = lValue[i];
hasSetValue();
}
@@ -115,8 +108,6 @@ PyObject *PropertyCosmeticEdgeList::getPyObject(void)
void PropertyCosmeticEdgeList::setPyObject(PyObject *value)
{
// check container of this property to notify about changes
if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
std::vector<CosmeticEdge*> values;