diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 019aab6390..c0cac1d428 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -652,7 +652,7 @@ public: Document* Application::openDocument(const char * FileName, bool createView) { std::vector filenames(1,FileName); auto docs = openDocuments(filenames, nullptr, nullptr, nullptr, createView); - if(docs.size()) + if(!docs.empty()) return docs.front(); return nullptr; } @@ -663,7 +663,7 @@ Document *Application::getDocumentByPath(const char *path, PathMatchMode checkCa if(DocFileMap.empty()) { for(const auto &v : DocMap) { const auto &file = v.second->FileName.getStrValue(); - if(file.size()) + if(!file.empty()) DocFileMap[FileInfo(file.c_str()).filePath()] = v.second; } } @@ -977,7 +977,7 @@ Document* Application::openDocumentPrivate(const char * FileName, try { // read the document newDoc->restore(File.filePath().c_str(),true,objNames); - if(DocFileMap.size()) + if(!DocFileMap.empty()) DocFileMap[FileInfo(newDoc->FileName.getValue()).filePath()] = newDoc; return newDoc; } diff --git a/src/App/ColorModel.cpp b/src/App/ColorModel.cpp index d2647b7cf6..6af1a42ffd 100644 --- a/src/App/ColorModel.cpp +++ b/src/App/ColorModel.cpp @@ -451,7 +451,7 @@ bool ColorLegend::remove (std::size_t ulPos) void ColorLegend::removeFirst () { - if (colorFields.size() > 0) { + if (!colorFields.empty()) { colorFields.erase(colorFields.begin()); names.erase(names.begin()); values.erase(values.begin()); @@ -460,7 +460,7 @@ void ColorLegend::removeFirst () void ColorLegend::removeLast () { - if (colorFields.size() > 0) { + if (!colorFields.empty()) { colorFields.erase(colorFields.end()-1); names.erase(names.end()-1); values.erase(values.end()-1); diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 8602487eb5..7276901e45 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -957,7 +957,7 @@ bool Document::undo(int id) if(it == mUndoMap.end()) return false; if(it->second != d->activeUndoTransaction) { - while(mUndoTransactions.size() && mUndoTransactions.back()!=it->second) + while(!mUndoTransactions.empty() && mUndoTransactions.back()!=it->second) undo(0); } } @@ -1008,7 +1008,7 @@ bool Document::redo(int id) auto it = mRedoMap.find(id); if(it == mRedoMap.end()) return false; - while(mRedoTransactions.size() && mRedoTransactions.back()!=it->second) + while(!mRedoTransactions.empty() && mRedoTransactions.back()!=it->second) redo(0); } @@ -1999,7 +1999,7 @@ Document::readObjects(Base::XMLReader& reader) if(!reader.hasAttribute(FC_ATTR_DEPENDENCIES)) d->partialLoadObjects.clear(); - else if(d->partialLoadObjects.size()) { + else if(!d->partialLoadObjects.empty()) { std::unordered_map deps; for (int i=0 ;ipartialLoadObjects.size()) { + if(!d->partialLoadObjects.empty()) { auto it = d->partialLoadObjects.find(name); if(it == d->partialLoadObjects.end()) continue; @@ -2368,7 +2368,7 @@ private: if (file.substr(0,fn.length()) == fn) { // starts with the same file name std::string suf(file.substr(fn.length())); - if (suf.size() > 0) { + if (!suf.empty()) { std::string::size_type nPos = suf.find_first_not_of("0123456789"); if (nPos==std::string::npos) { // store all backup files @@ -2500,7 +2500,7 @@ private: fn = str.str(); bool done = false; - if ((fn == "") || (fn[fn.length()-1] == ' ') || (fn[fn.length()-1] == '-')) { + if ((fn.empty()) || (fn[fn.length()-1] == ' ') || (fn[fn.length()-1] == '-')) { if (fn[fn.length()-1] == ' ') { fn = fn.substr(0,fn.length()-1); } @@ -2817,7 +2817,7 @@ bool Document::afterRestore(bool checkPartial) { bool Document::afterRestore(const std::vector &objArray, bool checkPartial) { checkPartial = checkPartial && testStatus(Document::PartialDoc); - if(checkPartial && d->touchedObjs.size()) + if(checkPartial && !d->touchedObjs.empty()) return false; // some link type property cannot restore link information until other @@ -2840,7 +2840,7 @@ bool Document::afterRestore(const std::vector &objArray, bool } } - if(checkPartial && d->touchedObjs.size()) { + if(checkPartial && !d->touchedObjs.empty()) { // partial document touched, signal full reload return false; } @@ -2901,7 +2901,7 @@ bool Document::afterRestore(const std::vector &objArray, bool } } - if(checkPartial && d->touchedObjs.size()) { + if(checkPartial && !d->touchedObjs.empty()) { // partial document touched, signal full reload return false; } else if(!d->touchedObjs.count(obj)) @@ -3001,7 +3001,7 @@ void Document::getLinksTo(std::set &links, { std::map > linkMap; - for(auto o : objs.size()?objs:d->objectArray) { + for(auto o : !objs.empty()?objs:d->objectArray) { if(o == obj) continue; auto linked = o; if(options & GetLinkArrayElement) @@ -3035,7 +3035,7 @@ void Document::getLinksTo(std::set &links, return; std::vector current(1,obj); - for(int depth=0;current.size();++depth) { + for(int depth=0;!current.empty();++depth) { if(!GetApplication().checkLinkDepth(depth,true)) break; std::vector next; @@ -3105,7 +3105,7 @@ static void _buildDependencyList(const std::vector &object int op = (options & Document::DepNoXLinked)?DocumentObject::OutListNoXLinked:0; for (auto obj : objectArray) { objs.push_back(obj); - while(objs.size()) { + while(!objs.empty()) { auto obj = objs.front(); objs.pop_front(); if(!obj || !obj->getNameInDocument()) @@ -3241,7 +3241,7 @@ std::vector Document::getDependentDocuments( for(auto doc : pending) docMap[doc] = add_vertex(depList); } - while(pending.size()) { + while(!pending.empty()) { auto doc = pending.back(); pending.pop_back(); @@ -3592,7 +3592,7 @@ int Document::recompute(const std::vector &objs, bool forc FC_TIME_LOG(t,"Recompute total"); - if (d->_RecomputeLog.size()) { + if (!d->_RecomputeLog.empty()) { d->pendingRemove.clear(); if (!testStatus(Status::IgnoreErrorOnRecompute)) Base::Console().Error("Recompute failed! Please check report view.\n"); diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 90a7885120..960e7225f1 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -449,7 +449,7 @@ void DocumentObject::getInListEx(std::set &inSet, std::stack pendings; pendings.push(const_cast(this)); - while(pendings.size()) { + while(!pendings.empty()) { auto obj = pendings.top(); pendings.pop(); for(auto o : obj->getInList()) { diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index c93fc5cd76..e102333672 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -243,7 +243,7 @@ std::string DocumentObjectT::getPropertyPython() const { std::stringstream str; str << getObjectPython(); - if (property.size()) + if (!property.empty()) str << '.' << property; return str.str(); } @@ -422,7 +422,7 @@ std::string SubObjectT::getObjectFullName(const char *docName) const ss << "#"; } ss << getObjectName(); - if (getObjectLabel().size() && getObjectLabel() != getObjectName()) + if (!getObjectLabel().empty() && getObjectLabel() != getObjectName()) ss << " (" << getObjectLabel() << ")"; return ss.str(); } diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 76f365ea7e..e4c5f48598 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -1014,7 +1014,7 @@ ExpressionPtr Expression::importSubNames(const std::map continue; std::string imported = PropertyLinkBase::tryImportSubName( obj,key.second.c_str(),owner->getDocument(), nameMap); - if(imported.size()) + if(!imported.empty()) subNameMap.emplace(std::move(key),std::move(imported)); } } @@ -1112,7 +1112,7 @@ App::any Expression::getValueAsAny() const { Py::Object Expression::getPyValue() const { try { Py::Object pyobj = _getPyValue(); - if(components.size()) { + if(!components.empty()) { for(auto &c : components) pyobj = c->get(this,pyobj); } @@ -1772,7 +1772,7 @@ FunctionExpression::FunctionExpression(const DocumentObject *_owner, Function _f case MAX: case CREATE: case MSCALE: - if (args.size() == 0) + if (args.empty()) EXPR_THROW("Invalid number of arguments: at least one required."); break; case LIST: @@ -2531,7 +2531,7 @@ const Property * VariableExpression::getProperty() const void VariableExpression::addComponent(Component *c) { do { - if(components.size()) + if(!components.empty()) break; if(!c->e1 && !c->e2) { var << c->comp; diff --git a/src/App/FeaturePython.h b/src/App/FeaturePython.h index e341d34f4c..afe63ca667 100644 --- a/src/App/FeaturePython.h +++ b/src/App/FeaturePython.h @@ -200,7 +200,7 @@ public: } const char* getViewProviderNameOverride() const override { viewProviderName = imp->getViewProviderName(); - if(viewProviderName.size()) + if(!viewProviderName.empty()) return viewProviderName.c_str(); return FeatureT::getViewProviderNameOverride(); } diff --git a/src/App/GeoFeature.cpp b/src/App/GeoFeature.cpp index 4808e0a648..26b48f7a75 100644 --- a/src/App/GeoFeature.cpp +++ b/src/App/GeoFeature.cpp @@ -130,7 +130,7 @@ DocumentObject *GeoFeature::resolveElement(DocumentObject *obj, const char *subn else{ const auto &names = geo->getElementName(element,type); std::string prefix(subname,element-subname); - if(names.first.size()) + if(!names.first.empty()) elementName.first = prefix + names.first; elementName.second = prefix + names.second; } diff --git a/src/App/Link.cpp b/src/App/Link.cpp index b0ca3ecaae..270cc30b73 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -917,7 +917,7 @@ void LinkBaseExtension::monitorOnChangeCopyObjects( } App::GroupExtension *LinkBaseExtension::linkedPlainGroup() const { - if(mySubElements.size() && mySubElements[0].size()) + if(!mySubElements.empty() && !mySubElements[0].empty()) return nullptr; auto linked = getTrueLinkedObject(false); if(!linked) @@ -970,7 +970,7 @@ int LinkBaseExtension::_getElementCountValue() const { } bool LinkBaseExtension::extensionHasChildElement() const { - if(_getElementListValue().size() + if(!_getElementListValue().empty() || (_getElementCountValue() && _getShowElementValue())) return true; if (getLinkClaimChildValue()) @@ -1309,7 +1309,7 @@ bool LinkBaseExtension::extensionGetSubObject(DocumentObject *&ret, const char * int idx = getElementIndex(subname,&subname); if(idx>=0) { const auto &elements = _getElementListValue(); - if(elements.size()) { + if(!elements.empty()) { if(idx>=(int)elements.size() || !elements[idx] || !elements[idx]->getNameInDocument()) return true; ret = elements[idx]->getSubObject(subname,pyObj,mat,true,depth+1); @@ -1402,7 +1402,7 @@ bool LinkBaseExtension::extensionGetSubObject(DocumentObject *&ret, const char * *mat = matNext; } } - checkGeoElementMap(obj,linked,pyObj,postfix.size()?postfix.c_str():nullptr); + checkGeoElementMap(obj,linked,pyObj,!postfix.empty()?postfix.c_str():nullptr); return true; } @@ -1531,7 +1531,7 @@ void LinkBaseExtension::updateGroup() { } } std::vector children; - if(groups.size()) { + if(!groups.empty()) { children = getElementListValue(); std::set childSet(children.begin(),children.end()); for(auto ext : groups) { @@ -1909,7 +1909,7 @@ void LinkBaseExtension::syncElementList() { } } else if (element->LinkedObject.getValue() != link->getValue() - || element->LinkedObject.getSubValues().size()) { + || !element->LinkedObject.getSubValues().empty()) { element->setLink(-1, link->getValue()); } } @@ -2036,7 +2036,7 @@ void LinkBaseExtension::setLink(int index, DocumentObject *obj, int idx = -1; if(getLinkModeValue()>=LinkModeAutoLink || (subname && subname[0]) || - subElements.size() || + !subElements.empty() || obj->getDocument()!=parent->getDocument() || (getElementListProperty()->find(obj->getNameInDocument(),&idx) && idx!=index)) { @@ -2087,14 +2087,14 @@ void LinkBaseExtension::setLink(int index, DocumentObject *obj, } if(!xlink) { - if(subElements.size() || (subname && subname[0])) + if(!subElements.empty() || (subname && subname[0])) LINK_THROW(Base::RuntimeError,"SubName/SubElement link requires PropertyXLink"); linkProp->setValue(obj); return; } std::vector subs; - if(subElements.size()) { + if(!subElements.empty()) { subs.reserve(subElements.size()); for(const auto &s : subElements) { subs.emplace_back(subname?subname:""); diff --git a/src/App/Link.h b/src/App/Link.h index a9b3adc6b0..60757cc725 100644 --- a/src/App/Link.h +++ b/src/App/Link.h @@ -270,7 +270,7 @@ public: const char *getSubName() const { parseSubName(); - return mySubName.size()?mySubName.c_str():nullptr; + return !mySubName.empty()?mySubName.c_str():nullptr; } const std::vector &getSubElements() const { diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index dc2dc26ab3..9c551a1052 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -122,11 +122,11 @@ ObjectIdentifier::ObjectIdentifier(const App::PropertyContainer * _owner, FC_THROWM(Base::RuntimeError,"Property must be owned by a document object."); owner = const_cast(docObj); - if (property.size() > 0) { + if (!property.empty()) { setDocumentObjectName(docObj); } } - if (property.size() > 0) { + if (!property.empty()) { addComponent(SimpleComponent(property)); if(index!=INT_MAX) addComponent(ArrayComponent(index)); @@ -331,7 +331,7 @@ bool ObjectIdentifier::verify(const App::Property &prop, bool silent) const { const std::string &ObjectIdentifier::toString() const { - if(_cache.size() || !owner) + if(!_cache.empty() || !owner) return _cache; std::ostringstream s; @@ -348,21 +348,21 @@ const std::string &ObjectIdentifier::toString() const result.propertyIndex==0)) { s << '.'; - }else if (documentNameSet && documentName.getString().size()) { - if(documentObjectNameSet && documentObjectName.getString().size()) + }else if (documentNameSet && !documentName.getString().empty()) { + if(documentObjectNameSet && !documentObjectName.getString().empty()) s << documentName.toString() << "#" << documentObjectName.toString() << '.'; - else if(result.resolvedDocumentObjectName.getString().size()) + else if(!result.resolvedDocumentObjectName.getString().empty()) s << documentName.toString() << "#" << result.resolvedDocumentObjectName.toString() << '.'; - } else if (documentObjectNameSet && documentObjectName.getString().size()) { + } else if (documentObjectNameSet && !documentObjectName.getString().empty()) { s << documentObjectName.toString() << '.'; } else if (result.propertyIndex > 0) { components[0].toString(s); s << '.'; } - if(subObjectName.getString().size()) + if(!subObjectName.getString().empty()) s << subObjectName.toString() << '.'; s << components[result.propertyIndex].getName(); @@ -398,21 +398,21 @@ std::string ObjectIdentifier::toPersistentString() const { if(documentObjectName.isRealString()) s << '@'; s << '.'; - } else if (documentNameSet && documentName.getString().size()) { - if(documentObjectNameSet && documentObjectName.getString().size()) + } else if (documentNameSet && !documentName.getString().empty()) { + if(documentObjectNameSet && !documentObjectName.getString().empty()) s << documentName.toString() << "#" << documentObjectName.toString() << '.'; - else if(result.resolvedDocumentObjectName.getString().size()) + else if(!result.resolvedDocumentObjectName.getString().empty()) s << documentName.toString() << "#" << result.resolvedDocumentObjectName.toString() << '.'; - } else if (documentObjectNameSet && documentObjectName.getString().size()) { + } else if (documentObjectNameSet && !documentObjectName.getString().empty()) { s << documentObjectName.toString() << '.'; } else if (result.propertyIndex > 0) { components[0].toString(s); s << '.'; } - if(subObjectName.getString().size()) { + if(!subObjectName.getString().empty()) { const char *subname = subObjectName.getString().c_str(); std::string exportName; s << String(PropertyLinkBase::exportSubName(exportName, @@ -426,7 +426,7 @@ std::string ObjectIdentifier::toPersistentString() const { std::size_t ObjectIdentifier::hash() const { - if(_hash && _cache.size()) + if(_hash && !_cache.empty()) return _hash; const_cast(this)->_hash = boost::hash_value(toString()); return _hash; @@ -484,10 +484,10 @@ bool ObjectIdentifier::updateLabelReference( ResolveResults result(*this); - if(subObjectName.getString().size() && result.resolvedDocumentObject) { + if(!subObjectName.getString().empty() && result.resolvedDocumentObject) { std::string sub = PropertyLinkBase::updateLabelReference( result.resolvedDocumentObject, subObjectName.getString().c_str(), obj,ref,newLabel); - if(sub.size()) { + if(!sub.empty()) { subObjectName = String(sub,true); _cache.clear(); return true; @@ -497,7 +497,7 @@ bool ObjectIdentifier::updateLabelReference( if(result.resolvedDocument != obj->getDocument()) return false; - if(documentObjectName.getString().size()) { + if(!documentObjectName.getString().empty()) { if(documentObjectName.isForceIdentifier()) return false; @@ -899,7 +899,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const bool docAmbiguous = false; /* Document name specified? */ - if (documentName.getString().size() > 0) { + if (!documentName.getString().empty()) { results.resolvedDocument = getDocument(documentName,&docAmbiguous); results.resolvedDocumentName = documentName; } @@ -914,7 +914,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const // Assume document name and object name from owner if not found if (!results.resolvedDocument) { - if (documentName.getString().size() > 0) { + if (!documentName.getString().empty()) { if(docAmbiguous) results.flags.set(ResolveAmbiguous); return; @@ -928,14 +928,14 @@ void ObjectIdentifier::resolve(ResolveResults &results) const results.resolvedDocumentName = String(results.resolvedDocument->getName(), false, true); /* Document object name specified? */ - if (documentObjectName.getString().size() > 0) { + if (!documentObjectName.getString().empty()) { results.resolvedDocumentObjectName = documentObjectName; results.resolvedDocumentObject = getDocumentObject( results.resolvedDocument, documentObjectName, results.flags); if (!results.resolvedDocumentObject) return; - if (components.size() > 0) { + if (!components.empty()) { results.propertyName = components[0].name.getString(); results.propertyIndex = 0; results.getProperty(*this); @@ -1012,7 +1012,7 @@ void ObjectIdentifier::resolve(ResolveResults &results) const Document * ObjectIdentifier::getDocument(String name, bool *ambiguous) const { - if (name.getString().size() == 0) + if (name.getString().empty()) name = getDocumentName(); App::Document * docById = nullptr; @@ -1098,12 +1098,12 @@ void ObjectIdentifier::getDepLabels(std::vector &labels) const { void ObjectIdentifier::getDepLabels( const ResolveResults &result, std::vector &labels) const { - if(documentObjectName.getString().size()) { + if(!documentObjectName.getString().empty()) { if(documentObjectName.isRealString()) labels.push_back(documentObjectName.getString()); } else if(result.propertyIndex == 1) labels.push_back(components[0].name.getString()); - if(subObjectName.getString().size()) + if(!subObjectName.getString().empty()) PropertyLinkBase::getLabelReferences(labels,subObjectName.getString().c_str()); } @@ -1130,7 +1130,7 @@ void ObjectIdentifier::getDep(Dependencies &deps, bool needProps, std::vector ObjectIdentifier::getStringList() const if (documentObjectNameSet) l.push_back(documentObjectName.toString()); } - if(subObjectName.getString().size()) { + if(!subObjectName.getString().empty()) { l.back() += subObjectName.toString(); } std::vector::const_iterator i = components.begin(); @@ -1266,7 +1266,7 @@ Property *ObjectIdentifier::getProperty(int *ptype) const Property *ObjectIdentifier::resolveProperty(const App::DocumentObject *obj, const char *propertyName, App::DocumentObject *&sobj, int &ptype) const { - if(obj && subObjectName.getString().size()) { + if(obj && !subObjectName.getString().empty()) { sobj = obj->getSubObject(subObjectName); obj = sobj; } @@ -1295,7 +1295,7 @@ Property *ObjectIdentifier::resolveProperty(const App::DocumentObject *obj, else { ptype = it->second; if(ptype != PseudoShape && - subObjectName.getString().size() && + !subObjectName.getString().empty() && !boost::ends_with(subObjectName.getString(),".")) { return nullptr; @@ -1358,7 +1358,7 @@ void ObjectIdentifier::setDocumentName(ObjectIdentifier::String &&name, bool for force = false; documentNameSet = force; _cache.clear(); - if(name.getString().size() && _DocumentMap) { + if(!name.getString().empty() && _DocumentMap) { if(name.isRealString()) { auto iter = _DocumentMap->find(name.toString()); if(iter!=_DocumentMap->end()) { @@ -1481,7 +1481,7 @@ std::string ObjectIdentifier::String::toString(bool toPython) const void ObjectIdentifier::String::checkImport(const App::DocumentObject *owner, const App::DocumentObject *obj, String *objName) { - if(owner && owner->getDocument() && str.size() && + if(owner && owner->getDocument() && !str.empty() && ExpressionParser::ExpressionImporter::reader()) { auto reader = ExpressionParser::ExpressionImporter::reader(); if (obj || objName) { @@ -1524,7 +1524,7 @@ Py::Object ObjectIdentifier::access(const ResolveResults &result, Py::Object *value, Dependencies *deps) const { if(!result.resolvedDocumentObject || !result.resolvedProperty || - (subObjectName.getString().size() && !result.resolvedSubObject)) + (!subObjectName.getString().empty() && !result.resolvedSubObject)) { FC_THROWM(Base::RuntimeError, result.resolveErrorString() << " in '" << toString() << "'"); @@ -1685,7 +1685,7 @@ Py::Object ObjectIdentifier::access(const ResolveResults &result, auto &propset = (*deps)[obj]; // inserting a blank name in the propset indicates the dependency is // on all properties of the corresponding object. - if (propset.size() != 1 || propset.begin()->size()) { + if (propset.size() != 1 || !propset.begin()->->empty()) { if (!propName) { propset.clear(); propset.insert(""); @@ -1831,9 +1831,9 @@ void ObjectIdentifier::setValue(const App::any &value) const } const std::string &ObjectIdentifier::getSubObjectName(bool newStyle) const { - if(newStyle && shadowSub.first.size()) + if(newStyle && !shadowSub.first.empty()) return shadowSub.first; - if(shadowSub.second.size()) + if(!shadowSub.second.empty()) return shadowSub.second; return subObjectName.getString(); } @@ -1927,7 +1927,7 @@ bool ObjectIdentifier::isTouched() const { void ObjectIdentifier::resolveAmbiguity() { if(!owner || !owner->getNameInDocument() || isLocalProperty() || - (documentObjectNameSet && documentObjectName.getString().size() && + (documentObjectNameSet && !documentObjectName.getString().empty() && (documentObjectName.isRealString() || documentObjectName.isForceIdentifier()))) { return; @@ -1993,12 +1993,12 @@ std::string ObjectIdentifier::ResolveResults::resolveErrorString() const else ss << "Document object '" << resolvedDocumentObjectName.toString() << "' not found"; - } else if (subObjectName.getString().size() && !resolvedSubObject) { + } else if (!subObjectName.getString().empty() && !resolvedSubObject) { ss << "Sub-object '" << resolvedDocumentObjectName.getString() << '.' << subObjectName.toString() << "' not found"; } else if (!resolvedProperty) { if(propertyType != PseudoShape && - subObjectName.getString().size() && + !subObjectName.getString().empty() && !boost::ends_with(subObjectName.getString(),".")) { ss << "Non geometry subname reference must end with '.'"; diff --git a/src/App/Property.cpp b/src/App/Property.cpp index aa3ba1a047..4ea7f844f6 100644 --- a/src/App/Property.cpp +++ b/src/App/Property.cpp @@ -171,7 +171,7 @@ struct PropertyCleaner { if(--_PropCleanerCounter) return; bool found = false; - while (_RemovedProps.size()) { + while (!_RemovedProps.empty()) { auto p = _RemovedProps.back(); _RemovedProps.pop_back(); if(p != prop) diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index d13c8c6b62..9fe2d3bfdc 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -180,7 +180,7 @@ void PropertyExpressionEngine::hasSetValue() std::string key = objName + propName; auto &propDeps = pimpl->propMap[key]; if(propDeps.empty()) { - if(propName.size()) + if(!propName.empty()) pimpl->conns.emplace_back(obj->signalChanged.connect(boost::bind( &PropertyExpressionEngine::slotChangedProperty,this,_1,_2))); else @@ -482,7 +482,7 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, std::shar if (expr) { std::string error = validateExpression(usePath, expr); - if (error.size() > 0) + if (!error.empty()) throw Base::RuntimeError(error.c_str()); AtomicPropertyChange signaller(*this); expressions[usePath] = ExpressionInfo(expr); @@ -766,7 +766,7 @@ std::string PropertyExpressionEngine::validateExpression(const ObjectIdentifier if (validator) { error = validator(usePath, expr); - if (error.size() > 0) + if (!error.empty()) return error; } diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 789bd51f69..699017518f 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -489,7 +489,7 @@ void PropertyLink::Restore(Base::XMLReader &reader) // Property not in a DocumentObject! assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId()) ); - if (name != "") { + if (!name.empty()) { DocumentObject* parent = static_cast(getContainer()); App::Document* document = parent->getDocument(); @@ -973,9 +973,9 @@ static inline const std::string &getSubNameWithStyle(const std::string &subName, const PropertyLinkBase::ShadowSub &shadow, bool newStyle) { if(!newStyle) { - if(shadow.second.size()) + if(!shadow.second.empty()) return shadow.second; - }else if(shadow.first.size()) + }else if(!shadow.first.empty()) return shadow.first; return subName; } @@ -1101,7 +1101,7 @@ static bool updateLinkReference(App::PropertyLinkBase *prop, if(!touched) return false; for(int idx : mapped) { - if(idx<(int)subs.size() && shadows[idx].first.size()) + if(idx<(int)subs.size() && !shadows[idx].first.empty()) subs[idx] = shadows[idx].first; } mapped.clear(); @@ -1318,16 +1318,16 @@ void PropertyLinkSub::Save (Base::Writer &writer) const if(exporting) { std::string exportName; writer.Stream() << encodeAttribute(exportSubName(exportName,_pcLinkSub,sub.c_str())); - if(shadow.second.size() && shadow.first == _cSubList[i]) + if(!shadow.second.empty() && shadow.first == _cSubList[i]) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; } else { writer.Stream() << encodeAttribute(sub); - if(_cSubList[i].size()) { + if(!_cSubList[i].empty()) { if(sub!=_cSubList[i]) { // Stores the actual value that is shadowed. For new version FC, // we will restore this shadowed value instead. writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_cSubList[i]); - }else if(shadow.first.size()){ + }else if(!shadow.first.empty()){ // Here means the user set value is old style element name. // We shall then store the shadow somewhere else. writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first); @@ -1412,7 +1412,7 @@ std::vector updateLinkSubs(const App::DocumentObject *obj, res.insert(res.end(),subs.begin(),it); } res.push_back(std::move(new_sub)); - }else if(res.size()) + }else if(!res.empty()) res.push_back(sub); } return res; @@ -1867,7 +1867,7 @@ const string PropertyLinkSubList::getPyReprString() const { assert(this->_lValueList.size() == this->_lSubList.size()); - if (this->_lValueList.size() == 0) + if (this->_lValueList.empty()) return std::string("None"); std::stringstream strm; @@ -1955,13 +1955,13 @@ std::vector PropertyLinkSubList::getSubListValues(b for (std::size_t i = 0; i < _lValueList.size(); i++) { App::DocumentObject* link = _lValueList[i]; std::string sub; - if(newStyle && _ShadowSubList[i].first.size()) + if(newStyle && !_ShadowSubList[i].first.empty()) sub = _ShadowSubList[i].first; - else if(!newStyle && _ShadowSubList[i].second.size()) + else if(!newStyle && !_ShadowSubList[i].second.empty()) sub = _ShadowSubList[i].second; else sub = _lSubList[i]; - if (values.size() == 0 || values.back().first != link){ + if (values.empty() || values.back().first != link){ //new object started, start a new subset. values.emplace_back(link, std::vector()); } @@ -2100,7 +2100,7 @@ void PropertyLinkSubList::updateElementReference(DocumentObject *feature, bool r mapped.reserve(_mapped.size()); for(int idx : _mapped) { if(idx<(int)_lSubList.size()) { - if(_ShadowSubList[idx].first.size()) + if(!_ShadowSubList[idx].first.empty()) _lSubList[idx] = _ShadowSubList[idx].first; else mapped.push_back(idx); @@ -2144,16 +2144,16 @@ void PropertyLinkSubList::Save (Base::Writer &writer) const if(exporting) { std::string exportName; writer.Stream() << encodeAttribute(exportSubName(exportName,obj,sub.c_str())); - if(shadow.second.size() && _lSubList[i]==shadow.first) + if(!shadow.second.empty() && _lSubList[i]==shadow.first) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; } else { writer.Stream() << encodeAttribute(sub); - if(_lSubList[i].size()) { + if(!_lSubList[i].empty()) { if(sub!=_lSubList[i]) { // Stores the actual value that is shadowed. For new version FC, // we will restore this shadowed value instead. writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_lSubList[i]); - }else if(shadow.first.size()) { + }else if(!shadow.first.empty()) { // Here means the user set value is old style element name. // We shall then store the shadow somewhere else. writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first); @@ -2263,7 +2263,7 @@ Property *PropertyLinkSubList::CopyOnImportExternal( auto value = *itValue; const auto &sub = *itSub; if(!value || !value->getNameInDocument()) { - if(values.size()) { + if(!values.empty()) { values.push_back(value); subs.push_back(sub); } @@ -2271,7 +2271,7 @@ Property *PropertyLinkSubList::CopyOnImportExternal( } auto linked = tryImport(owner->getDocument(),value,nameMap); auto new_sub = tryImportSubName(value,sub.c_str(),owner->getDocument(),nameMap); - if(linked!=value || new_sub.size()) { + if(linked!=value || !new_sub.empty()) { if(values.empty()) { values.reserve(_lValueList.size()); values.insert(values.end(),_lValueList.begin(),itValue); @@ -2280,7 +2280,7 @@ Property *PropertyLinkSubList::CopyOnImportExternal( } values.push_back(linked); subs.push_back(std::move(new_sub)); - }else if(values.size()) { + }else if(!values.empty()) { values.push_back(linked); subs.push_back(sub); } @@ -2306,14 +2306,14 @@ Property *PropertyLinkSubList::CopyOnLabelChange(App::DocumentObject *obj, auto value = *itValue; const auto &sub = *itSub; if(!value || !value->getNameInDocument()) { - if(values.size()) { + if(!values.empty()) { values.push_back(value); subs.push_back(sub); } continue; } auto new_sub = updateLabelReference(value,sub.c_str(),obj,ref,newLabel); - if(new_sub.size()) { + if(!new_sub.empty()) { if(values.empty()) { values.reserve(_lValueList.size()); values.insert(values.end(),_lValueList.begin(),itValue); @@ -2322,7 +2322,7 @@ Property *PropertyLinkSubList::CopyOnLabelChange(App::DocumentObject *obj, } values.push_back(value); subs.push_back(std::move(new_sub)); - }else if(values.size()) { + }else if(!values.empty()) { values.push_back(value); subs.push_back(sub); } @@ -2346,7 +2346,7 @@ Property *PropertyLinkSubList::CopyOnLinkReplace(const App::DocumentObject *pare auto value = *itValue; const auto &sub = *itSub; if(!value || !value->getNameInDocument()) { - if(values.size()) { + if(!values.empty()) { values.push_back(value); subs.push_back(sub); } @@ -2376,7 +2376,7 @@ Property *PropertyLinkSubList::CopyOnLinkReplace(const App::DocumentObject *pare } values.push_back(res.first); subs.push_back(std::move(res.second)); - }else if(values.size()) { + }else if(!values.empty()) { bool duplicate = false; if(value == newObj) { for(auto pos : positions) { @@ -3111,7 +3111,7 @@ void PropertyXLink::setValue(std::string &&filename, std::string &&name, DocumentObject *pObject=nullptr; DocInfoPtr info; - if(filename.size()) { + if(!filename.empty()) { owner->getDocument()->signalLinkXsetValue(filename); info = DocInfo::get(filename.c_str(),owner->getDocument(),this,name.c_str()); if(info->pcDoc) @@ -3175,13 +3175,13 @@ bool PropertyXLink::upgrade(Base::XMLReader &reader, const char *typeName) { int PropertyXLink::checkRestore(std::string *msg) const { if(!docInfo) { - if(!_pcLink && objectName.size()) { + if(!_pcLink && !objectName.empty()) { // this condition means linked object not found if(msg) { std::ostringstream ss; ss << "Link not restored" << std::endl; ss << "Object: " << objectName; - if(filePath.size()) + if(!filePath.empty()) ss << std::endl << "File: " << filePath; *msg = ss.str(); } @@ -3202,7 +3202,7 @@ int PropertyXLink::checkRestore(std::string *msg) const { ss << "Linked object: " << objectName; if(docInfo->pcDoc) ss << std::endl << "Linked document: " << docInfo->pcDoc->Label.getValue(); - else if(filePath.size()) + else if(!filePath.empty()) ss << std::endl << "Linked file: " << filePath; *msg = ss.str(); } @@ -3272,14 +3272,14 @@ void PropertyXLink::Save (Base::Writer &writer) const { auto pDoc = owner->getDocument(); const char *docPath = pDoc->getFileName(); if(docPath && docPath[0]) { - if(filePath.size()) + if(!filePath.empty()) _path = DocInfo::getDocPath(filePath.c_str(),pDoc,false); else _path = docPath; }else FC_WARN("PropertyXLink export without saving the document"); } - if(_path.size()) + if(!_path.empty()) path = _path.c_str(); } writer.Stream() << writer.ind() @@ -3301,14 +3301,14 @@ void PropertyXLink::Save (Base::Writer &writer) const { std::string exportName; writer.Stream() << "\" sub=\"" << encodeAttribute(exportSubName(exportName,_pcLink,sub.c_str())); - if(shadowSub.second.size() && shadowSub.first==subName) + if(!shadowSub.second.empty() && shadowSub.first==subName) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; }else{ writer.Stream() << "\" sub=\"" << encodeAttribute(sub); - if(sub.size()) { + if(!sub.empty()) { if(sub!=subName) writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(subName); - else if(shadowSub.first.size()) + else if(!shadowSub.first.empty()) writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadowSub.first); } } @@ -3326,14 +3326,14 @@ void PropertyXLink::Save (Base::Writer &writer) const { if(exporting) { std::string exportName; writer.Stream() << encodeAttribute(exportSubName(exportName,_pcLink,sub.c_str())); - if(shadow.second.size() && shadow.first == _SubList[i]) + if(!shadow.second.empty() && shadow.first == _SubList[i]) writer.Stream() << "\" " ATTR_MAPPED "=\"1"; } else { writer.Stream() << encodeAttribute(sub); - if(_SubList[i].size()) { + if(!_SubList[i].empty()) { if(sub!=_SubList[i]) writer.Stream() << "\" " ATTR_SHADOWED "=\"" << encodeAttribute(_SubList[i]); - else if(shadow.first.size()) + else if(!shadow.first.empty()) writer.Stream() << "\" " ATTR_SHADOW "=\"" << encodeAttribute(shadow.first); } } @@ -3364,7 +3364,7 @@ void PropertyXLink::Restore(Base::XMLReader &reader) assert(getContainer()->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())); DocumentObject *object = nullptr; - if(name.size() && file.empty()) { + if(!name.empty() && file.empty()) { DocumentObject* parent = static_cast(getContainer()); Document *document = parent->getDocument(); object = document ? document->getObject(name.c_str()) : nullptr; @@ -3422,7 +3422,7 @@ void PropertyXLink::Restore(Base::XMLReader &reader) return; } - if(file.size() || (!object && name.size())) { + if(!file.empty() || (!object && !name.empty())) { this->stamp = stampAttr; setValue(std::move(file),std::move(name),std::move(subs),std::move(shadows)); }else @@ -3509,7 +3509,7 @@ void PropertyXLink::Paste(const Property &from) throw Base::TypeError("Incompatible property to paste to"); const auto &other = static_cast(from); - if(other.docName.size()) { + if(!other.docName.empty()) { auto doc = GetApplication().getDocument(other.docName.c_str()); if(!doc) { FC_WARN("Document '" << other.docName << "' not found"); @@ -3731,11 +3731,11 @@ void PropertyXLink::setAllowPartial(bool enable) { return; if(!App::GetApplication().isRestoring() && !owner->getDocument()->isPerformingTransaction() && - !_pcLink && docInfo && filePath.size() && objectName.size() && + !_pcLink && docInfo && !filePath.empty() && !objectName.empty() && (!docInfo->pcDoc || docInfo->pcDoc->testStatus(Document::PartialDoc))) { auto path = docInfo->getDocPath(filePath.c_str(),owner->getDocument(),false); - if(path.size()) + if(!path.empty()) App::GetApplication().openDocument(path.c_str()); } } @@ -4000,7 +4000,7 @@ const string PropertyXLinkSubList::getPyReprString() const DocumentObject *PropertyXLinkSubList::getValue() const { - if(_Links.size()) + if(!_Links.empty()) return _Links.begin()->getValue(); return nullptr; } @@ -4523,7 +4523,7 @@ void PropertyXLinkContainer::afterRestore() { auto obj = info.xlink->getValue(); if(!obj) continue; - if(info.docName.size()) { + if(!info.docName.empty()) { if(info.docName != obj->getDocument()->getName()) _DocMap[info.docName] = obj->getDocument()->getName(); if(info.docLabel != obj->getDocument()->Label.getValue()) @@ -4598,7 +4598,7 @@ void PropertyXLinkContainer::Save (Base::Writer &writer) const { docSet.insert(std::make_pair(obj->getDocument(),i)); } - if(docSet.size()) + if(!docSet.empty()) writer.Stream() << "\" docs=\"" << docSet.size(); } diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 1d56d2d130..7c18f4bad3 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1407,7 +1407,7 @@ void PropertyString::setValue(const char* newLabel) propChanges = PropertyLinkBase::updateLabelReferences(obj,newLabel); } - if(propChanges.size() && !GetApplication().getActiveTransaction()) { + if(!propChanges.empty() && !GetApplication().getActiveTransaction()) { commit = true; std::ostringstream str; str << "Change " << obj->getNameInDocument() << ".Label"; diff --git a/src/App/Transactions.cpp b/src/App/Transactions.cpp index dc07e9ea05..4ab3334b56 100644 --- a/src/App/Transactions.cpp +++ b/src/App/Transactions.cpp @@ -182,7 +182,7 @@ void Transaction::apply(Document &Doc, bool forward) }catch(...) { errMsg = "Unknown exception"; } - if(errMsg.size()) { + if(!errMsg.empty()) { FC_ERR("Exception on " << (forward?"redo":"undo") << " '" << Name << "':" << errMsg); } @@ -310,7 +310,7 @@ void TransactionObject::applyChn(Document & /*Doc*/, TransactionalObject *pcObj, // been destroies. We must prepare for the case where user removed // a dynamic property but does not recordered as transaction. auto name = pcObj->getPropertyName(prop); - if(!name || (data.name.size() && data.name != name) || data.propertyType != prop->getTypeId()) { + if(!name || (!data.name.empty() && data.name != name) || data.propertyType != prop->getTypeId()) { // Here means the original property is not found, probably removed if(data.name.empty()) { // not a dynamic property, nothing to do @@ -380,7 +380,7 @@ void TransactionObject::addOrRemoveProperty(const Property* pcProp, bool add) return; auto &data = _PropChangeMap[pcProp->getID()]; - if(data.name.size()) { + if(!data.name.empty()) { if(!add && !data.property) { // this means add and remove the same property inside a single // transaction, so they cancel each other out.