Merge branch 'main' of src:greg/sword_rs
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,16 +24,31 @@ pub mod ffi {
|
||||
fn set_key_text(self: Pin<&mut Module>, key_text: &String) -> ();
|
||||
fn set_skip_consecutive_links(self: Pin<&mut Module>, skip: bool);
|
||||
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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user