[App] remove superfluous nullptr checks

This commit is contained in:
Uwe
2022-07-18 03:12:01 +02:00
parent b801e7151a
commit e69a920f18
12 changed files with 55 additions and 54 deletions

View File

@@ -808,7 +808,7 @@ PyObject *DocumentPy::getCustomAttributes(const char* attr) const
App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr);
if (prop)
return nullptr;
if (this->ob_type->tp_dict == nullptr) {
if (!this->ob_type->tp_dict) {
if (PyType_Ready(this->ob_type) < 0)
return nullptr;
}
@@ -830,7 +830,7 @@ int DocumentPy::setCustomAttributes(const char* attr, PyObject *)
App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr);
if (prop)
return 0;
if (this->ob_type->tp_dict == nullptr) {
if (!this->ob_type->tp_dict) {
if (PyType_Ready(this->ob_type) < 0)
return 0;
}

View File

@@ -274,7 +274,7 @@ bool Enumeration::operator==(const Enumeration &other) const
for (size_t i = 0; i < enumArray.size(); ++i) {
if (enumArray[i]->data() == other.enumArray[i]->data())
continue;
if (enumArray[i]->data() == nullptr || other.enumArray[i]->data() == nullptr)
if (!enumArray[i]->data() || !other.enumArray[i]->data())
return false;
if (!enumArray[i]->isEqual(other.enumArray[i]->data()))
return false;
@@ -284,7 +284,7 @@ bool Enumeration::operator==(const Enumeration &other) const
bool Enumeration::operator==(const char *other) const
{
if (getCStr() == nullptr) {
if (!getCStr()) {
return false;
}

View File

@@ -1976,11 +1976,11 @@ Py::Object FunctionExpression::evalAggregate(
if (!p)
continue;
if ((qp = freecad_dynamic_cast<PropertyQuantity>(p)) != nullptr)
if ((qp = freecad_dynamic_cast<PropertyQuantity>(p)))
c->collect(qp->getQuantityValue());
else if ((fp = freecad_dynamic_cast<PropertyFloat>(p)) != nullptr)
else if ((fp = freecad_dynamic_cast<PropertyFloat>(p)))
c->collect(Quantity(fp->getValue()));
else if ((ip = freecad_dynamic_cast<PropertyInteger>(p)) != nullptr)
else if ((ip = freecad_dynamic_cast<PropertyInteger>(p)))
c->collect(Quantity(ip->getValue()));
else
_EXPR_THROW("Invalid property type for aggregate.", owner);
@@ -2858,7 +2858,7 @@ Expression *ConditionalExpression::simplify() const
std::unique_ptr<Expression> e(condition->simplify());
NumberExpression * v = freecad_dynamic_cast<NumberExpression>(e.get());
if (v == nullptr)
if (!v)
return new ConditionalExpression(owner, condition->simplify(), trueExpr->simplify(), falseExpr->simplify());
else {
if (fabs(v->getValue()) > 0.5)
@@ -3327,7 +3327,7 @@ Expression * App::ExpressionParser::parse(const App::DocumentObject *owner, cons
if (result != 0)
throw ParserError("Failed to parse expression.");
if (ScanResult == nullptr)
if (!ScanResult)
throw ParserError("Unknown error in expression");
if (valueExpression)
@@ -3355,7 +3355,7 @@ UnitExpression * ExpressionParser::parseUnit(const App::DocumentObject *owner, c
if (result != 0)
throw ParserError("Failed to parse expression.");
if (ScanResult == nullptr)
if (!ScanResult)
throw ParserError("Unknown error in expression");
// Simplify expression

View File

@@ -204,12 +204,12 @@ short int ExtensionContainer::getPropertyType(const char* name) const {
const char* ExtensionContainer::getPropertyName(const Property* prop) const {
const char* res = App::PropertyContainer::getPropertyName(prop);
if(res != nullptr)
if (res)
return res;
for(const auto& entry : _extensions) {
for (const auto& entry : _extensions) {
res = entry.second->extensionGetPropertyName(prop);
if(res != nullptr)
if (res)
return res;
}
@@ -219,12 +219,12 @@ const char* ExtensionContainer::getPropertyName(const Property* prop) const {
const char* ExtensionContainer::getPropertyGroup(const Property* prop) const {
const char* res = App::PropertyContainer::getPropertyGroup(prop);
if(res != nullptr)
if (res)
return res;
for(const auto& entry : _extensions) {
for (const auto& entry : _extensions) {
res = entry.second->extensionGetPropertyGroup(prop);
if(res != nullptr)
if (res)
return res;
}
@@ -234,12 +234,12 @@ const char* ExtensionContainer::getPropertyGroup(const Property* prop) const {
const char* ExtensionContainer::getPropertyGroup(const char* name) const {
const char* res = App::PropertyContainer::getPropertyGroup(name);
if(res != nullptr)
if (res)
return res;
for(const auto& entry : _extensions) {
for (const auto& entry : _extensions) {
res = entry.second->extensionGetPropertyGroup(name);
if(res != nullptr)
if (res)
return res;
}
@@ -250,12 +250,12 @@ const char* ExtensionContainer::getPropertyGroup(const char* name) const {
const char* ExtensionContainer::getPropertyDocumentation(const Property* prop) const {
const char* res = App::PropertyContainer::getPropertyDocumentation(prop);
if(res != nullptr)
if (res)
return res;
for(const auto& entry : _extensions) {
for (const auto& entry : _extensions) {
res = entry.second->extensionGetPropertyDocumentation(prop);
if(res != nullptr)
if (res)
return res;
}
@@ -265,12 +265,12 @@ const char* ExtensionContainer::getPropertyDocumentation(const Property* prop) c
const char* ExtensionContainer::getPropertyDocumentation(const char* name) const {
const char* res = App::PropertyContainer::getPropertyDocumentation(name);
if(res != nullptr)
if (res)
return res;
for(const auto& entry : _extensions) {
res = entry.second->extensionGetPropertyDocumentation(name);
if(res != nullptr)
if (res)
return res;
}

View File

@@ -43,7 +43,7 @@ std::string ExtensionContainerPy::representation(void) const
int ExtensionContainerPy::initialization() {
if (this->ob_type->tp_dict == nullptr) {
if (!this->ob_type->tp_dict) {
if (PyType_Ready(this->ob_type) < 0)
return 0;
}
@@ -61,7 +61,7 @@ int ExtensionContainerPy::initialization() {
// make sure to do the initialization only once
if (meth->ml_name) {
PyObject* item = PyDict_GetItemString(dict, meth->ml_name);
if (item == nullptr) {
if (!item) {
// Note: this adds the methods to the type object to make sure
// it appears in the call tips. The function will not be bound
// to an instance
@@ -69,7 +69,7 @@ int ExtensionContainerPy::initialization() {
while (meth->ml_name) {
PyObject *func;
func = PyCFunction_New(meth, 0);
if (func == nullptr)
if (!func)
break;
if (PyDict_SetItemString(dict, meth->ml_name, func) < 0)
break;
@@ -238,7 +238,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
// make sure to do the initialization only once
if (meth->ml_name) {
PyObject* item = PyDict_GetItemString(dict, meth->ml_name);
if (item == nullptr) {
if (!item) {
// Note: this adds the methods to the type object to make sure
// it appears in the call tips. The function will not be bound
// to an instance
@@ -246,7 +246,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
while (meth->ml_name) {
PyObject *func;
func = PyCFunction_New(meth, 0);
if (func == nullptr)
if (!func)
break;
if (PyDict_SetItemString(dict, meth->ml_name, func) < 0)
break;

View File

@@ -129,14 +129,14 @@ bool FeaturePythonImp::mustExecute() const
void FeaturePythonImp::onBeforeChange(const Property* prop)
{
if(py_onBeforeChange.isNone())
if (py_onBeforeChange.isNone())
return;
// Run the execute method of the proxy object.
Base::PyGILStateLocker lock;
try {
const char *prop_name = object->getPropertyName(prop);
if(prop_name == nullptr)
if (!prop_name)
return;
if (has__object__) {
Py::Tuple args(1);
@@ -184,13 +184,13 @@ bool FeaturePythonImp::onBeforeChangeLabel(std::string &newLabel)
void FeaturePythonImp::onChanged(const Property* prop)
{
if(py_onChanged.isNone())
if (py_onChanged.isNone())
return;
// Run the execute method of the proxy object.
Base::PyGILStateLocker lock;
try {
const char *prop_name = object->getPropertyName(prop);
if(prop_name == nullptr)
if (!prop_name)
return;
if (has__object__) {
Py::Tuple args(1);

View File

@@ -168,7 +168,7 @@ PyObject *FeaturePythonPyT<FeaturePyT>::_getattr(const char *attr)
// Return the default dict
PyTypeObject *tp = this->ob_type;
// register type if needed
if (tp->tp_dict == nullptr) {
if (!tp->tp_dict) {
if (PyType_Ready(tp) < 0)
return nullptr;
}

View File

@@ -855,7 +855,7 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document *
for (std::vector<DocumentObject*>::iterator j = docObjects.begin(); j != docObjects.end(); ++j) {
if (strcmp((*j)->Label.getValue(), static_cast<const char*>(name)) == 0) {
// Found object with matching label
if (objectByLabel != nullptr) {
if (objectByLabel) {
FC_WARN("duplicate object label " << doc->getName() << '#' << name);
return nullptr;
}
@@ -863,13 +863,13 @@ App::DocumentObject * ObjectIdentifier::getDocumentObject(const App::Document *
}
}
if (objectByLabel == nullptr && objectById == nullptr) // Not found at all
if (!objectByLabel && !objectById) // Not found at all
return nullptr;
else if (objectByLabel == nullptr) { // Found by name
else if (!objectByLabel) { // Found by name
flags.set(ResolveByIdentifier);
return objectById;
}
else if (objectById == nullptr) { // Found by label
else if (!objectById) { // Found by label
flags.set(ResolveByLabel);
return objectByLabel;
}
@@ -913,7 +913,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const
results.propertyIndex = 0;
// Assume document name and object name from owner if not found
if (results.resolvedDocument == nullptr) {
if (!results.resolvedDocument) {
if (documentName.getString().size() > 0) {
if(docAmbiguous)
results.flags.set(ResolveAmbiguous);
@@ -921,7 +921,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const
}
results.resolvedDocument = owner->getDocument();
if (results.resolvedDocument == nullptr)
if (!results.resolvedDocument)
return;
}
@@ -1029,7 +1029,7 @@ Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const
for (std::vector<App::Document*>::const_iterator i = docs.begin(); i != docs.end(); ++i) {
if ((*i)->Label.getValue() == name.getString()) {
/* Multiple hits for same label? */
if (docByLabel != nullptr) {
if (docByLabel) {
if(ambiguous) *ambiguous = true;
return nullptr;
}
@@ -1038,17 +1038,18 @@ Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const
}
/* Not found on id? */
if (docById == nullptr)
if (!docById)
return docByLabel; // Either not found at all, or on label
else {
/* Not found on label? */
if (docByLabel == nullptr) /* Then return doc by id */
if (!docByLabel) /* Then return doc by id */
return docById;
/* docByLabel and docById could be equal; that is ok */
if(docByLabel==docById)
if (docByLabel == docById)
return docById;
if(ambiguous) *ambiguous = true;
if (ambiguous)
*ambiguous = true;
return nullptr;
}
}
@@ -1979,23 +1980,23 @@ ObjectIdentifier::ResolveResults::ResolveResults(const ObjectIdentifier &oi)
std::string ObjectIdentifier::ResolveResults::resolveErrorString() const
{
std::ostringstream ss;
if (resolvedDocument == nullptr) {
if (!resolvedDocument) {
if(flags.test(ResolveAmbiguous))
ss << "Ambiguous document name/label '"
<< resolvedDocumentName.getString() << "'";
else
ss << "Document '" << resolvedDocumentName.toString() << "' not found";
} else if (resolvedDocumentObject == nullptr) {
} else if (!resolvedDocumentObject) {
if(flags.test(ResolveAmbiguous))
ss << "Ambiguous document object name '"
<< resolvedDocumentObjectName.getString() << "'";
else
ss << "Document object '" << resolvedDocumentObjectName.toString()
<< "' not found";
} else if (subObjectName.getString().size() && resolvedSubObject == nullptr) {
} else if (subObjectName.getString().size() && !resolvedSubObject) {
ss << "Sub-object '" << resolvedDocumentObjectName.getString()
<< '.' << subObjectName.toString() << "' not found";
} else if (resolvedProperty == nullptr) {
} else if (!resolvedProperty) {
if(propertyType != PseudoShape &&
subObjectName.getString().size() &&
!boost::ends_with(subObjectName.getString(),"."))

View File

@@ -724,7 +724,7 @@ void PropertyExpressionEngine::getPathsToDocumentObject(DocumentObject* obj,
{
DocumentObject * owner = freecad_dynamic_cast<DocumentObject>(getContainer());
if (owner == nullptr || owner==obj)
if (!owner || owner==obj)
return;
for(auto &v : expressions) {

View File

@@ -1721,7 +1721,7 @@ void PropertyLinkSubList::setValues(const std::vector<DocumentObject*>& lValue,c
_lSubList.resize(lSubNames.size());
int i = 0;
for (std::vector<const char*>::const_iterator it = lSubNames.begin();it!=lSubNames.end();++it,++i) {
if (*it != nullptr)
if (*it)
_lSubList[i] = *it;
}
updateElementReference(nullptr);
@@ -1923,7 +1923,7 @@ DocumentObject *PropertyLinkSubList::getValue() const
App::DocumentObject* ret = nullptr;
//FIXME: cache this to avoid iterating each time, to improve speed
for (std::size_t i = 0; i < this->_lValueList.size(); i++) {
if (ret == nullptr)
if (!ret)
ret = this->_lValueList[i];
if (ret != this->_lValueList[i])
return nullptr;

View File

@@ -44,7 +44,7 @@ Range::Range(const char * range, bool normalize)
assert(range != nullptr);
if (strchr(range, ':') == nullptr) {
if (!strchr(range, ':')) {
from = range;
to = range;
}

View File

@@ -488,7 +488,7 @@ App::TransactionFactory* App::TransactionFactory::self = nullptr;
TransactionFactory& TransactionFactory::instance()
{
if (self == nullptr)
if (!self)
self = new TransactionFactory;
return *self;
}