Re: A more elegant way of defining a loop?

2002-07-24 Thread Andre Poenitz

On Mon, Jul 22, 2002 at 11:40:47AM +0200, Lars Gullik Bjønnes wrote:
> But it is hard to find the right steps to be able to do it with baby
> steps.

I know. There was this RowSt thing in mathed, too.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: A more elegant way of defining a loop?

2002-07-22 Thread Lars Gullik Bjønnes

Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:

>> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes:
>
| Lars> Paragraphs in containers, rows in containers etc.
>
| Lars> But it is hard to find the right steps to be able to do it with
| Lars> baby steps.
>
| Why not create a pseudo stl list interface for paragraphs (keep the
| next/previous internally, but add proper iterators) and then remove
| progressively all uses of previous()/next(). When they have all been
| removed, you can actually use the container you want for the
| paragraphs.
>
| Easy, isn't it? ;)

I have been down this road as well..., it makes things easier, but it
is not exacly baby steps...

(I have a checked out tree with a lot of this done... I'll try to
begin introducing stuff from it.)

-- 
Lgb



Re: A more elegant way of defining a loop?

2002-07-22 Thread Jean-Marc Lasgouttes

> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes:

Lars> Paragraphs in containers, rows in containers etc.

Lars> But it is hard to find the right steps to be able to do it with
Lars> baby steps.

Why not create a pseudo stl list interface for paragraphs (keep the
next/previous internally, but add proper iterators) and then remove
progressively all uses of previous()/next(). When they have all been
removed, you can actually use the container you want for the
paragraphs.

Easy, isn't it? ;)

JMarc



Re: A more elegant way of defining a loop?

2002-07-22 Thread Lars Gullik Bjønnes

Andre Poenitz <[EMAIL PROTECTED]> writes:

| On Fri, Jul 12, 2002 at 12:21:15PM +0100, Angus Leeming wrote:
>> A Row is a row. It shouldn't care or know about its next() and previous().
>> 
>> A list is a collection of Rows.
>> 
>> That's what the STL is /for/.
>
| Indeed^3.

And this is part of the huge code clean up that I really, really want
done.

Paragraphs in containers, rows in containers etc.

But it is hard to find the right steps to be able to do it with baby
steps.

-- 
Lgb



Re: A more elegant way of defining a loop?

2002-07-12 Thread Andre Poenitz

On Fri, Jul 12, 2002 at 12:21:15PM +0100, Angus Leeming wrote:
> A Row is a row. It shouldn't care or know about its next() and previous().
> 
> A list is a collection of Rows.
> 
> That's what the STL is /for/.

Indeed^3.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: A more elegant way of defining a loop?

2002-07-12 Thread Andre Poenitz

On Fri, Jul 12, 2002 at 01:32:26PM +0200, Juergen Vigna wrote:
> >I tried that once and failed as there is not alwasy a clear meaning of a
> >Row * in the code. It could be a single row or a set of rows starting with
> >this row. This makes things really messy.
> 
> Would you care to explain this better? A Row * is always 1 row, as much
> as I know of that code. The rows are used _only_ in LyXText and denotes
> the whole set of rows of the entire document (visible rows on screen).

Maybe I am mistaken and it was Paragraph * that acted that way. It has been
a while since I tried that.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: A more elegant way of defining a loop?

2002-07-12 Thread Juergen Vigna

Angus Leeming wrote:
> A Row is a row. It shouldn't care or know about its next() and previous().
> 
> A list is a collection of Rows.

Ok explanation understood and accepted!

  Jug

-- 
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._
Dr. Jürgen VignaE-Mail:  [EMAIL PROTECTED]
Mitterstrich 151/A  Tel/Fax: +39-0471-450260 / +39-0471-450253
I-39050 SteineggWeb: http://www.lyx.org/~jug
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._





Re: A more elegant way of defining a loop?

2002-07-12 Thread Angus Leeming

