From 2380483023f63d3cd9d3b121b1f6a6bd32c422ba Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 27 Feb 2023 23:41:23 +0100 Subject: [PATCH] [chip-tool] Clean up ComplexArguments once a command is done (#25343) --- examples/chip-tool/commands/clusters/ComplexArgument.h | 4 ++++ examples/chip-tool/commands/common/Command.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/examples/chip-tool/commands/clusters/ComplexArgument.h b/examples/chip-tool/commands/clusters/ComplexArgument.h index 0251c5fd6bf8ff..37a219325d66f2 100644 --- a/examples/chip-tool/commands/clusters/ComplexArgument.h +++ b/examples/chip-tool/commands/clusters/ComplexArgument.h @@ -369,6 +369,8 @@ class ComplexArgument virtual ~ComplexArgument() {} virtual CHIP_ERROR Parse(const char * label, const char * json) = 0; + + virtual void Reset() = 0; }; template @@ -402,6 +404,8 @@ class TypedComplexArgument : public ComplexArgument return ComplexArgumentParser::Setup(label, *mRequest, value); } + void Reset() { *mRequest = T(); } + private: T * mRequest; }; diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index f08d87a2c7ed19..c1d62793024ef7 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -1018,6 +1018,11 @@ void Command::ResetArguments() } vectorArgument->clear(); } + else if (type == ArgumentType::Complex) + { + auto argument = static_cast(arg.value); + argument->Reset(); + } } } }