Currently only caring about insets, and writing to file. (Could also
be used to write to the painter)

By doing it like this we can hide all writing and formatting detail
insete the classes derived from writer (we can use whatever method we
like format classes from Asger would possibly be usable)

Gains:
        - simplified code in insets
        - we ensure that all insets can be output with all different
          writers
        - when adding new insets, the compiler will barf unless you
          inplement the new writer method in all derived classes.

Ok, this is likely not the perfect way to do this, but IMO at least
one thing should be kept from this: the absence of a "code"
enum/field.

There should be no code anywhere that cares what kind of writer it got
passed.

// Pure Virtual class.
class Writer {
        writeInsetUrl(<data args in inseturl>) = 0;
};

class LaTeXWriter : Writer {
        writeInsetUrl(<data args in inseturl>) {
                filestr << "\url{" << args << "}" << endl;
        }
};

class ASCIIWriter : Writer {
        writeInsetUrl(<data args in inseturl>) {
                filestr << args << endl;
        }
};

class HTMLWriter : Writer {
        writeInsetUrl(<data args in inseturl>) {
                filestr << "<a href=" << arg << ">" << arg << "</a>"
                << endl;
        }
};

class LinuxDocWriter : Writer {
        writeInsetUrl(<data args in inseturl>) {
                filestr ??
        }
};

class PainterWriter : Writer {
        writeInsetUrl(<data args in inseturl>) {
                painter.drawButton(text text);
        }
};


Think of a verbatim inset:

InsetVerbatim::write(Writer wri) {
        wri.writeInsetVerbatim(vector<verbatimvalidobjects> vec);
}


LaTeXWriter::writeInsetVerbatim(vector<verbatimvalidobjects> vec) {
        filestr << "\\begin{verbatim}" << endl
        for (a = vec.begin(); a != vec.end(); ++a) {
                (*a).write(this);
        }
        filestr.endineol();
        filestr << "\\end{verbatim}" << endl;
}


Well I don't know anymore, but it seemed like nice idea when I was
taking a shower. Especially since it hid all the hairy stuff.

        Lgb



Reply via email to