diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp index 6234a73b390..63160713474 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp @@ -514,14 +514,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( const auto& [key,value] : args ) { - if( (*i).second!=nullptr ) + if( value!=nullptr ) { - key=(*i).first; - val=*(*i).second; - parseField(key, val); + parseField(key, *value); } } } @@ -550,17 +547,22 @@ void Base::parse ( BaseObjectDescription* arg ) } } - for( auto& it : arg->getAttributeMap() ) - { - const std::string& attrName = it.first; + // 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& [key,value] : arg->getAttributeMap() ) + { // 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); } @@ -569,30 +571,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(); @@ -621,9 +621,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()) << "\" "; @@ -638,9 +637,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();