From ceefe5d5f9165060e5a82bf4d890768c50e5501c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Laigre?= Date: Mon, 22 Jun 2020 12:06:25 +0200 Subject: [PATCH] Add the extension in read method and not by read caller (#132) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add the extension in read method and not by read caller * Remove covariance Signed-off-by: Sébastien LAIGRE Signed-off-by: Mathieu BAGUE --- .../entsoe/EntsoeAreaXmlSerializer.hpp | 2 +- .../entsoe/MergedXnodeXmlSerializer.hpp | 2 +- .../extensions/entsoe/XnodeXmlSerializer.hpp | 3 ++- .../entsoe/src/EntsoeAreaXmlSerializer.cpp | 5 +++-- .../entsoe/src/MergedXnodeXmlSerializer.cpp | 5 +++-- extensions/entsoe/src/XnodeXmlSerializer.cpp | 4 ++-- .../iidm/ActivePowerControlXmlSerializer.hpp | 2 +- .../CoordinatedReactiveControlXmlSerializer.hpp | 2 +- ...gsTransformerPhaseAngleClockXmlSerializer.hpp | 2 +- ...gsTransformerPhaseAngleClockXmlSerializer.hpp | 2 +- .../iidm/src/ActivePowerControlXmlSerializer.cpp | 6 ++---- .../CoordinatedReactiveControlXmlSerializer.cpp | 5 +++-- ...gsTransformerPhaseAngleClockXmlSerializer.cpp | 16 +++++++++------- ...gsTransformerPhaseAngleClockXmlSerializer.cpp | 6 ++++-- .../converter/xml/ExtensionXmlSerializer.hpp | 4 ++-- src/iidm/converter/xml/NetworkXml.cpp | 3 +-- .../xml/extensions/LoadBarXmlSerializer.cpp | 5 +++-- .../xml/extensions/LoadBarXmlSerializer.hpp | 2 +- .../xml/extensions/LoadFooXmlSerializer.cpp | 5 +++-- .../xml/extensions/LoadFooXmlSerializer.hpp | 2 +- .../xml/extensions/LoadMockExtXmlSerializer.cpp | 5 +++-- .../xml/extensions/LoadMockExtXmlSerializer.hpp | 2 +- .../xml/extensions/LoadQuxXmlSerializer.cpp | 5 +++-- .../xml/extensions/LoadQuxXmlSerializer.hpp | 2 +- .../xml/extensions/TerminalMockXmlSerializer.cpp | 5 +++-- .../xml/extensions/TerminalMockXmlSerializer.hpp | 2 +- 26 files changed, 57 insertions(+), 47 deletions(-) diff --git a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/EntsoeAreaXmlSerializer.hpp b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/EntsoeAreaXmlSerializer.hpp index 599765598..f94665f86 100644 --- a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/EntsoeAreaXmlSerializer.hpp +++ b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/EntsoeAreaXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace entsoe { class EntsoeAreaXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/MergedXnodeXmlSerializer.hpp b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/MergedXnodeXmlSerializer.hpp index 03141ce11..47827e6eb 100644 --- a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/MergedXnodeXmlSerializer.hpp +++ b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/MergedXnodeXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace entsoe { class MergedXnodeXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/XnodeXmlSerializer.hpp b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/XnodeXmlSerializer.hpp index 22c736901..d401a4ce6 100644 --- a/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/XnodeXmlSerializer.hpp +++ b/extensions/entsoe/include/powsybl/iidm/extensions/entsoe/XnodeXmlSerializer.hpp @@ -9,6 +9,7 @@ #define POWSYBL_IIDM_EXTENSIONS_ENTSOE_XNODEXMLSERIALIZER_HPP #include +#include namespace powsybl { @@ -20,7 +21,7 @@ namespace entsoe { class XnodeXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/entsoe/src/EntsoeAreaXmlSerializer.cpp b/extensions/entsoe/src/EntsoeAreaXmlSerializer.cpp index cbc4dd73a..40044475a 100644 --- a/extensions/entsoe/src/EntsoeAreaXmlSerializer.cpp +++ b/extensions/entsoe/src/EntsoeAreaXmlSerializer.cpp @@ -33,7 +33,7 @@ EntsoeAreaXmlSerializer::EntsoeAreaXmlSerializer() : AbstractExtensionXmlSerializer("entsoeArea", "network", "ea", "http://www.itesla_project.eu/schema/iidm/ext/entsoe_area/1_0") { } -std::unique_ptr EntsoeAreaXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& EntsoeAreaXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } @@ -41,7 +41,8 @@ std::unique_ptr EntsoeAreaXmlSerializer::read(Extendable& extendable, const auto& code = Enum::fromString(context.getReader().readUntilEndElement(getExtensionName())); - return stdcxx::make_unique(substation, code); + extendable.addExtension(stdcxx::make_unique(substation, code)); + return extendable.getExtension(); } void EntsoeAreaXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { diff --git a/extensions/entsoe/src/MergedXnodeXmlSerializer.cpp b/extensions/entsoe/src/MergedXnodeXmlSerializer.cpp index b29b0e5e8..6475a04f3 100644 --- a/extensions/entsoe/src/MergedXnodeXmlSerializer.cpp +++ b/extensions/entsoe/src/MergedXnodeXmlSerializer.cpp @@ -29,7 +29,7 @@ MergedXnodeXmlSerializer::MergedXnodeXmlSerializer() : AbstractExtensionXmlSerializer("mergedXnode", "network", "mxn", "http://www.itesla_project.eu/schema/iidm/ext/merged_xnode/1_0") { } -std::unique_ptr MergedXnodeXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& MergedXnodeXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } @@ -43,7 +43,8 @@ std::unique_ptr MergedXnodeXmlSerializer::read(Extendable& extendable const auto& xnodeQ2 = context.getReader().getAttributeValue("xnodeQ2"); const auto& code = context.getReader().getAttributeValue("code"); - return stdcxx::make_unique(line, rdp, xdp, xnodeP1, xnodeQ1, xnodeP2, xnodeQ2, "", "", code); + extendable.addExtension(stdcxx::make_unique(line, rdp, xdp, xnodeP1, xnodeQ1, xnodeP2, xnodeQ2, "", "", code)); + return extendable.getExtension(); } void MergedXnodeXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { diff --git a/extensions/entsoe/src/XnodeXmlSerializer.cpp b/extensions/entsoe/src/XnodeXmlSerializer.cpp index 9850e7668..d99ee9edd 100644 --- a/extensions/entsoe/src/XnodeXmlSerializer.cpp +++ b/extensions/entsoe/src/XnodeXmlSerializer.cpp @@ -30,10 +30,10 @@ XnodeXmlSerializer::XnodeXmlSerializer() : AbstractExtensionXmlSerializer("xnode", "network", "xn", "http://www.itesla_project.eu/schema/iidm/ext/xnode/1_0") { } -std::unique_ptr XnodeXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& XnodeXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { const auto& code = context.getReader().getAttributeValue("code"); extendable.newExtension().withCode(code).add(); - return stdcxx::make_unique(extendable.getExtension()); + return extendable.getExtension(); } void XnodeXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/ActivePowerControlXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/ActivePowerControlXmlSerializer.hpp index fe1cdbca8..e1b6baddc 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/ActivePowerControlXmlSerializer.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/ActivePowerControlXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace iidm { class ActivePowerControlXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/CoordinatedReactiveControlXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/CoordinatedReactiveControlXmlSerializer.hpp index 1c57cfadf..ef9ecd5dd 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/CoordinatedReactiveControlXmlSerializer.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/CoordinatedReactiveControlXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace iidm { class CoordinatedReactiveControlXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.hpp index a0e88462c..1936fe06d 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace iidm { class ThreeWindingsTransformerPhaseAngleClockXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/iidm/include/powsybl/iidm/extensions/iidm/TwoWindingsTransformerPhaseAngleClockXmlSerializer.hpp b/extensions/iidm/include/powsybl/iidm/extensions/iidm/TwoWindingsTransformerPhaseAngleClockXmlSerializer.hpp index a3e53d4df..b6f600fd8 100644 --- a/extensions/iidm/include/powsybl/iidm/extensions/iidm/TwoWindingsTransformerPhaseAngleClockXmlSerializer.hpp +++ b/extensions/iidm/include/powsybl/iidm/extensions/iidm/TwoWindingsTransformerPhaseAngleClockXmlSerializer.hpp @@ -20,7 +20,7 @@ namespace iidm { class TwoWindingsTransformerPhaseAngleClockXmlSerializer : public converter::xml::AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const override; void write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const override; diff --git a/extensions/iidm/src/ActivePowerControlXmlSerializer.cpp b/extensions/iidm/src/ActivePowerControlXmlSerializer.cpp index a9792e00e..6a2305f7c 100644 --- a/extensions/iidm/src/ActivePowerControlXmlSerializer.cpp +++ b/extensions/iidm/src/ActivePowerControlXmlSerializer.cpp @@ -19,8 +19,6 @@ #include #include -#include - #include #include @@ -36,12 +34,12 @@ ActivePowerControlXmlSerializer::ActivePowerControlXmlSerializer() : AbstractExtensionXmlSerializer("activePowerControl", "network", "apc", "http://www.itesla_project.eu/schema/iidm/ext/active_power_control/1_0") { } -std::unique_ptr ActivePowerControlXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& ActivePowerControlXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { const auto& participate = context.getReader().getAttributeValue("participate"); const auto& droop = context.getReader().getAttributeValue("droop"); extendable.newExtension().withParticipate(participate).withDroop(droop).add(); - return stdcxx::make_unique(extendable.getExtension()); + return extendable.getExtension(); } void ActivePowerControlXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { diff --git a/extensions/iidm/src/CoordinatedReactiveControlXmlSerializer.cpp b/extensions/iidm/src/CoordinatedReactiveControlXmlSerializer.cpp index 5adc2cdd8..0c78bfd53 100644 --- a/extensions/iidm/src/CoordinatedReactiveControlXmlSerializer.cpp +++ b/extensions/iidm/src/CoordinatedReactiveControlXmlSerializer.cpp @@ -33,7 +33,7 @@ CoordinatedReactiveControlXmlSerializer::CoordinatedReactiveControlXmlSerializer AbstractExtensionXmlSerializer("coordinatedReactiveControl", "network", "crc", "http://www.powsybl.org/schema/iidm/ext/coordinated_reactive_control/1_0") { } -std::unique_ptr CoordinatedReactiveControlXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& CoordinatedReactiveControlXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } @@ -41,7 +41,8 @@ std::unique_ptr CoordinatedReactiveControlXmlSerializer::read(Extenda const auto& qPercent = context.getReader().getAttributeValue("qPercent"); - return stdcxx::make_unique(generator, qPercent); + extendable.addExtension(stdcxx::make_unique(generator, qPercent)); + return extendable.getExtension(); } void CoordinatedReactiveControlXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { diff --git a/extensions/iidm/src/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.cpp b/extensions/iidm/src/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.cpp index 7fb6d864e..f4913ee63 100644 --- a/extensions/iidm/src/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.cpp +++ b/extensions/iidm/src/ThreeWindingsTransformerPhaseAngleClockXmlSerializer.cpp @@ -33,7 +33,7 @@ ThreeWindingsTransformerPhaseAngleClockXmlSerializer::ThreeWindingsTransformerPh AbstractExtensionXmlSerializer("threeWindingsTransformerPhaseAngleClock", "network", "threewtpac", "http://www.powsybl.org/schema/iidm/ext/three_windings_transformer_phase_angle_clock/1_0") { } -std::unique_ptr ThreeWindingsTransformerPhaseAngleClockXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& ThreeWindingsTransformerPhaseAngleClockXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } @@ -42,15 +42,16 @@ std::unique_ptr ThreeWindingsTransformerPhaseAngleClockXmlSerializer: const auto& phaseAngleClockLeg2 = context.getReader().getOptionalAttributeValue("phaseAngleClockLeg2", 0UL); const auto& phaseAngleClockLeg3 = context.getReader().getOptionalAttributeValue("phaseAngleClockLeg3", 0UL); - return stdcxx::make_unique(transformer, phaseAngleClockLeg2, phaseAngleClockLeg3); + extendable.addExtension(stdcxx::make_unique(transformer, phaseAngleClockLeg2, phaseAngleClockLeg3)); + return extendable.getExtension(); } -void ThreeWindingsTransformerPhaseAngleClockXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { - const auto& ext = safeCast(extension); + void ThreeWindingsTransformerPhaseAngleClockXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { + const auto& ext = safeCast(extension); - context.getExtensionsWriter().writeOptionalAttribute("phaseAngleClockLeg2", ext.getPhaseAngleClockLeg2(), 0UL); - context.getExtensionsWriter().writeOptionalAttribute("phaseAngleClockLeg3", ext.getPhaseAngleClockLeg3(), 0UL); -} + context.getExtensionsWriter().writeOptionalAttribute("phaseAngleClockLeg2", ext.getPhaseAngleClockLeg2(), 0UL); + context.getExtensionsWriter().writeOptionalAttribute("phaseAngleClockLeg3", ext.getPhaseAngleClockLeg3(), 0UL); + } } // namespace iidm @@ -59,3 +60,4 @@ void ThreeWindingsTransformerPhaseAngleClockXmlSerializer::write(const Extension } // namespace iidm } // namespace powsybl + diff --git a/extensions/iidm/src/TwoWindingsTransformerPhaseAngleClockXmlSerializer.cpp b/extensions/iidm/src/TwoWindingsTransformerPhaseAngleClockXmlSerializer.cpp index 3e33396cd..a8980293c 100644 --- a/extensions/iidm/src/TwoWindingsTransformerPhaseAngleClockXmlSerializer.cpp +++ b/extensions/iidm/src/TwoWindingsTransformerPhaseAngleClockXmlSerializer.cpp @@ -31,7 +31,7 @@ TwoWindingsTransformerPhaseAngleClockXmlSerializer::TwoWindingsTransformerPhaseA AbstractExtensionXmlSerializer("twoWindingsTransformerPhaseAngleClock", "network", "twowtpac", "http://www.powsybl.org/schema/iidm/ext/two_windings_transformer_phase_angle_clock/1_0") { } -std::unique_ptr TwoWindingsTransformerPhaseAngleClockXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { +Extension& TwoWindingsTransformerPhaseAngleClockXmlSerializer::read(Extendable& extendable, converter::xml::NetworkXmlReaderContext& context) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } @@ -39,7 +39,8 @@ std::unique_ptr TwoWindingsTransformerPhaseAngleClockXmlSerializer::r const auto& phaseAngleClock = context.getReader().getOptionalAttributeValue("phaseAngleClock", 0UL); - return stdcxx::make_unique(transformer, phaseAngleClock); + extendable.addExtension(stdcxx::make_unique(transformer, phaseAngleClock)); + return extendable.getExtension(); } void TwoWindingsTransformerPhaseAngleClockXmlSerializer::write(const Extension& extension, converter::xml::NetworkXmlWriterContext& context) const { @@ -55,3 +56,4 @@ void TwoWindingsTransformerPhaseAngleClockXmlSerializer::write(const Extension& } // namespace iidm } // namespace powsybl + diff --git a/include/powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp b/include/powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp index 07624c966..183dd806d 100644 --- a/include/powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp +++ b/include/powsybl/iidm/converter/xml/ExtensionXmlSerializer.hpp @@ -101,11 +101,11 @@ class ExtensionXmlSerializer : public ExtensionProvider { * @param extendable The holder of the new extension * @param context The current XML context * - * @return An extension + * @return The added extension * * @throw An {@link AssertionError} if the extension is not compatible with the extendable type */ - virtual std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const = 0; + virtual Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const = 0; /** * Write an extension in XML diff --git a/src/iidm/converter/xml/NetworkXml.cpp b/src/iidm/converter/xml/NetworkXml.cpp index 912687779..d77a4f1ae 100644 --- a/src/iidm/converter/xml/NetworkXml.cpp +++ b/src/iidm/converter/xml/NetworkXml.cpp @@ -117,8 +117,7 @@ void readExtensions(Identifiable& identifiable, NetworkXmlReaderContext& context stdcxx::CReference serializer = extensionProviders.findProvider(extensionName); if (serializer) { - std::unique_ptr extension = serializer.get().read(identifiable, context); - identifiable.addExtension(std::move(extension)); + serializer.get().read(identifiable, context); } else { extensionsNotFound.insert(extensionName); context.getReader().readUntilEndElement(extensionName, []() {}); diff --git a/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.cpp b/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.cpp index cd6bc0f9d..e46bd79df 100644 --- a/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.cpp +++ b/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.cpp @@ -24,13 +24,14 @@ LoadBarXmlSerializer::LoadBarXmlSerializer() : AbstractExtensionXmlSerializer("loadBar", "network", "bar", "http://www.itesla_project.eu/schema/iidm/ext/loadbar/1_0") { } -std::unique_ptr LoadBarXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& /*context*/) const { +Extension& LoadBarXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& /*context*/) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } auto& load = dynamic_cast(extendable); - return stdcxx::make_unique(load); + extendable.addExtension(stdcxx::make_unique(load)); + return extendable.getExtension(); } void LoadBarXmlSerializer::write(const Extension& /*extension*/, NetworkXmlWriterContext& /*context*/) const { diff --git a/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.hpp b/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.hpp index f1602bf99..9f97edb98 100644 --- a/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.hpp +++ b/test/iidm/converter/xml/extensions/LoadBarXmlSerializer.hpp @@ -24,7 +24,7 @@ namespace extensions { class LoadBarXmlSerializer : public AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const override; void write(const Extension& extension, NetworkXmlWriterContext& context) const override; diff --git a/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.cpp b/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.cpp index f22ab9f5d..bba623922 100644 --- a/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.cpp +++ b/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.cpp @@ -24,13 +24,14 @@ LoadFooXmlSerializer::LoadFooXmlSerializer() : AbstractExtensionXmlSerializer("loadFoo", "network", "foo", "http://www.itesla_project.eu/schema/iidm/ext/loadfoo/1_0") { } -std::unique_ptr LoadFooXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& /*context*/) const { +Extension& LoadFooXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& /*context*/) const { if (!stdcxx::isInstanceOf(extendable)) { throw AssertionError(stdcxx::format("Unexpected extendable type: %1% (%2% expected)", stdcxx::demangle(extendable), stdcxx::demangle())); } auto& load = dynamic_cast(extendable); - return stdcxx::make_unique(load); + extendable.addExtension(stdcxx::make_unique(load)); + return extendable.getExtension(); } void LoadFooXmlSerializer::write(const Extension& /*extension*/, NetworkXmlWriterContext& /*context*/) const { diff --git a/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.hpp b/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.hpp index 2da5daf99..08cb07526 100644 --- a/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.hpp +++ b/test/iidm/converter/xml/extensions/LoadFooXmlSerializer.hpp @@ -24,7 +24,7 @@ namespace extensions { class LoadFooXmlSerializer : public AbstractExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const override; void write(const Extension& extension, NetworkXmlWriterContext& context) const override; diff --git a/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.cpp b/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.cpp index 71f8b99b9..636822717 100644 --- a/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.cpp +++ b/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.cpp @@ -37,7 +37,7 @@ LoadMockExtXmlSerializer::LoadMockExtXmlSerializer() : .build()) { } -std::unique_ptr LoadMockExtXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { +Extension& LoadMockExtXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { checkReadingCompatibility(context); if (!stdcxx::isInstanceOf(extendable)) { @@ -45,7 +45,8 @@ std::unique_ptr LoadMockExtXmlSerializer::read(Extendable& extendable } auto& load = dynamic_cast(extendable); - return stdcxx::make_unique(load); + extendable.addExtension(stdcxx::make_unique(load)); + return extendable.getExtension(); } void LoadMockExtXmlSerializer::write(const Extension& /*extension*/, NetworkXmlWriterContext& /*context*/) const { diff --git a/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.hpp b/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.hpp index c03eead0b..2bec488dc 100644 --- a/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.hpp +++ b/test/iidm/converter/xml/extensions/LoadMockExtXmlSerializer.hpp @@ -24,7 +24,7 @@ namespace extensions { class LoadMockExtXmlSerializer : public AbstractVersionableExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const override; void write(const Extension& extension, NetworkXmlWriterContext& context) const override; diff --git a/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.cpp b/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.cpp index 215151ede..04b387ba6 100644 --- a/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.cpp +++ b/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.cpp @@ -34,7 +34,7 @@ LoadQuxXmlSerializer::LoadQuxXmlSerializer() : .build()) { } -std::unique_ptr LoadQuxXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { +Extension& LoadQuxXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { checkReadingCompatibility(context); if (!stdcxx::isInstanceOf(extendable)) { @@ -42,7 +42,8 @@ std::unique_ptr LoadQuxXmlSerializer::read(Extendable& extendable, Ne } auto& load = dynamic_cast(extendable); - return stdcxx::make_unique(load); + extendable.addExtension(stdcxx::make_unique(load)); + return extendable.getExtension(); } void LoadQuxXmlSerializer::write(const Extension& /*extension*/, NetworkXmlWriterContext& /*context*/) const { diff --git a/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.hpp b/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.hpp index ffaf31114..2a9dab07d 100644 --- a/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.hpp +++ b/test/iidm/converter/xml/extensions/LoadQuxXmlSerializer.hpp @@ -24,7 +24,7 @@ namespace extensions { class LoadQuxXmlSerializer : public AbstractVersionableExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const override; void write(const Extension& extension, NetworkXmlWriterContext& context) const override; diff --git a/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.cpp b/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.cpp index cc5490d51..97c2a939b 100644 --- a/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.cpp +++ b/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.cpp @@ -42,7 +42,7 @@ TerminalMockXmlSerializer::TerminalMockXmlSerializer() : .build()) { } -std::unique_ptr TerminalMockXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { +Extension& TerminalMockXmlSerializer::read(Extendable& extendable, NetworkXmlReaderContext& context) const { checkReadingCompatibility(context); if (!stdcxx::isInstanceOf(extendable)) { @@ -62,7 +62,8 @@ std::unique_ptr TerminalMockXmlSerializer::read(Extendable& extendabl } }); - return std::move(terminalMockExt); + extendable.addExtension(std::move(terminalMockExt)); + return extendable.getExtension(); } void TerminalMockXmlSerializer::write(const Extension& extension, NetworkXmlWriterContext& context) const { diff --git a/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.hpp b/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.hpp index 86d0cfdfe..3cf7a4971 100644 --- a/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.hpp +++ b/test/iidm/converter/xml/extensions/TerminalMockXmlSerializer.hpp @@ -24,7 +24,7 @@ namespace extensions { class TerminalMockXmlSerializer : public AbstractVersionableExtensionXmlSerializer { public: // ExtensionXmlSerializer - std::unique_ptr read(Extendable& extendable, NetworkXmlReaderContext& context) const override; + Extension& read(Extendable& extendable, NetworkXmlReaderContext& context) const override; void write(const Extension& extension, NetworkXmlWriterContext& context) const override;