From 42431012cf1b9193c2c2e0e03cc258544e810960 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 6 Jan 2025 15:55:45 +0100 Subject: [PATCH 1/4] [Base] Fix a minor bug related to the printing of info message while parsing Parsing emits some messages with msg_info(). But this one is controlled by the printLog data field. The consequence is that every fields parsed before the "printLog" one are not reporting messages properly. To fix it we need to process the printLog one before any other so there is a consistent result. --- Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp index 1888327ab0d..75c30467113 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp @@ -563,6 +563,13 @@ void Base::parse ( BaseObjectDescription* arg ) } } + // Process the printLog attribute before any other as this one impact how the subsequent + // messages, including the ones emitted in the "parseField" method are reported to the user. + // getAttributes, returns a nullptr if printLog is not used. + auto value = arg->getAttribute("printLog"); + if(value) + parseField("printLog", value); + for( auto& it : arg->getAttributeMap() ) { const std::string& attrName = it.first; From f0c206c176108882a639da06ac2d718133f4b827 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 6 Jan 2025 15:58:28 +0100 Subject: [PATCH 2/4] [Base] Minor code upgrade to iterate over maps using structured binding. --- .../Core/src/sofa/core/objectmodel/Base.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp index 75c30467113..b37ae27aa58 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp @@ -527,14 +527,11 @@ void Base::parseFields ( const std::list& str ) void Base::parseFields ( const std::map& args ) { - std::string key,val; - for( std::map::const_iterator i=args.begin(), iend=args.end(); i!=iend; ++i ) + for( auto& [key,value] : args ) { - if( (*i).second!=nullptr ) + if( value!=nullptr ) { - key=(*i).first; - val=*(*i).second; - parseField(key, val); + parseField(key, *value); } } } @@ -570,17 +567,15 @@ void Base::parse ( BaseObjectDescription* arg ) if(value) parseField("printLog", value); - for( auto& it : arg->getAttributeMap() ) + for( auto& [key,value] : arg->getAttributeMap() ) { - const std::string& attrName = it.first; - // FIX: "type" is already used to define the type of object to instantiate, any Data with // the same name cannot be extracted from BaseObjectDescription - if (attrName == std::string("type")) + if (key == "type") continue; - if (!hasField(attrName)) continue; - parseField(attrName, it.second); + if (hasField(key)) + parseField(key, value); } updateLinks(false); } From 5fd9658b4d44d008253be3e6bfbc6033d3f5ef43 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Mon, 6 Jan 2025 16:07:03 +0100 Subject: [PATCH 3/4] [Base] Extra c++11 replacement of "for earch" loops. --- .../Core/src/sofa/core/objectmodel/Base.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp index b37ae27aa58..3ca05aef46d 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp @@ -584,30 +584,28 @@ void Base::parse ( BaseObjectDescription* arg ) void Base::updateLinks(bool logErrors) { // update links - for(VecLink::const_iterator iLink = m_vecLink.begin(); iLink != m_vecLink.end(); ++iLink) + for(auto& link : m_vecLink) { - const bool ok = (*iLink)->updateLinks(); - if (!ok && (*iLink)->storePath() && logErrors) + const bool ok = link->updateLinks(); + if (!ok && link->storePath() && logErrors) { - msg_warning() << "Link update failed for " << (*iLink)->getName() << " = " << (*iLink)->getValueString() ; + msg_warning() << "Link update failed for " << link->getName() << " = " << link->getValueString() ; } } } void Base::writeDatas ( std::map& args ) { - for(VecData::const_iterator iData = m_vecData.begin(); iData != m_vecData.end(); ++iData) + for(const auto& field : m_vecData) { - const BaseData* field = *iData; std::string name = field->getName(); if( args[name] != nullptr ) *args[name] = field->getValueString(); else args[name] = new string(field->getValueString()); } - for(VecLink::const_iterator iLink = m_vecLink.begin(); iLink != m_vecLink.end(); ++iLink) + for(const auto& link : m_vecLink) { - const BaseLink* link = *iLink; std::string name = link->getName(); if( args[name] != nullptr ) *args[name] = link->getValueString(); @@ -636,9 +634,8 @@ static std::string xmlencode(const std::string& str) void Base::writeDatas (std::ostream& out, const std::string& separator) { - for(VecData::const_iterator iData = m_vecData.begin(); iData != m_vecData.end(); ++iData) + for(const auto& field : m_vecData) { - const BaseData* field = *iData; if (!field->getLinkPath().empty() ) { out << separator << field->getName() << "=\""<< xmlencode(field->getLinkPath()) << "\" "; @@ -653,9 +650,8 @@ void Base::writeDatas (std::ostream& out, const std::string& separator) } } } - for(VecLink::const_iterator iLink = m_vecLink.begin(); iLink != m_vecLink.end(); ++iLink) + for(const auto& link : m_vecLink) { - const BaseLink* link = *iLink; if(link->storePath()) { std::string val = link->getValueString(); From 42c6dfc48c0d955a640fd61a44d75b5a831a9de5 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 8 Jan 2025 11:46:38 +0100 Subject: [PATCH 4/4] Update Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com> --- Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp index 3ca05aef46d..0fbd7bd1abf 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp @@ -527,7 +527,7 @@ void Base::parseFields ( const std::list& str ) void Base::parseFields ( const std::map& args ) { - for( auto& [key,value] : args ) + for( const auto& [key,value] : args ) { if( value!=nullptr ) {