On Thu, Dec 11, 2003 at 09:58:44AM +0000, Angus Leeming wrote:
> 2. Example usage of string2params, in factory.C's createInset:
> 
>         case LFUN_INSET_INSERT: {
>                 string const name = cmd.getArg(0);
> 
>                 if (name == "bibitem") {
>                         InsetCommandParams icp;
>                         InsetCommandMailer::string2params(cmd.argument, icp);
>                         return new InsetBibitem(icp);
>                 } else ...
> 
>  [...]
> 
> 2. Replacement for string2params.
> 
>         case LFUN_INSET_INSERT: {
>                 string const name = cmd.getArg(0);
> 
>                 if (name == "bibitem") {
>                         istringstream is(cmd.argument);
>                         InsetCommandStreamer ics(name);
>                         is >> ics;
>                         return new InsetBibitem(ics.params);
>                 } else ...
> 
> Is this demonstrably better than the interface above?

Hm. Not this way.

> My personal conclusion is that the present interface is sufficient, 
> but I'm willing to hear your arguments too. 

Don't know.

Well... we have a static function 

  InsetCommandMailer:: static void string2params(std::string const &, std::string 
const & name, InsetCommandParams &);

i.e. a function that basically fills InsetCommandParams.

I could imagine implementing this as a member function of InsetCommandParams

  InsetCommandParams::create(std::string const &, std::string const & name)

or even a constructor:

  InsetCommandParams::InsetCommandParams(std::string const &, std::string const & name)

and the user code would look like

 if (name == "bibitem") {
         return new InsetBibitem(InsetCommandParams(cmd.argument));
 } else ...

Now, I see that this clashs with the constructor of InsetCommandParams.
But that's not a conceptional problem.

In fact, InsetBibitem could have a constructor from a string and user
code would look like

 if (name == "bibitem") {
         return new InsetBibitem(cmd.argument);
 } else ...

Now, that's short enough. I think in this place using the mailer is
just an unneeded intermediate step.

Which leaves

> 1. Example usage of params2string, in LyXFunc::dispatch:
> 
>         case LFUN_DIALOG_SHOW_NEW_INSET: {
>                 string const name = func.getArg(0);
>                 string data = trim(func.argument.substr(name.size()));
> 
>                 if (name == "foo") {
>                         ...
>                 } else if (name == "box") {
>                         // \c data == "Boxed" || "Frameless" etc
>                         InsetBoxParams p(data);
>                         data = InsetBoxMailer::params2string(p);
>                 }
>                 owner->getDialogs().show(name, data, 0);
>                 break;
>         }

This is also a bit verbose. We basically transform a 'data' into 'data'.
So why not have a freestanding

         void transformInsetBoxData(string &)

or
         string transformInsetBoxData(string const &)

function doing the job of

                                 InsetBoxParams p(data);
                                 data = InsetBoxMailer::params2string(p);

?

This way the user does not have to know about InsetBoxParams and
InsetBoxMailer at all.

Andre'

Reply via email to