With a little help, we now have VerseKey
Went with a basic wrapper that cxx is able to handle for the bridge between the languages, along with simple wrapper methods
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
#include "versekey.h"
|
||||
#include <memory>
|
||||
#include <sword/versekey.h>
|
||||
|
||||
namespace sword_rs {
|
||||
// Key methods
|
||||
uint8_t VerseKey::get_error() const {
|
||||
return ptr ? ptr->getError() : 0;
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_locale() const {
|
||||
return ptr ? rust::String(ptr->getLocale()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_range_text() const {
|
||||
return ptr ? rust::String(ptr->getRangeText()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_short_text() const {
|
||||
return ptr ? rust::String(ptr->getShortText()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_text() const {
|
||||
return ptr ? rust::String(ptr->getText()) : rust::String("");
|
||||
}
|
||||
|
||||
void VerseKey::normalize(bool autocheck) {
|
||||
if (ptr) {
|
||||
ptr->normalize(autocheck);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t VerseKey::pop_error() {
|
||||
return ptr ? ptr->popError() : 0;
|
||||
}
|
||||
|
||||
void VerseKey::set_locale(const rust::String &locale) {
|
||||
if (ptr) {
|
||||
ptr->setLocale(std::string(locale).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_text(const rust::String &text) {
|
||||
if (ptr) {
|
||||
ptr->setText(std::string(text).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// VerseKey specific methods
|
||||
rust::String VerseKey::get_book_name() const {
|
||||
return ptr ? rust::String(ptr->getBookName()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_book_abbrev() const {
|
||||
return ptr ? rust::String(ptr->getBookAbbrev()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_osis_book_name() const {
|
||||
return ptr ? rust::String(ptr->getOSISBookName()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_osis_ref() const {
|
||||
return ptr ? rust::String(ptr->getOSISRef()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_osis_ref_range_text() const {
|
||||
return ptr ? rust::String(ptr->getOSISRefRangeText()) : rust::String("");
|
||||
}
|
||||
|
||||
rust::String VerseKey::get_short_range_text() const {
|
||||
return ptr ? rust::String(ptr->getShortRangeText()) : rust::String("");
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_testament() const {
|
||||
return ptr ? ptr->getTestament() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_testament_max() const {
|
||||
return ptr ? ptr->getTestamentMax() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_book() const {
|
||||
return ptr ? ptr->getBook() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_book_max() const {
|
||||
return ptr ? ptr->getBookMax() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_chapter() const {
|
||||
return ptr ? ptr->getChapter() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_chapter_max() const {
|
||||
return ptr ? ptr->getChapterMax() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_verse() const {
|
||||
return ptr ? ptr->getVerse() : 0;
|
||||
}
|
||||
|
||||
uint8_t VerseKey::get_verse_max() const {
|
||||
return ptr ? ptr->getVerseMax() : 0;
|
||||
}
|
||||
|
||||
bool VerseKey::is_autonormalize() const {
|
||||
return ptr ? ptr->isAutoNormalize() : false;
|
||||
}
|
||||
|
||||
bool VerseKey::is_intros() const {
|
||||
return ptr ? ptr->isIntros() : false;
|
||||
}
|
||||
|
||||
void VerseKey::set_autonormalize(bool autoNormalize) {
|
||||
if (ptr) {
|
||||
ptr->setAutoNormalize(autoNormalize);
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_book_name(const rust::String &bookName) {
|
||||
if (ptr) {
|
||||
ptr->setBookName(std::string(bookName).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_intros(bool intros) {
|
||||
if (ptr) {
|
||||
ptr->setIntros(intros);
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_testament(uint8_t testament) {
|
||||
if (ptr) {
|
||||
ptr->setTestament(testament);
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_book(uint8_t book) {
|
||||
if (ptr) {
|
||||
ptr->setBook(book);
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_chapter(uint8_t chapter) {
|
||||
if (ptr) {
|
||||
ptr->setChapter(chapter);
|
||||
}
|
||||
}
|
||||
|
||||
void VerseKey::set_verse(uint8_t verse) {
|
||||
if (ptr) {
|
||||
ptr->setVerse(verse);
|
||||
}
|
||||
}
|
||||
|
||||
// Explicit cleanup method
|
||||
void VerseKey::cleanup() {
|
||||
if (owned && ptr) {
|
||||
delete ptr;
|
||||
ptr = nullptr;
|
||||
owned = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Factory functions
|
||||
std::unique_ptr<VerseKey> new_verse_key() {
|
||||
auto verse_key = std::unique_ptr<VerseKey>(new VerseKey{new sword::VerseKey(), true});
|
||||
return verse_key;
|
||||
}
|
||||
|
||||
std::unique_ptr<VerseKey> new_verse_key_from_text(const rust::String& text) {
|
||||
auto verse_key = std::unique_ptr<VerseKey>(new VerseKey{new sword::VerseKey(std::string(text).c_str()), true});
|
||||
return verse_key;
|
||||
}
|
||||
|
||||
VerseKey verse_key_from_borrowed(sword::VerseKey* key) {
|
||||
VerseKey verse_key{key, false};
|
||||
return verse_key;
|
||||
}
|
||||
|
||||
void delete_verse_key(VerseKey* key) {
|
||||
if (key) {
|
||||
key->cleanup();
|
||||
delete key;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user