App: fix memory leaks in Enumeration class and simplify code

This commit is contained in:
wmayer
2022-05-10 18:47:23 +02:00
committed by wwmayer
parent f13abb44a4
commit 2628fb0350
12 changed files with 329 additions and 340 deletions

View File

@@ -392,9 +392,9 @@ void PropertyEnumeration::setEnumVector(const std::vector<std::string> &values)
hasSetValue();
}
const char ** PropertyEnumeration::getEnums() const
bool PropertyEnumeration::hasEnums() const
{
return _enum.getEnums();
return _enum.hasEnums();
}
bool PropertyEnumeration::isValid() const
@@ -447,7 +447,7 @@ void PropertyEnumeration::Restore(Base::XMLReader &reader)
if (val < 0) {
// If the enum is empty at this stage do not print a warning
if (_enum.getEnums())
if (_enum.hasEnums())
Base::Console().Warning("Enumeration index %d is out of range, ignore it\n", val);
val = getValue();
}
@@ -598,13 +598,13 @@ bool PropertyEnumeration::getPyPathValue(const ObjectIdentifier &path, Py::Objec
if (p == ".Enum" || p == ".All") {
Base::PyGILStateLocker lock;
Py::Tuple res(_enum.maxValue()+1);
const char **enums = _enum.getEnums();
std::vector<std::string> enums = _enum.getEnumVector();
PropertyString tmp;
for(int i=0;i<=_enum.maxValue();++i) {
for(int i=0;i< int(enums.size());++i) {
tmp.setValue(enums[i]);
res.setItem(i,Py::asObject(tmp.getPyObject()));
}
if(p == ".Enum")
if (p == ".Enum")
r = res;
else {
Py::Tuple tuple(2);
@@ -1374,7 +1374,7 @@ PropertyString::~PropertyString()
void PropertyString::setValue(const char* newLabel)
{
if(!newLabel)
if(!newLabel)
return;
if(_cValue == newLabel)