Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:
| >>>>> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes:
|
| Lars> it is ok to have different streams for latex,ascii,sgml, but we
| Lars> should also see if we can get rid of the latex,ascii,sgml output
| Lars> methods in the insets. and have the actuall output methods
| Lars> external to the insets. This makes it a lot easier to add new
| Lars> output formats.
|
| I do not see how we could do that while still using virtual methods.
| This would also mean that these output methods should have access to
| the private members of the insets (a bad idea, IMO). Of course, we
| could put all the output methods in the same file (like mathed used to
| do), but I guess this is not what you have in mind.
Even if this is not the most popular patters, it is a lot better than
what we have now.
Visitor pattern:
class DocElementVisitor {
public:
virtual void VisitParagraph(Paragraph &) = 0;
virtual void VisitMinipage(InsetMinipage &) = 0;
};
class DocElement {
public:
virtual void Accept(DocElementVisitor &) = 0;
};
void Paragraph::Accept(DocElementVisitor & v)
{
v.VisitParagraph(*this);
}
voif InsetMinipage::Accept(DocElementVisitor & v)
{
v.VisitMinipage(*this);
}
class LaTeXOutput : public DocElementVisitor {
public:
virtual void VisitParagraph(Paragraph & par) {
...
}
virtual void VisitMinipage(InsetMinipage & inset) {
...
}
};
class DocStats : public DocElementVisitor {
public:
virtual void VisitParagraph(Paragraph & par) {
chars_ += par.num_chars();
words_ += par.num_words();
}
virtual void VisitMinipage(InsetMinipage & inset) {
++insets_;
}
private:
int chars_;
int words_;
int insets_;
--
Lgb