[sword-devel] Getting info about books, chapters, and verses in a module

Troy A. Griffitts scribe at crosswire.org
Tue Nov 17 19:33:09 EST 2020

Thank you Tobias,

A few comments below:

On 11/17/20 10:46 AM, Tobias Klein wrote:
> Hi Loren,
> This is how I’m doing it in node-sword-interface.
> 1) Getting the list of books in a module
> vector<string> ModuleHelper::getBookList(string moduleName)
> https://github.com/ezra-project/node-sword-interface/blob/master/src/sword_backend/module_helper.cpp#L70 
> <https://github.com/ezra-project/node-sword-interface/blob/master/src/sword_backend/module_helper.cpp#L70>
A small comment, there are different styles of book names:




The first two are localized to whatever language you have set for the 
engine, e.g.,


> 2) Getting a map with the number of verses per chapter per book
> std::map<std::string, std::vector<int>> 
> getBibleChapterVerseCounts(std::string moduleName);
> https://github.com/ezra-project/node-sword-interface/blob/master/src/sword_backend/module_helper.cpp#L92 
> <https://github.com/ezra-project/node-sword-interface/blob/master/src/sword_backend/module_helper.cpp#L92>

I am note sure I condone this behavior here :)  If you found a need to 
do something like this because you couldn't easily use the suggestions 
below, please let me know and maybe we can fix something or extend 
functionality to meet your needs.

If you ever want to know how many Books, Chapters, Verses, etc. are 
available in a reference system, these should serve that purpose:


VerseKey::getBookMax(), once you set the testament

VerseKey::getChapterMax(), once you set the book

VerseKey::getVerseMax(), once you set the chapter

Please remember that each module might give different results, and 
creating a VerseKey object without specifying a reference system will 
create a KJV VerseKey.  If you want the module-specific reference 
system, it is always good to do as your first example does and grab the 
current key, or use SWModule::createKey() to create a key specialized 
for the module-- which you'll need to delete when you are done using.

Hope this helps.  Thanks for the comments!

There's an example here which goes into some of this and covers other 
things like VerseKey ranges:




> Best regards,
> Tobias
>> Am 17.11.2020 um 04:43 schrieb Loren Burkholder 
>> <computersemiexpert at outlook.com <mailto:computersemiexpert at outlook.com>>:
>> I was digging into the docs and found that a VerseKey can give some 
>> info about the book and chapter that it is in, and the numbers of 
>> books and chapters. This could be useful to me because I want to get 
>> a list of the books in a module, then load the number of chapters for 
>> the book and the number of verses for the selected chapter on-demand. 
>> However, I'm not completely sure how I should be doing this. Would 
>> the following pseudo-code be appropriate, or is there a different 
>> method that I should be using?
>> m_books = someVar; // what should this do?
>> key.setBook(m_books.currentIndex());
>> m_chapters = key.getChapterMax();
>> m_verses = key.getVerseMax();
>> setCurrentRef(m_books[index], m_chapters[index], m_verses[index]);
>> I know that this isn't great pseudo code but it's what I came up with.
>> Thanks,
>> Loren
>> _______________________________________________
>> sword-devel mailing list: sword-devel at crosswire.org 
>> <mailto:sword-devel at crosswire.org>
>> http://crosswire.org/mailman/listinfo/sword-devel 
>> <http://crosswire.org/mailman/listinfo/sword-devel>
>> Instructions to unsubscribe/change your settings at above page
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://crosswire.org/pipermail/sword-devel/attachments/20201117/f9d0939c/attachment-0001.html>

More information about the sword-devel mailing list