Added some Versification knowledge

This commit is contained in:
Greg Hellings
2025-06-22 01:39:01 -05:00
parent 0c7843b386
commit ef56594bad
4 changed files with 69 additions and 0 deletions
+3
View File
@@ -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");
}
+16
View File
@@ -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<String>;
fn getVersification(self: &Versification, name: &mut String) -> *const VersificationSystem;
fn new_versification() -> UniquePtr<Versification>;
}
}
#[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();
+25
View File
@@ -0,0 +1,25 @@
#include "versification.h"
#include "rust/cxx.h"
namespace sword_rs {
Versification::Versification() :
mgr(sword::VersificationMgr::getSystemVersificationMgr()) { }
rust::Vec<rust::String> Versification::getVersifications() const {
sword::StringList versifications = this->mgr->getVersificationSystems();
rust::Vec<rust::String> 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<Versification> new_versification() {
return std::unique_ptr<Versification>(new Versification());
}
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <sword/versificationmgr.h>
#include "rust/cxx.h"
#include <memory>
namespace sword_rs {
using VersificationSystem = sword::VersificationMgr::System;
class Versification {
private:
sword::VersificationMgr* mgr;
public:
Versification();
~Versification() {}
rust::Vec<rust::String> getVersifications() const;
const VersificationSystem* getVersification(rust::String&) const;
};
std::unique_ptr<Versification> new_versification();
}