diff --git a/include/powsybl/iidm/VoltageLevel.hxx b/include/powsybl/iidm/VoltageLevel.hxx index c7fe85c2a..c322fd072 100644 --- a/include/powsybl/iidm/VoltageLevel.hxx +++ b/include/powsybl/iidm/VoltageLevel.hxx @@ -71,10 +71,7 @@ stdcxx::Reference VoltageLevel::getConnectable(const std::string& id) { template unsigned long VoltageLevel::getConnectableCount() const { - const auto& terminals = getTerminals(); - return std::count_if(std::begin(terminals), std::end(terminals), [](const Terminal& terminal) { - return Terminal::isInstanceOf(terminal); - }); + return boost::size(getConnectables()); } template diff --git a/src/iidm/Substation.cpp b/src/iidm/Substation.cpp index a74c8ffe7..889fbccdf 100644 --- a/src/iidm/Substation.cpp +++ b/src/iidm/Substation.cpp @@ -54,11 +54,7 @@ Network& Substation::getNetwork() { } unsigned long Substation::getThreeWindingsTransformerCount() const { - unsigned long res = 0UL; - for (const auto& it : m_voltageLevels) { - res += it.get().getConnectableCount(); - } - return res / 3UL; + return boost::size(getThreeWindingsTransformers()); } stdcxx::const_range Substation::getThreeWindingsTransformers() const { @@ -86,11 +82,7 @@ const std::string& Substation::getTso() const { } unsigned long Substation::getTwoWindingsTransformerCount() const { - unsigned long res = 0UL; - for (const auto& it : m_voltageLevels) { - res += it.get().getConnectableCount(); - } - return res / 2UL; + return boost::size(getTwoWindingsTransformers()); } stdcxx::const_range Substation::getTwoWindingsTransformers() const { diff --git a/src/iidm/VoltageLevel.cpp b/src/iidm/VoltageLevel.cpp index 7e56edffe..8f8e2bfda 100644 --- a/src/iidm/VoltageLevel.cpp +++ b/src/iidm/VoltageLevel.cpp @@ -54,10 +54,7 @@ stdcxx::range VoltageLevel::getBatteries() { } unsigned long VoltageLevel::getConnectableCount() const { - const auto& terminals = getTerminals(); - return std::count_if(std::begin(terminals), std::end(terminals), [](const Terminal& terminal) { - return terminal.getConnectable(); - }); + return boost::size(getConnectables()); } unsigned long VoltageLevel::getDanglingLineCount() const {