On Sat, Apr 01, 2006 at 12:11:59PM +0200, Abdelrazak Younes wrote:
> Andre Poenitz a écrit :
> >On Sat, Apr 01, 2006 at 09:47:19AM +0200, Abdelrazak Younes wrote:
> >>>What happens if you put in a "proper" test as I proposed?
> >> 
> >>It seems to work fine.
> >
> >I was actually surprised that it != 0 worked. I thought it should not.
> >
> >>[...] This DocIterator/ParIterator is really complicated.
> >
> >The other option LyX used for half a decade or so is not to have
> >DocIterators at all...
> 
> I didn't say it is not needed or useful. Just that I find it complicated 
> to follow. I also think it is maybe overused in "buffer_funcs.C". Let me 
> take an example:
> 
> bool needEnumCounterReset(ParIterator const & it)
> {
>       Paragraph const & par = *it;
>       BOOST_ASSERT(par.layout()->labeltype == LABEL_ENUMERATE);
>       lyx::depth_type const cur_depth = par.getDepth();
>       ParIterator prev_it = it;
>       while (prev_it.pit()) {
>               --prev_it.top().pit();
>               Paragraph const & prev_par = *prev_it;
>               if (prev_par.getDepth() <= cur_depth)
>                       return  prev_par.layout()->labeltype !=
>                               LABEL_ENUMERATE;
>       }
>       // start of nested inset: reset
>       return true;
> }
> 
> I would rewrite this like this:
> 
> bool needEnumCounterReset(ParagraphList & pars, size_t const pos)
> {
>       BOOST_ASSERT(pars[pos].layout()->labeltype == LABEL_ENUMERATE);
>       lyx::depth_type const cur_depth = pars[pos].getDepth();
>       for (size_t i = pos - 1; i != 0; ++i)
>       {
>               if (pars[i].getDepth() <= cur_depth)
>                       return  pars[i].layout()->labeltype !=
>                               LABEL_ENUMERATE;
>       }
>       // start of nested inset: reset
>       return true;
> }
> 
> Maybe I am missing something but this is simpler. Please correct me if I 
> am wrong.

If it works the same then I am all for simpler solutions. Using --i
might be in order, though.

Andre'

Reply via email to