On Friday 12 July 2002 12:32 pm, Juergen Vigna wrote:
> Andre Poenitz wrote:
> > I tried that once and failed as there is not alwasy a clear meaning of a
> > Row * in the code. It could be a single row or a set of rows starting
> > with this row. This makes things really messy.
>
> Would you care to explain this better? A Row * is always 1 row, as much
> as I know of that code. The rows are used _only_ in LyXText and denotes
> the whole set of rows of the entire document (visible rows on screen).
> I don't see what's messy with it?

A Row is a row. It shouldn't care or know about its next() and previous().

A list is a collection of Rows.

That's what the STL is /for/.

Angus



Re: A more elegant way of defining a loop?

2002-07-12 Thread Juergen Vigna

Andre Poenitz wrote:

> I tried that once and failed as there is not alwasy a clear meaning of a
> Row * in the code. It could be a single row or a set of rows starting with
> this row. This makes things really messy.

Would you care to explain this better? A Row * is always 1 row, as much
as I know of that code. The rows are used _only_ in LyXText and denotes
the whole set of rows of the entire document (visible rows on screen).
I don't see what's messy with it?

   Jug

-- 
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._
Dr. Jürgen VignaE-Mail:  [EMAIL PROTECTED]
Mitterstrich 151/A  Tel/Fax: +39-0471-450260 / +39-0471-450253
I-39050 SteineggWeb: http://www.lyx.org/~jug
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._




Re: A more elegant way of defining a loop?

2002-07-12 Thread Andre Poenitz

On Fri, Jul 12, 2002 at 11:56:25AM +0100, Angus Leeming wrote:
> Glad to see that I wasn't being ridiculously stupid. Someone should refactor 
> Row so that list is a natural construct. Till then I thought I should 
> use it as it was designed to be used ;-)

I tried that once and failed as there is not alwasy a clear meaning of a
Row * in the code. It could be a single row or a set of rows starting with
this row. This makes things really messy.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: A more elegant way of defining a loop?

2002-07-12 Thread Angus Leeming

On Friday 12 July 2002 11:14 am, Andre Poenitz wrote:

> for (Row const * row = visible.first; true; row = row->next()) {
>// do what you want to do...
>if (row != visible.second)
>  break;
> }

Glad to see that I wasn't being ridiculously stupid. Someone should refactor 
Row so that list is a natural construct. Till then I thought I should 
use it as it was designed to be used ;-)

> saves one "global" variable but uses 'break' which some people frown upon
> (mostly for reasons I don't accept...)
>
> Andre'



Re: A more elegant way of defining a loop?

2002-07-12 Thread Andre Poenitz

On Fri, Jul 12, 2002 at 10:43:46AM +0100, Angus Leeming wrote:
> Another coding question. Can I write this loop another, more elegant  way?
> Angus
> 
>   // visible contains pointers to the first and last rows visible in 
>   // the BufferView
>   std::pair visible = ...
> 
>   bool running = true;
>   for (Row const * row = visible.first; running; row = row->next()) {
>   do what you want to do...
> 
>   running = row != visible.second;
>   }

for (Row const * row = visible.first; row != visible.second; row = row->next()) {
do what you want to do...
}

is slightly different (might have 0 loops) but depending on what you do it
could be the same. If not I'd write that as

for (Row const * row = visible.first; true; row = row->next()) {
 // do what you want to do...
   if (row != visible.second)
 break;
}

saves one "global" variable but uses 'break' which some people frown upon
(mostly for reasons I don't accept...)

Andre'


-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



A more elegant way of defining a loop?

2002-07-12 Thread Angus Leeming

Another coding question. Can I write this loop another, more elegant  way?
Angus

// visible contains pointers to the first and last rows visible in 
// the BufferView
std::pair visible = ...

bool running = true;
for (Row const * row = visible.first; running; row = row->next()) {
do what you want to do...

running = row != visible.second;
}