From ef56594bad15b24a1f350b7f08b77f76171b27a8 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Sun, 22 Jun 2025 01:39:01 -0500 Subject: [PATCH] Added some Versification knowledge --- build.rs | 3 +++ src/cxx/mod.rs | 16 ++++++++++++++++ src/cxx/versification.cc | 25 +++++++++++++++++++++++++ src/cxx/versification.h | 25 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 src/cxx/versification.cc create mode 100644 src/cxx/versification.h diff --git a/build.rs b/build.rs index 75d2980..e4908de 100644 --- a/build.rs +++ b/build.rs @@ -6,6 +6,7 @@ fn main() { cxx_build::bridge("src/cxx/mod.rs") .file("src/cxx/mgr.cc") .file("src/cxx/module.cc") + .file("src/cxx/versification.cc") .includes(deps.all_include_paths()) .cpp_link_stdlib("stdc++") .flag("-Os") @@ -16,5 +17,7 @@ fn main() { println!("cargo:rerun-if-changed=src/cxx/mgr.h"); println!("cargo:rerun-if-changed=src/cxx/module.cc"); println!("cargo:rerun-if-changed=src/cxx/module.h"); + println!("cargo:rerun-if-changed=src/cxx/versification.h"); + println!("cargo:rerun-if-changed=src/cxx/versification.cc"); println!("cargo:rustc-link-lib=sword"); } diff --git a/src/cxx/mod.rs b/src/cxx/mod.rs index 153a814..40fb431 100644 --- a/src/cxx/mod.rs +++ b/src/cxx/mod.rs @@ -3,6 +3,7 @@ pub mod ffi { unsafe extern "C++" { include!("sword_rs/src/cxx/mgr.h"); include!("sword_rs/src/cxx/module.h"); + include!("sword_rs/src/cxx/versification.h"); type Mgr; @@ -18,16 +19,31 @@ pub mod ffi { fn render_text(self: Pin<&mut Module>) -> String; fn set_key_text(self: Pin<&mut Module>, key_text: &String) -> (); fn strip_text(self: Pin<&mut Module>) -> String; + + type Versification; + type VersificationSystem; + + fn getVersifications(self: &Versification) -> Vec; + fn getVersification(self: &Versification, name: &mut String) -> *const VersificationSystem; + fn new_versification() -> UniquePtr; } } #[cfg(test)] mod tests { + use crate::cxx::ffi::{new_versification, Versification}; + use super::*; use std::fs::{create_dir, File}; use std::io::Write; use tempfile; + #[test] + fn knows_versifications() { + let v = new_versification(); + assert!(v.getVersifications().contains(&"KJV".to_string())); + } + #[test] fn can_create_mgr() { let mgr = ffi::new_mgr(); diff --git a/src/cxx/versification.cc b/src/cxx/versification.cc new file mode 100644 index 0000000..fe4dd07 --- /dev/null +++ b/src/cxx/versification.cc @@ -0,0 +1,25 @@ +#include "versification.h" +#include "rust/cxx.h" + +namespace sword_rs { + Versification::Versification() : + mgr(sword::VersificationMgr::getSystemVersificationMgr()) { } + + rust::Vec Versification::getVersifications() const { + sword::StringList versifications = this->mgr->getVersificationSystems(); + rust::Vec v; + v.reserve(versifications.size()); + for (sword::SWBuf s : versifications) { + v.push_back(rust::String(s.c_str())); + } + return v; + } + + const sword::VersificationMgr::System* Versification::getVersification(rust::String& name) const { + return this->mgr->getVersificationSystem(name.c_str()); + } + + std::unique_ptr new_versification() { + return std::unique_ptr(new Versification()); + } +} diff --git a/src/cxx/versification.h b/src/cxx/versification.h new file mode 100644 index 0000000..bc11b16 --- /dev/null +++ b/src/cxx/versification.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include "rust/cxx.h" +#include + +namespace sword_rs { + using VersificationSystem = sword::VersificationMgr::System; + + class Versification { + private: + sword::VersificationMgr* mgr; + + public: + Versification(); + + ~Versification() {} + + rust::Vec getVersifications() const; + + const VersificationSystem* getVersification(rust::String&) const; + }; + + std::unique_ptr new_versification(); +}