Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Base] Fix a minor bug related to the printing of info message while parsing & minor upgrade to c++11 #5191

Merged
merged 6 commits into from
Jan 23, 2025
46 changes: 22 additions & 24 deletions Sofa/framework/Core/src/sofa/core/objectmodel/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,11 @@ void Base::parseFields ( const std::list<std::string>& str )

void Base::parseFields ( const std::map<std::string,std::string*>& args )
{
std::string key,val;
for( std::map<string,string*>::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);
}
}
}
Expand Down Expand Up @@ -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);
hugtalbot marked this conversation as resolved.
Show resolved Hide resolved
}
updateLinks(false);
}
Expand All @@ -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<std::string,std::string*>& 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();
Expand Down Expand Up @@ -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()) << "\" ";
Expand All @@ -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();
Expand Down
Loading