From ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 Apr 2022 12:02:48 -0400 Subject: Speed gains when working with multiple modules --- src/lib/libbible.cc | 31 +++++++++++++++++++++++++------ src/lib/libbible.h | 11 +++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libbible.cc b/src/lib/libbible.cc index c7a4c61..c6850f7 100644 --- a/src/lib/libbible.cc +++ b/src/lib/libbible.cc @@ -12,8 +12,12 @@ using namespace std; SWMgr library(new MarkupFilterMgr(FMT_XHTML)); OSISFootnotes filter; -vector getBooks(SWModule *target) { +vector getBooksSWModule(SWModule *target) { vector books; + if(target == nullptr) { + // Module doesn't exist + return books; + } VerseKey *key = (VerseKey *) target->getKey(); for(char t = 1; t <= key->getTestamentMax(); t++) { key->setTestament(t); @@ -26,9 +30,9 @@ vector getBooks(SWModule *target) { } // Another issue (maybe bug?) Some translations are NT only, // but still report OT books/chapters. - if(string(target->renderText()).empty()) { - continue; - } + //if(string(target->renderText()).empty()) { + // continue; + //} books.push_back(key->getBookName()); } } @@ -42,11 +46,26 @@ map> libbible::getModules() { for (it = library.getModules().begin(); it != library.getModules().end(); it++) { string modName = (*it).second->getName(); SWModule *target = library.getModule(modName.c_str()); - mods[modName] = getBooks(target); + mods[modName] = getBooksSWModule(target); } return mods; } +vector libbible::getModuleNames() { + library.load(); + vector mods; + ModMap::iterator it; + for (it = library.getModules().begin(); it != library.getModules().end(); it++) { + mods.push_back((*it).second->getName()); + } + return mods; +} + +vector libbible::getBooks(string modName) { + library.load(); + return getBooksSWModule(library.getModule(modName.c_str())); +} + vector libbible::getPassages(string modName, string book) { vector passages; SWModule *target = library.getModule(modName.c_str()); @@ -91,7 +110,7 @@ libbible::passage libbible::getPassage(string modName, string reference) { // Bad input return pass; } - vector validBooks = getBooks(target); + vector validBooks = getBooksSWModule(target); //printf("Hey, I'm inferring missing parts!\n"); // Let's use the target to help us target->setKey(reference.c_str()); diff --git a/src/lib/libbible.h b/src/lib/libbible.h index f77dc8c..fda4d20 100644 --- a/src/lib/libbible.h +++ b/src/lib/libbible.h @@ -27,6 +27,17 @@ namespace libbible { * @return Map of modName to supported books */ std::map> getModules(void); + + /* + * @return List of module names + */ + std::vector getModuleNames(void); + + /* + * @param modName the for which to get the books + * @return Vector of books in the module + */ + std::vector getBooks(std::string modName); /* * @return Vector of valid single full-chapter passages for a book -- cgit v1.2.3