[sword-devel] Best way to work with Genbooks

Troy A. Griffitts scribe at crosswire.org
Wed Mar 6 10:01:38 EST 2024


On 3/6/24 07:49, David "Judah's Shadow" Blue wrote:
> On Tuesday, March 5, 2024 12:28:26 PM EST you wrote:
>> Hi David,
>>
>> Traversing a tree without recursion usually required keeping a stack you
>> can push onto and pop when you hit a leaf.  This is all handled for you
>> in the call stack when you use recursion.  If you really do want to
>> avoid recursion, I would recommend having a look at general strategies
>> for tree traversal without recursion. Something like:
>>
>> https://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/
>>
>> With recursion, our TreeIndexUtil printTree function serves as a great
>> example:
>>
>> https://crosswire.org/svn/sword/trunk/utilities/treeidxutil.cpp
>>
>> Hope this helps. Blessings in your work,
> Thanks, I had already started designing a recursive algorithm just in case, so
> I put it to use. My only other issue in working with genbooks, is finding a
> specific key. It seems like assureKeyPath() would go to the user supplied path.
> But, is there a way to vailidate that I've found an actual path in the module?
> The docs on assureKeyPath say nodes get created if they don't exist, but I
> want to be able to display an error if the path specified doesn't exist.

Hey David,  glad you are making progress on the TOC.

Yes, assureKeyPath will create the full path if it doesn't exist.

If you would simply like to try to position a treekey to a path, you can 
set it like any other SWKey, by simply assigning it to a string value or 
using the setText() method.

Then you can check for error afterward, specifically it should be set to 
KEYERR_OUTOFBOUNDS if it doesn't exist.

Hope this helps,

Troy



>


More information about the sword-devel mailing list