[sword-devel] Best way to work with Genbooks

David "Judah's Shadow" Blue yudahsshadow at gmx.com
Tue Mar 5 12:13:43 EST 2024


On Monday, March 4, 2024 4:32:43 PM EST David "Judah's Shadow" Blue wrote:
> Ok, I think I have a handle on how to generate the TOC. However, I'm not
> seeing a method in the API docs that would give me the text for a given TOC
> entry

Well I thought i had a handle on generating a TOC, but I'm only getting down 
one branch. I want to avoid recursion if I can, but I can't figure out how to 
get back up the tree to traverse down the next branch. If I have to use 
recursion I can, but I'd really like to avoid it. Here's my code so far.

std::string Genbook::getTOC() {
    sword::TreeKey *treeKey;
    sword::SWModule *mod;
    std::string toc = "";

    mod = swordLibrary->getModule(book.c_str());

    //Assume we don't have a TreeKey yet since we're just starting.
    treeKey = dynamic_cast<sword::TreeKey*>(mod->getKey());

    if(treeKey->firstChild()) {
        while(treeKey->nextSibling()) {
            toc += treeKey->getText();
            toc += "\n";
            if(treeKey->hasChildren()) {
                treeKey->increment();
            }
        }
    }

   return toc;

}





More information about the sword-devel mailing list