Files
sword_rs/src/cxx/versekey.cc
T

226 lines
6.0 KiB
C++
Raw Normal View History

2025-06-25 02:30:42 -05:00
#include "versekey.h"
#include <sword/versekey.h>
namespace sword_rs {
2025-06-26 02:19:26 -05:00
// VerseKey methods - all include null pointer checks for safety
2025-06-25 02:30:42 -05:00
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());
}
}
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);
}
}
2025-06-26 02:19:26 -05:00
bool VerseKey::is_valid() const {
return ptr != nullptr;
}
// Factory function for self-managing VerseKey
VerseKey* new_verse_key() {
try {
auto sword_key = new sword::VerseKey();
auto wrapper = new VerseKey();
wrapper->ptr = sword_key;
wrapper->managed = false; // self-managing
return wrapper;
} catch (...) {
return nullptr;
2025-06-25 02:30:42 -05:00
}
}
2025-06-26 02:19:26 -05:00
// Factory function for self-managing VerseKey from text
VerseKey* new_verse_key_from_text(const rust::String text) {
try {
auto sword_key = new sword::VerseKey(std::string(text).c_str());
auto wrapper = new VerseKey();
wrapper->ptr = sword_key;
wrapper->managed = false; // self-managing
return wrapper;
} catch (...) {
return nullptr;
}
2025-06-25 02:30:42 -05:00
}
2025-06-26 02:19:26 -05:00
// Creates a managed VerseKey wrapper from module's sword::VerseKey
VerseKey* get_verse_key_wrapper(SwordVerseKey* sword_key) {
if (!sword_key) {
return nullptr;
}
try {
auto wrapper = new VerseKey();
wrapper->ptr = sword_key;
wrapper->managed = true; // managed by external code
return wrapper;
} catch (...) {
return nullptr;
}
2025-06-25 02:30:42 -05:00
}
2025-06-26 02:19:26 -05:00
// Clone function - always returns self-managing copy using copy constructor
VerseKey* clone_verse_key(const VerseKey& source) {
if (!source.ptr) {
return nullptr;
}
try {
// Create a new sword::VerseKey using copy constructor
auto sword_key = new sword::VerseKey(*source.ptr);
auto wrapper = new VerseKey();
wrapper->ptr = sword_key;
wrapper->managed = false; // clones are always self-managing
return wrapper;
} catch (...) {
return nullptr;
}
2025-06-25 02:30:42 -05:00
}
2025-06-26 02:19:26 -05:00
// Delete function for VerseKey wrappers
void delete_verse_key(VerseKey* verse_key) {
if (verse_key) {
verse_key->cleanup();
delete verse_key;
2025-06-25 02:30:42 -05:00
}
}
}