Skip to content

Commit

Permalink
Add new class DictHelper and first method getKeyList
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-klein committed Oct 26, 2024
1 parent 5316ab6 commit 2e683bf
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ${CMAKE_SOURCE_DIR}/src/sword_backend/module_store.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/repository_interface.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/sword_status_reporter.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/module_helper.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/dict_helper.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/string_helper.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/file_system_helper.cpp
${CMAKE_SOURCE_DIR}/src/sword_backend/module_installer.cpp
Expand Down
17 changes: 16 additions & 1 deletion src/node_sword_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "module_store.hpp"
#include "text_processor.hpp"
#include "module_helper.hpp"
#include "dict_helper.hpp"
#include "module_installer.hpp"
#include "strongs_entry.hpp"
#include "module_search.hpp"
Expand Down Expand Up @@ -126,6 +127,17 @@ void get_book_list(ModuleHelper& module_helper)
}
}

void get_dict_key_list(DictHelper& dict_helper)
{
vector<string> keyList = dict_helper.getKeyList("Vines");

cout << "Got " << keyList.size() << " entries!" << endl;

for (int i = 0; i < keyList.size(); i++) {
cout << keyList[i] << endl;
}
}

void test_unlock_key(ModuleInstaller& module_installer, ModuleStore& module_store, TextProcessor& text_processor)
{
module_installer.uninstallModule("NA28");
Expand Down Expand Up @@ -167,6 +179,7 @@ int main(int argc, char** argv)
{
ModuleStore moduleStore;
ModuleHelper moduleHelper(moduleStore);
DictHelper dictHelper(moduleStore);
SwordStatusReporter statusReporter;
RepositoryInterface repoInterface(statusReporter, moduleHelper, moduleStore);
ModuleInstaller moduleInstaller(repoInterface, moduleStore);
Expand Down Expand Up @@ -209,14 +222,16 @@ int main(int argc, char** argv)
/*sword_facade.installModule("StrongsHebrew");
sword_facade.installModule("StrongsGreek");*/

get_strongs_entry(textProcessor);
//get_strongs_entry(textProcessor);

//get_module_text(textProcessor);

//get_book_intro(textProcessor);

//get_book_list(moduleHelper);

get_dict_key_list(dictHelper);

//string translation = sword_facade.getSwordTranslation(string("/usr/share/sword/locales.d"), string("de"), string("locales"));
//cout << translation << endl;

Expand Down
57 changes: 57 additions & 0 deletions src/sword_backend/dict_helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* This file is part of node-sword-interface.
Copyright (C) 2019 - 2024 Tobias Klein <[email protected]>
node-sword-interface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
node-sword-interface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with node-sword-interface. See the file COPYING.
If not, see <http://www.gnu.org/licenses/>. */

// Sword includes
#include <swmodule.h>
#include <swld.h>

#include "dict_helper.hpp"

using namespace std;
using namespace sword;

std::vector<std::string> DictHelper::getKeyList(std::string moduleName)
{
vector<string> keyList;

SWModule* module = this->_moduleStore.getLocalModule(moduleName);

if (module == 0) {
cerr << "getLocalModule returned zero pointer for " << moduleName << endl;
} else {
const char* moduleType = module->getType();

if (strcmp(moduleType, "Lexicons / Dictionaries") != 0) {

cerr << "Given module is not a lexicon/dictionary!" << endl;

} else {
sword::SWLD* swldModule = dynamic_cast<sword::SWLD*>(module);

long entryCount = swldModule->getEntryCount();

for (long i; i < entryCount; i++) {
const char* key = swldModule->getKeyForEntry(i);
string stringKey = string(key);
keyList.push_back(stringKey);
}
}
}

return keyList;
}
39 changes: 39 additions & 0 deletions src/sword_backend/dict_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This file is part of node-sword-interface.
Copyright (C) 2019 - 2024 Tobias Klein <[email protected]>
node-sword-interface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
node-sword-interface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with node-sword-interface. See the file COPYING.
If not, see <http://www.gnu.org/licenses/>. */

#ifndef _DICT_HELPER
#define _DICT_HELPER

#include <string>
#include <vector>

#include "module_store.hpp"

class DictHelper {
public:
DictHelper(ModuleStore& moduleStore) : _moduleStore(moduleStore) {}

std::vector<std::string> getKeyList(std::string moduleName);

virtual ~DictHelper(){}

private:
ModuleStore& _moduleStore;
};

#endif // _DICT_HELPER

0 comments on commit 2e683bf

Please sign in to comment.