On Friday 09 August 2002 8:41 pm, Martin Vermeer wrote:
> Hmmm yes, why not? This should work. It might even fix the floats
> problem as a side effect. But how would you set up the Buffer Counters?
> I just didn't see how to do that.

Well, a Counter, owned by a Paragraph would have 
        type // Section, enum, Figure etc
        value // given to it by the Buffer

and the buffer counters would just loop over all Paragraphs from the 
beginning and tell that counter its value.

Something like
        SectionValue = 0;
        Paragraph * par = buffer.firstParagraph();
        while (par) {
                // Only some Paragraphs will set their Counter variable.
                Counter * counter = par->Counter();
                if (Counter && Counter->type == "Section") {
                        Counter->value = SectionValue;
                        ++SectionValue;
                }
                par = par->next();
        }
        
> > It seems daft to have a list in each paragraph when the paragraph uses
> > only a single element of the list.
>
> Yes. But that's how it was before...

There's a lot of code like that ;-)

> > So your paragraph would only touch the section counter from the
> > buffer-wide array, assign it to its own counter after stepping
> > (incrementing) it. Yes that works.
>
> Actually even better: I don't think that a paragraph should have its own
> counter at all. Just the buffer-wide counter array, used directly for
> generating the number label string. Is there any reason to store a
> number in the paragraph itself?

Well you have to know that the Paragraph is of a certain type "Section" 
"Figure Caption" etc, but maybe you know this already?

It's probably less work if you store the Counter as then you need update it 
only when another Counter of the same type is inserted.

And, voilà! You have a CounterInset!

So you could loop over all insets
        Buffer::inset_iterator it  = buffer.inset_const_iterator_begin();
        Buffer::inset_iterator end = buffer.inset_const_iterator_end();

        for (; it != end; ++it) {
                if ((*it)->Code() != COUNTER_CODE)
                        continue;

                Counter * counter = static_cast<InsetCounter *>(*it);
                // Set its value
                ...
        }

Just thoughts.

Regards,
Angus

Reply via email to