Re: [RFC 2/8] Use classes to represent MI Command instead of structures

Tom Tromey
2019-04-25T19:25:08Z

>>>>> "Jan" == Jan Vrany <jan.vrany@fit.cvut.cz> writes:

Jan> +std::unique_ptr<scoped_restore_tmpl<int>>
Jan> +mi_command::do_suppress_notification ()
Jan> +{
Jan> + if (m_suppress_notification != NULL)
Jan> + return std::unique_ptr<scoped_restore_tmpl <int>> (
Jan> + new scoped_restore_tmpl <int> (m_suppress_notification, 1));
Jan> +
Jan> + return std::unique_ptr<scoped_restore_tmpl <int>> ();

Rather than returning a unique_ptr, I think this could directly return a
scoped_restore_tmpl<int>. Then, if m_suppress_notification is NULL,
just use the address of a dummy variable instead.

Jan> +void
Jan> +mi_command_cli::invoke (struct mi_parse *parse)
Jan> +{
Jan> + std::unique_ptr<scoped_restore_tmpl <int>> restore
Jan> + = do_suppress_notification ();

Alternatively, if all invoke methods have to start this way, make invoke
non-virtual and then have it do the setup and then call a virtual
do_invoke function. Then invoke can use a gdb::optional<...>.

Tom