Skip to content

Commit

Permalink
check for port exists
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Feb 25, 2025
1 parent c386e5e commit 4daa665
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/io/inputs/model-converter/modelConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PortTypeNotFound::PortTypeNotFound(const std::string& portId, const std::string&
}

ObjectWithThisIdAlreadyExists::ObjectWithThisIdAlreadyExists(const std::string& id):
std::runtime_error("Port type already exists: " + id)
std::runtime_error("Object id already exists: " + id)
{
}

Expand Down Expand Up @@ -197,16 +197,24 @@ std::vector<Antares::Study::SystemModel::Port> convertPorts(
* \return A vector of SystemModel::PortFieldDefinition objects.
*/
std::vector<Study::SystemModel::PortFieldDefinition> convertPortFieldDefinitions(
const IO::Inputs::YmlModel::Model& model,
const std::vector<Study::SystemModel::PortFieldDefinition>& ports)
const IO::Inputs::YmlModel::Model& model)
{
std::vector<Study::SystemModel::PortFieldDefinition> portFieldDefinitions;
portFieldDefinitions.reserve(model.port_field_definitions.size());
for (const auto& port: model.port_field_definitions)
for (const auto& pfdefinition: model.port_field_definitions)
{
if (std::ranges::find_if(model.ports,
[&pfdefinition](const auto& p)
{ return p.id == pfdefinition.port; })
== model.ports.end())
{
// TODO add custom ex
throw ObjectWithThisIdAlreadyExists(pfdefinition.port);
}
}
return portFieldDefinitions;
}

/**
* \brief Converts constraints from YmlModel::Model to SystemModel::Constraint.
*
Expand Down

0 comments on commit 4daa665

Please sign in to comment.