From 9d05f886059f68894976ef5630dec2d8608ae4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20LAIGRE?= Date: Thu, 30 Jul 2020 07:58:46 +0200 Subject: [PATCH] Call to boost::size to get the number of 2WT, 3WT and Connectables from a VL/substation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien LAIGRE --- include/powsybl/iidm/VoltageLevel.hxx | 5 +---- src/iidm/Substation.cpp | 12 ++---------- src/iidm/VoltageLevel.cpp | 5 +---- 3 files changed, 4 insertions(+), 18 deletions(-) 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 {