diff options
author | Your Name <you@example.com> | 2022-04-18 12:02:48 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2022-04-18 12:02:48 -0400 |
commit | ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2 (patch) | |
tree | c54d4ffa92cb171ba23a81b2d9d4c6b5e3b41dd4 | |
parent | f843d4e1af82ac7485e8e9428e7411d88d39450e (diff) | |
download | libbible-ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2.tar.gz libbible-ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2.tar.bz2 libbible-ddc05ee8fa60ec240d09d1d71a08f9521a1bd8b2.zip |
Speed gains when working with multiple modulesv1.0.4
-rw-r--r-- | Makefile | 11 | ||||
-rw-r--r-- | src/lib/libbible.cc | 31 | ||||
-rw-r--r-- | src/lib/libbible.h | 11 | ||||
-rw-r--r-- | src/test/testLibbible.cc | 12 |
4 files changed, 54 insertions, 11 deletions
@@ -1,4 +1,4 @@ -export version = 1.0.2 +export version = 1.0.4 export soname_version = $(word 1, $(subst ., , $(version))) override CXXFLAGS += -MMD -Wall -std=c++20 SOURCES = $(wildcard src/*.cc) @@ -10,6 +10,7 @@ exec_prefix ?= $(prefix) libdir ?= $(exec_prefix)/lib bindir ?= $(exec_prefix)/bin includedir ?= $(prefix)/include +completions ?= `pkg-config --variable=completionsdir bash-completion` $(EXECUTABLE): $(OBJECTS) libbible $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) -Lsrc/lib -lbible @@ -27,15 +28,15 @@ test: libbible install: libbible $(EXECUTABLE) install -d $(DESTDIR)$(libdir) install -m 644 src/lib/libbible.so $(DESTDIR)$(libdir)/libbible.so.$(version) - ln -s libbible.so.$(soname_version) $(DESTDIR)$(libdir)/libbible.so - ln -s libbible.so.$(version) $(DESTDIR)$(libdir)/libbible.so.$(soname_version) + ln -sf libbible.so.$(soname_version) $(DESTDIR)$(libdir)/libbible.so + ln -sf libbible.so.$(version) $(DESTDIR)$(libdir)/libbible.so.$(soname_version) install -m 644 src/lib/libbible.a $(DESTDIR)$(libdir) install -d $(DESTDIR)$(includedir) install -m 644 src/lib/libbible.h $(DESTDIR)$(includedir) install -d $(DESTDIR)$(bindir) install -m 755 $(EXECUTABLE) $(DESTDIR)$(bindir) - install -d $(DESTDIR)`pkg-config --variable=completionsdir bash-completion` - install -m 644 bible.bash $(DESTDIR)`pkg-config --variable=completionsdir bash-completion`/$(EXECUTABLE) + install -d $(DESTDIR)$(completions) + install -m 644 bible.bash $(DESTDIR)$(completions)/$(EXECUTABLE) .PHONY: clean clean: 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<string> getBooks(SWModule *target) { +vector<string> getBooksSWModule(SWModule *target) { vector<string> 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<string> 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<string, vector<string>> 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<string> libbible::getModuleNames() { + library.load(); + vector<string> mods; + ModMap::iterator it; + for (it = library.getModules().begin(); it != library.getModules().end(); it++) { + mods.push_back((*it).second->getName()); + } + return mods; +} + +vector<string> libbible::getBooks(string modName) { + library.load(); + return getBooksSWModule(library.getModule(modName.c_str())); +} + vector<libbible::passage> libbible::getPassages(string modName, string book) { vector<libbible::passage> 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<string> validBooks = getBooks(target); + vector<string> 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<std::string, std::vector<std::string>> getModules(void); + + /* + * @return List of module names + */ + std::vector<std::string> getModuleNames(void); + + /* + * @param modName the for which to get the books + * @return Vector of books in the module + */ + std::vector<std::string> getBooks(std::string modName); /* * @return Vector of valid single full-chapter passages for a book diff --git a/src/test/testLibbible.cc b/src/test/testLibbible.cc index 0f65e6d..a4fbc32 100644 --- a/src/test/testLibbible.cc +++ b/src/test/testLibbible.cc @@ -26,6 +26,7 @@ class TestLibbible : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestLibbible); CPPUNIT_TEST(testGetModules); + CPPUNIT_TEST(testGetBooks); CPPUNIT_TEST(testGetPassages); CPPUNIT_TEST(testGetText); CPPUNIT_TEST(testSettings); @@ -39,6 +40,7 @@ class TestLibbible : public CppUnit::TestFixture protected: void testGetModules(void); + void testGetBooks(void); void testGetPassages(void); void testGetText(void); void testSettings(void); @@ -91,6 +93,16 @@ void TestLibbible::testGetModules(void) { CPPUNIT_ASSERT(mods["JPS"].size() == 39); } +void TestLibbible::testGetBooks(void) { + vector<string> mods = libbible::getModuleNames(); + vector<string> kjvbooks = libbible::getBooks("KJV"); + CPPUNIT_ASSERT(kjvbooks.size() == 66); + CPPUNIT_ASSERT(kjvbooks[7] == "Ruth"); + CPPUNIT_ASSERT(kjvbooks[42] == "John"); + vector<string> jpsbooks = libbible::getBooks("JPS"); + CPPUNIT_ASSERT(jpsbooks.size() == 39); +} + void TestLibbible::testGetPassages(void) { auto passages = libbible::getPassages("KJV", "Romans"); CPPUNIT_ASSERT(passages[0].modName == "KJV"); |