This commit is contained in:
aozhiwei 2021-12-16 19:54:58 +08:00
parent 1d17503122
commit 374a63d8e0
2 changed files with 54 additions and 0 deletions

View File

@ -8,5 +8,7 @@ mod tests {
}
mod xvalue;
mod metamgr;
pub use xvalue::XValue;
pub use metamgr::MetaMgr;

52
src/metamgr.rs Normal file
View File

@ -0,0 +1,52 @@
use std::rc::Rc;
use std::collections::HashMap;
struct MetaClass<T> {
file_name: String,
idx: i32,
prim_key: String,
sec_key: String,
wrap_list: Vec<Rc<T>>,
wrap_id_hash: HashMap<i64, Rc<T>>,
wrap_name_hash: HashMap<String, Rc<T>>
}
pub struct MetaMgr<T> {
meta_classes: Vec<MetaClass::<T>>,
}
impl<T> MetaMgr<T> {
pub fn new() -> Self {
return MetaMgr::<T>{
meta_classes: Vec::new()
};
}
pub fn init(&mut self) {
}
pub fn un_init(&mut self) {
}
pub fn get_byid(&mut self, idx: i32, id: i64) -> Option<&Rc<T>> {
return self.internal_get_byid(idx as usize, id);
}
pub fn internal_get_byid(&mut self, idx: usize, id: i64) -> Option<&Rc<T>> {
if idx >= 0 && idx <= self.meta_classes.len() {
match self.meta_classes[idx].wrap_id_hash.get(&id) {
Some(v) => {
return Some(v);
}
None => {
}
}
}
return None;
}
}