Skip to content

Commit

Permalink
put check in function
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 12, 2024
1 parent 19c4492 commit 6626f29
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ namespace open_atmos
return ConfigParseStatus::Success;
}

bool ContainsOnlyUniqueSpecies(const std::vector<types::Species>& all_species)
{
for (size_t i = 0; i < all_species.size(); ++i)
{
for (size_t j = i + 1; j < all_species.size(); ++j)
{
if (all_species[i].name == all_species[j].name)
{
return false;
}
}
}
return true;
}

std::pair<ConfigParseStatus, std::vector<types::Species>> ParseSpecies(const json& objects)
{
ConfigParseStatus status = ConfigParseStatus::Success;
Expand Down Expand Up @@ -183,20 +198,8 @@ namespace open_atmos
all_species.push_back(species);
}

// check for duplicate species
for (size_t i = 0; i < all_species.size(); ++i)
{
for (size_t j = i + 1; j < all_species.size(); ++j)
{
if (all_species[i].name == all_species[j].name)
{
status = ConfigParseStatus::DuplicateSpeciesDetected;
}
break;
}
if (status != ConfigParseStatus::Success)
break;
}
if (!ContainsOnlyUniqueSpecies(all_species))
status = ConfigParseStatus::DuplicateSpeciesDetected;

return { status, all_species };
}
Expand Down

0 comments on commit 6626f29

Please sign in to comment.