App: modernize C++: return braced init list

This commit is contained in:
wmayer
2023-08-18 00:36:24 +02:00
committed by wwmayer
parent 2bc90e6090
commit 89bdd489b0
34 changed files with 70 additions and 74 deletions
+2 -2
View File
@@ -593,7 +593,7 @@ std::vector<App::Document*> Application::getDocuments() const
std::string Application::getUniqueDocumentName(const char *Name, bool tempDoc) const
{
if (!Name || *Name == '\0')
return std::string();
return {};
std::string CleanName = Base::Tools::getIdentifier(Name);
// name in use?
@@ -3160,7 +3160,7 @@ std::tuple<QString, QString, QString> getCustomPaths()
userTemp = fi.absoluteFilePath();
}
return std::tuple<QString, QString, QString>(userHome, userData, userTemp);
return {userHome, userData, userTemp};
}
/*!
+1 -1
View File
@@ -43,7 +43,7 @@ using namespace Base;
// returns a string which represent the object e.g. when printed in python
std::string ComplexGeoDataPy::representation() const
{
return std::string("<ComplexGeoData object>");
return {"<ComplexGeoData object>"};
}
PyObject* ComplexGeoDataPy::getElementTypes(PyObject *args)
+1 -1
View File
@@ -3799,7 +3799,7 @@ const char * Document::getObjectName(DocumentObject *pFeat) const
std::string Document::getUniqueObjectName(const char *Name) const
{
if (!Name || *Name == '\0')
return std::string();
return {};
std::string CleanName = Base::Tools::getIdentifier(Name);
// name in use?
+1 -1
View File
@@ -312,7 +312,7 @@ int DocumentObject::isExporting() const {
std::string DocumentObject::getExportName(bool forced) const {
if(!pcNameInDocument)
return std::string();
return {};
if(!forced && !isExporting())
return *pcNameInDocument;
+1 -1
View File
@@ -32,7 +32,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string DocumentObjectExtensionPy::representation() const
{
return std::string("<document object extension>");
return {"<document object extension>"};
}
PyObject *DocumentObjectExtensionPy::getCustomAttributes(const char* /*attr*/) const
+1 -1
View File
@@ -34,7 +34,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string DocumentObjectGroupPy::representation() const
{
return std::string("<group object>");
return {"<group object>"};
}
PyObject *DocumentObjectGroupPy::getCustomAttributes(const char* /*attr*/) const
+6 -6
View File
@@ -55,12 +55,12 @@ Py::String DocumentObjectPy::getName() const
if (!internal) {
throw Py::RuntimeError(std::string("This object is currently not part of a document"));
}
return Py::String(std::string(internal));
return {std::string(internal)};
}
Py::String DocumentObjectPy::getFullName() const
{
return Py::String(getDocumentObjectPtr()->getFullName());
return {getDocumentObjectPtr()->getFullName()};
}
Py::Object DocumentObjectPy::getDocument() const
@@ -694,7 +694,7 @@ PyObject* DocumentObjectPy::getParent(PyObject *args)
Py::Boolean DocumentObjectPy::getMustExecute() const
{
try {
return Py::Boolean(getDocumentObjectPtr()->mustExecute()?true:false);
return {getDocumentObjectPtr()->mustExecute() ? true : false};
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -741,7 +741,7 @@ Py::Int DocumentObjectPy::getID() const {
}
Py::Boolean DocumentObjectPy::getRemoving() const {
return Py::Boolean(getDocumentObjectPtr()->testStatus(ObjectStatus::Remove));
return {getDocumentObjectPtr()->testStatus(ObjectStatus::Remove)};
}
PyObject *DocumentObjectPy::resolve(PyObject *args)
@@ -813,11 +813,11 @@ PyObject *DocumentObjectPy::adjustRelativeLinks(PyObject *args) {
}
Py::String DocumentObjectPy::getOldLabel() const {
return Py::String(getDocumentObjectPtr()->getOldLabel());
return {getDocumentObjectPtr()->getOldLabel()};
}
Py::Boolean DocumentObjectPy::getNoTouch() const {
return Py::Boolean(getDocumentObjectPtr()->testStatus(ObjectStatus::NoTouch));
return {getDocumentObjectPtr()->testStatus(ObjectStatus::NoTouch)};
}
void DocumentObjectPy::setNoTouch(Py::Boolean value) {
+2 -2
View File
@@ -364,7 +364,7 @@ std::string SubObjectT::getNewElementName() const {
std::pair<std::string, std::string> element;
auto obj = getObject();
if(!obj)
return std::string();
return {};
GeoFeature::resolveElement(obj,subname.c_str(),element);
return std::move(element.first);
}
@@ -373,7 +373,7 @@ std::string SubObjectT::getOldElementName(int *index) const {
std::pair<std::string, std::string> element;
auto obj = getObject();
if(!obj)
return std::string();
return {};
GeoFeature::resolveElement(obj,subname.c_str(),element);
if(!index)
return std::move(element.second);
+11 -11
View File
@@ -472,7 +472,7 @@ PyObject* DocumentPy::commitTransaction(PyObject * args)
}
Py::Boolean DocumentPy::getHasPendingTransaction() const {
return Py::Boolean(getDocumentPtr()->hasPendingTransaction());
return {getDocumentPtr()->hasPendingTransaction()};
}
PyObject* DocumentPy::undo(PyObject * args)
@@ -780,17 +780,17 @@ Py::String DocumentPy::getDependencyGraph() const
{
std::stringstream out;
getDocumentPtr()->exportGraphviz(out);
return Py::String(out.str());
return {out.str()};
}
Py::String DocumentPy::getName() const
{
return Py::String(getDocumentPtr()->getName());
return {getDocumentPtr()->getName()};
}
Py::Boolean DocumentPy::getRecomputesFrozen() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::Status::SkipRecompute));
return {getDocumentPtr()->testStatus(Document::Status::SkipRecompute)};
}
void DocumentPy::setRecomputesFrozen(Py::Boolean arg)
@@ -942,35 +942,35 @@ PyObject *DocumentPy::getDependentDocuments(PyObject *args) {
Py::Boolean DocumentPy::getRestoring() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::Status::Restoring));
return {getDocumentPtr()->testStatus(Document::Status::Restoring)};
}
Py::Boolean DocumentPy::getPartial() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::Status::PartialDoc));
return {getDocumentPtr()->testStatus(Document::Status::PartialDoc)};
}
Py::Boolean DocumentPy::getImporting() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::Status::Importing));
return {getDocumentPtr()->testStatus(Document::Status::Importing)};
}
Py::Boolean DocumentPy::getRecomputing() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::Status::Recomputing));
return {getDocumentPtr()->testStatus(Document::Status::Recomputing)};
}
Py::Boolean DocumentPy::getTransacting() const
{
return Py::Boolean(getDocumentPtr()->isPerformingTransaction());
return {getDocumentPtr()->isPerformingTransaction()};
}
Py::String DocumentPy::getOldLabel() const
{
return Py::String(getDocumentPtr()->getOldLabel());
return {getDocumentPtr()->getOldLabel()};
}
Py::Boolean DocumentPy::getTemporary() const
{
return Py::Boolean(getDocumentPtr()->testStatus(Document::TempDoc));
return {getDocumentPtr()->testStatus(Document::TempDoc)};
}
+1 -1
View File
@@ -328,7 +328,7 @@ DynamicProperty::PropData DynamicProperty::getDynamicPropertyData(const Property
auto it = index.find(const_cast<Property*>(prop));
if(it != index.end())
return *it;
return PropData();
return {};
}
bool DynamicProperty::changeDynamicProperty(const Property *prop, const char *group, const char *doc) {
+2 -2
View File
@@ -848,12 +848,12 @@ IndexedName ElementMap::find(const MappedName& name, ElementIDRefs* sids) const
MappedName ElementMap::find(const IndexedName& idx, ElementIDRefs* sids) const
{
if (!idx) {
return MappedName();
return {};
}
auto iter = this->indexedNames.find(idx.getType());
if (iter == this->indexedNames.end()) {
return MappedName();
return {};
}
auto& indices = iter->second;
+3 -3
View File
@@ -12,7 +12,7 @@ const char *Data::isMappedElement(const char *name) {
std::string Data::newElementName(const char *name) {
if(!name)
return std::string();
return {};
const char *dot = strrchr(name,'.');
if(!dot || dot==name)
return name;
@@ -30,7 +30,7 @@ std::string Data::newElementName(const char *name) {
std::string Data::oldElementName(const char *name) {
if(!name)
return std::string();
return {};
const char *dot = strrchr(name,'.');
if(!dot || dot==name)
return name;
@@ -48,7 +48,7 @@ std::string Data::oldElementName(const char *name) {
std::string Data::noElementName(const char *name) {
if(!name)
return std::string();
return {};
auto element = findElementName(name);
if(element)
return std::string(name,element-name);
+5 -5
View File
@@ -449,12 +449,12 @@ Py::Object pyObjectFromAny(const App::any &value) {
App::any pyObjectToAny(Py::Object value, bool check) {
if(value.isNone())
return App::any();
return {};
PyObject *pyvalue = value.ptr();
if(!check)
return App::any(pyObjectWrap(pyvalue));
return {pyObjectWrap(pyvalue)};
if (PyObject_TypeCheck(pyvalue, &Base::QuantityPy::Type)) {
Base::QuantityPy * qp = static_cast<Base::QuantityPy*>(pyvalue);
@@ -1048,7 +1048,7 @@ ExpressionPtr Expression::updateLabelReference(
App::DocumentObject *obj, const std::string &ref, const char *newLabel) const
{
if(ref.size()<=2)
return ExpressionPtr();
return {};
std::vector<std::string> labels;
for(auto &v : getIdentifiers())
v.first.getDepLabels(labels);
@@ -1061,7 +1061,7 @@ ExpressionPtr Expression::updateLabelReference(
return ExpressionPtr(expr);
}
}
return ExpressionPtr();
return {};
}
class ReplaceObjectExpressionVisitor : public ExpressionVisitor {
@@ -1097,7 +1097,7 @@ ExpressionPtr Expression::replaceObject(const DocumentObject *parent,
const_cast<Expression*>(this)->visit(v);
if(v.paths.empty())
return ExpressionPtr();
return {};
// Now make a copy and do the actual replacement
auto expr = copy();
+2 -2
View File
@@ -67,7 +67,7 @@ QString ExpressionTokenizer::perform(const QString& prefix, int pos)
// No tokens
if (tokens.empty()) {
return QString();
return {};
}
prefixEnd = prefix.size();
@@ -114,7 +114,7 @@ QString ExpressionTokenizer::perform(const QString& prefix, int pos)
if (!stringing && !prefix.isEmpty() &&
prefixEnd > 0 && prefixEnd <= prefix.size() &&
prefix[prefixEnd-1] == QChar(32)) {
return QString();
return {};
}
if (!stringing) {
+1 -4
View File
@@ -115,12 +115,9 @@ std::string Extension::name() const {
if (pos != std::string::npos)
return temp.substr(pos+1);
else
return std::string();
return {};
}
Property* Extension::extensionGetPropertyByName(const char* name) const {
return extensionGetPropertyData().getPropertyByName(this, name);
+1 -1
View File
@@ -38,7 +38,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string ExtensionContainerPy::representation() const
{
return std::string("<extension>");
return {"<extension>"};
}
int ExtensionContainerPy::initialization() {
+1 -1
View File
@@ -34,7 +34,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string ExtensionPy::representation() const
{
return std::string("<extension>");
return {"<extension>"};
}
PyObject *ExtensionPy::getCustomAttributes(const char* /*attr*/) const
+1 -1
View File
@@ -480,7 +480,7 @@ std::string FeaturePythonImp::getViewProviderName()
e.ReportException();
}
return std::string();
return {};
}
FeaturePythonImp::ValueT
+3 -3
View File
@@ -235,7 +235,7 @@ void GeoFeatureGroupExtension::extensionOnChanged(const Property* p) {
std::vector< DocumentObject* > GeoFeatureGroupExtension::getScopedObjectsFromLinks(const DocumentObject* obj, LinkScope scope) {
if(!obj)
return std::vector< DocumentObject* >();
return {};
//we get all linked objects. We can't use outList() as this includes the links from expressions
std::vector< App::DocumentObject* > result;
@@ -256,7 +256,7 @@ std::vector< DocumentObject* > GeoFeatureGroupExtension::getScopedObjectsFromLin
std::vector< DocumentObject* > GeoFeatureGroupExtension::getScopedObjectsFromLink(App::Property* prop, LinkScope scope) {
if(!prop)
return std::vector< DocumentObject* >();
return {};
std::vector< App::DocumentObject* > result;
auto link = Base::freecad_dynamic_cast<PropertyLinkBase>(prop);
@@ -321,7 +321,7 @@ void GeoFeatureGroupExtension::getCSInList(const DocumentObject* obj,
std::vector< DocumentObject* > GeoFeatureGroupExtension::getCSRelevantLinks(const DocumentObject* obj) {
if(!obj)
return std::vector< DocumentObject* >();
return {};
//get all out links
std::vector<DocumentObject*> vec;
+1 -2
View File
@@ -33,10 +33,9 @@ using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string GeoFeatureGroupExtensionPy::representation() const
{
return std::string("<GeoFeatureGroup object>");
return {"<GeoFeatureGroup object>"};
}
PyObject *GeoFeatureGroupExtensionPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
+1 -1
View File
@@ -34,7 +34,7 @@ using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string GeoFeaturePy::representation() const
{
return std::string("<GeoFeature object>");
return {"<GeoFeature object>"};
}
PyObject* GeoFeaturePy::getPaths(PyObject * /*args*/)
+1 -1
View File
@@ -132,7 +132,7 @@ void Document::exportGraphviz(std::ostream& out) const
std::string getId(const ObjectIdentifier & path) {
DocumentObject * docObj = path.getDocumentObject();
if (!docObj)
return std::string();
return {};
return std::string((docObj)->getDocument()->getName()) + "#" + docObj->getNameInDocument() + "." + path.getPropertyName() + path.getSubPathStr();
}
+1 -1
View File
@@ -36,7 +36,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string GroupExtensionPy::representation() const
{
return std::string("<group extension object>");
return {"<group extension object>"};
}
PyObject* GroupExtensionPy::newObject(PyObject *args)
+1 -1
View File
@@ -80,7 +80,7 @@ int MaterialPy::PyInit(PyObject* args, PyObject* kwds)
// returns a string which represents the object e.g. when printed in python
std::string MaterialPy::representation() const
{
return std::string("<Material object>");
return {"<Material object>"};
}
PyObject* MaterialPy::set(PyObject * args)
+3 -3
View File
@@ -374,13 +374,13 @@ const std::string &ObjectIdentifier::toString() const
std::string ObjectIdentifier::toPersistentString() const {
if(!owner)
return std::string();
return {};
std::ostringstream s;
ResolveResults result(*this);
if(result.propertyIndex >= (int)components.size())
return std::string();
return {};
if(localProperty ||
(result.resolvedProperty &&
@@ -1776,7 +1776,7 @@ App::any ObjectIdentifier::getValue(bool pathValue, bool *isPseudoProperty) cons
}catch(Py::Exception &) {
Base::PyException::ThrowException();
}
return App::any();
return {};
}
Py::Object ObjectIdentifier::getPyValue(bool pathValue, bool *isPseudoProperty) const
+1 -1
View File
@@ -32,7 +32,7 @@ using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string OriginGroupExtensionPy::representation() const
{
return std::string("<OriginGroup object>");
return {"<OriginGroup object>"};
}
PyObject *OriginGroupExtensionPy::getCustomAttributes(const char* /*attr*/) const
+1 -1
View File
@@ -32,7 +32,7 @@ using namespace App;
// returns a string which represents the object e.g. when printed in python
std::string PartPy::representation() const
{
return std::string("<Part object>");
return {"<Part object>"};
}
PyObject *PartPy::getCustomAttributes(const char* /*attr*/) const
+1 -1
View File
@@ -158,7 +158,7 @@ public:
unsigned int getMemSize () const override;
virtual std::string getFullName() const {return std::string();}
virtual std::string getFullName() const {return {};}
/// find a property by its name
virtual Property *getPropertyByName(const char* name) const;
+1 -1
View File
@@ -45,7 +45,7 @@ using namespace App;
// returns a string which represent the object e.g. when printed in python
std::string PropertyContainerPy::representation() const
{
return std::string("<property container>");
return {"<property container>"};
}
PyObject* PropertyContainerPy::getPropertyByName(PyObject *args)
+1 -1
View File
@@ -811,7 +811,7 @@ std::string PropertyExpressionEngine::validateExpression(const ObjectIdentifier
return e.what();
}
return std::string();
return {};
}
/**
+1 -1
View File
@@ -102,7 +102,7 @@ public:
bool getPyPathValue(const ObjectIdentifier &path, Py::Object &res) const override;
virtual Base::Unit getUnit() const {
return Base::Unit();
return {};
}
bool isSame(const Property &other) const override {
+6 -6
View File
@@ -147,7 +147,7 @@ std::string PropertyLinkBase::updateLabelReference(const App::DocumentObject *pa
const char *subname, App::DocumentObject *obj, const std::string &ref, const char *newLabel)
{
if(!obj || !obj->getNameInDocument() || !parent || !parent->getNameInDocument())
return std::string();
return {};
// Because the label is allowed to be the same across different
// hierarchies, we have to search for all occurrences, and make sure the
@@ -162,7 +162,7 @@ std::string PropertyLinkBase::updateLabelReference(const App::DocumentObject *pa
return sub;
}
}
return std::string();
return {};
}
std::vector<std::pair<Property*, std::unique_ptr<Property> > >
@@ -192,7 +192,7 @@ PropertyLinkBase::updateLabelReferences(App::DocumentObject *obj, const char *ne
static std::string propertyName(const Property *prop) {
if(!prop)
return std::string();
return {};
if(!prop->getContainer() || !prop->hasName()) {
auto xlink = Base::freecad_dynamic_cast<const PropertyXLink>(prop);
if(xlink)
@@ -1238,7 +1238,7 @@ std::string PropertyLinkBase::tryImportSubName(const App::DocumentObject *obj, c
const App::Document *doc, const std::map<std::string,std::string> &nameMap)
{
if(!doc || !obj || !obj->getNameInDocument())
return std::string();
return {};
std::ostringstream ss;
std::string subname(_subname);
@@ -1249,7 +1249,7 @@ std::string PropertyLinkBase::tryImportSubName(const App::DocumentObject *obj, c
auto sobj = obj->getSubObject(subname.c_str());
if(!sobj) {
FC_ERR("Failed to restore label reference " << obj->getFullName() << '.' << subname);
return std::string();
return {};
}
dot[0] = 0;
if(next[0] == '$') {
@@ -1273,7 +1273,7 @@ std::string PropertyLinkBase::tryImportSubName(const App::DocumentObject *obj, c
}
if(sub!=subname.c_str())
return ss.str();
return std::string();
return {};
}
#define ATTR_SHADOWED "shadowed"
+1 -1
View File
@@ -127,7 +127,7 @@ Py::Long StringHasherPy::getSize() const
Py::Boolean StringHasherPy::getSaveAll() const
{
return Py::Boolean(getStringHasherPtr()->getSaveAll());
return {getStringHasherPtr()->getSaveAll()};
}
void StringHasherPy::setSaveAll(Py::Boolean value)
+3 -3
View File
@@ -66,17 +66,17 @@ Py::List StringIDPy::getRelated() const
Py::String StringIDPy::getData() const
{
return Py::String(getStringIDPtr()->dataToText(this->_index));
return {getStringIDPtr()->dataToText(this->_index)};
}
Py::Boolean StringIDPy::getIsBinary() const
{
return Py::Boolean(getStringIDPtr()->isBinary());
return {getStringIDPtr()->isBinary()};
}
Py::Boolean StringIDPy::getIsHashed() const
{
return Py::Boolean(getStringIDPtr()->isHashed());
return {getStringIDPtr()->isHashed()};
}
Py::Long StringIDPy::getIndex() const