53 lines
1.0 KiB
Rust
53 lines
1.0 KiB
Rust
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;
|
|
}
|
|
|
|
}
|