Richard Heck wrote:
Abdelrazak Younes wrote:
Abdelrazak Younes wrote:
Richard Heck wrote:

This got started because there was a crash that involved passing a temporary to Paragraph::setLayout(), and I added a comment to the effect that one ought not to do that. Then Andre suggested there must be a better way, in particular, that maybe we could make Layout's constructor private, etc. Unfortunately, you can't do that, because we have a std::vector of Layout's.

What's wrong with a vector<Layout *> and a private Layout ctor? You just need to declare TextClass as friend in the layout class, that's all. I probably missed something...

I had a look at TextClass, I think that the public typedef (LayoutList and const_iterator) are not really needed. They are only used in GuiToolbars.cpp and GuiDocument.cpp; we can write TextClass helper methods for those cases.

Then, if you don't need the public iterator interface, there's nothing stopping us from using vector<Layout *>, AFAICS from q quick glance.

That's pretty much how the code used to be. Maybe I'm just discovering why it was like that. But what we DON'T need here is the shared pointer that used to be used: It was std::vector<boost_shared_ptr<Layout> >.

Right.


That said, the iterator is really natural, and it was when I wanted to use one rather than to use some sort of helper than things started getting messy.

But you can still use the iterator within TextClass of course. I guess this debate is about genericity versus object orientation. I am fine with genericity inside an object :-). In our case, I think that the two cases were we need an iterator are not performance critical so constructing a temporary vector is fine in this case.

But if you really want the vector<Layout> solution, you could also makes use of RandomAccessList which is used for the ParagraphList.

Abdel.

Reply via email to