-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new class DictHelper and first method getKeyList
- Loading branch information
1 parent
5316ab6
commit 2e683bf
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |