Author: rgheck
Date: Mon Dec 20 22:55:09 2010
New Revision: 36974
URL: http://www.lyx.org/trac/changeset/36974

Log:
Finish disentangling tocString(). We introduce a new method, forToc(),
that also makes sure it doesn't do more work than it needs to do, by
limiting the size to 40 characters. Previously, InsetBranch::addToToc()
would have added a string representing the entire contents of the
branch! It's hard to imagine that having to recalculate that sort of
thing doesn't cause some problems with speed, especially in documents
with lots of notes and branches and such.



I've some questions about this.

1. Why do you prefer to have a separate function which needs an implementation in dozens of functions while it does more or less the same as toString(). I mean, why don't you like my solution of AS_STR_INTOC ? We could also add AS_STR_SHORTEN. And generalize toString to - void toString(odocstream & os, int options = AS_STR_NONE, size_t max_len = 0);

2. I especially don't like this kind of duplicated code:

{{{
void InsetQuotes::toString(odocstream & os) const
{
    os << displayString();
}


void InsetQuotes::forToc(docstring & os, size_t) const
{
    os += displayString();
}
}}}

and there are more of these: InsetBranch, InsetRef, InsetSpecialChar, InsetMathHull.

2. I would prefer a different name than "forToc". Especially since it does almost the same as toString(), I would like to see a name that resembles that it does the same (almost), like tocString() maybe ;).

3. You gave a docstring & argument to forToc, while toString has an odocstream & argument. Why the confusing difference ?

Now you have this code in InsetRef:

{{{
void InsetRef::toString(odocstream & os) const
{
    plaintext(os, OutputParams(0));
}


void InsetRef::forToc(docstring & os, size_t) const
{
    odocstringstream ods;
    plaintext(ods, OutputParams(0));
    os += ods.str();
}
}}}

4. I find it a bit confusing that InsetBranch::addToToc() does not use InsetBranch::forToc(). So, forToc() is only used when this branch is in an InsetText which is added to the TOC, while when adding the branch to the toc we override the behaviour by calling InsetText::forToc directly.


Vincent

Reply via email to