1
This commit is contained in:
parent
03e78e2779
commit
b3b93c650e
@ -7,13 +7,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod xvalue;
|
|
||||||
mod metamgr;
|
|
||||||
mod timer;
|
mod timer;
|
||||||
mod listhead;
|
mod listhead;
|
||||||
|
|
||||||
pub use xvalue::XValue;
|
|
||||||
pub use metamgr::MetaMgr;
|
|
||||||
pub use metamgr::ProtoMsg;
|
|
||||||
pub use timer::Timer;
|
pub use timer::Timer;
|
||||||
pub use listhead::ListHead;
|
pub use listhead::ListHead;
|
||||||
|
174
src/metamgr.rs
174
src/metamgr.rs
@ -1,174 +0,0 @@
|
|||||||
use std::rc::Rc;
|
|
||||||
//use std::fs::File;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
pub trait ProtoMsg {
|
|
||||||
fn deserialize(&self,
|
|
||||||
obj: &serde_json::Map<String, serde_json::Value>,
|
|
||||||
id_key: &mut i64,
|
|
||||||
name_key: &mut String) {}
|
|
||||||
fn init1(&self) {}
|
|
||||||
fn init2(&self) {}
|
|
||||||
fn init3(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct MetaClass<T> {
|
|
||||||
file_name: String,
|
|
||||||
idx: i32,
|
|
||||||
prim_key: String,
|
|
||||||
sec_key: String,
|
|
||||||
dummy: T,
|
|
||||||
wrap_list: Vec<Rc<T>>,
|
|
||||||
wrap_id_hash: HashMap<i64, Rc<T>>,
|
|
||||||
wrap_name_hash: HashMap<String, Rc<T>>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Clone + ProtoMsg> MetaClass<T> {
|
|
||||||
|
|
||||||
fn deserialize_json(&mut self, idx: i64, obj: &serde_json::Map<String, serde_json::Value>) {
|
|
||||||
let msg = Rc::new(self.dummy.clone());
|
|
||||||
let id_key = &mut 0;
|
|
||||||
let name_key = &mut String::new();
|
|
||||||
msg.deserialize(&obj, id_key, name_key);
|
|
||||||
self.wrap_list.push(msg.clone());
|
|
||||||
if self.prim_key.is_empty() {
|
|
||||||
self.wrap_id_hash.insert(idx, msg.clone());
|
|
||||||
} else {
|
|
||||||
if *id_key != 0 {
|
|
||||||
self.wrap_id_hash.insert(*id_key, msg.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !name_key.is_empty() {
|
|
||||||
self.wrap_name_hash.insert(name_key.to_string(), msg.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test1<T>(mgr: &MetaMgr<T>, meta: &MetaClass<T>) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test2<T>(mgr: &MetaMgr<T>) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MetaMgr<T> {
|
|
||||||
meta_classes: Vec<MetaClass::<T>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Clone + ProtoMsg> 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 register_meta(&mut self, file_name: String, idx: i32, prim_key: String, sec_key: String, dummy: T) {
|
|
||||||
let meta = MetaClass::<T> {
|
|
||||||
file_name: file_name,
|
|
||||||
idx: 100,
|
|
||||||
prim_key: prim_key,
|
|
||||||
sec_key: sec_key,
|
|
||||||
dummy: dummy,
|
|
||||||
wrap_list: Vec::new(),
|
|
||||||
wrap_id_hash: HashMap::new(),
|
|
||||||
wrap_name_hash: HashMap::new()
|
|
||||||
};
|
|
||||||
self.meta_classes.push(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test(&self, meta: &mut MetaClass::<T>) {
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load(&mut self) {
|
|
||||||
/*
|
|
||||||
for i in 0..self.meta_classes.len() {
|
|
||||||
let meta = &self.meta_classes[i];
|
|
||||||
match File::open(&meta.file_name) {
|
|
||||||
Ok(f) => {
|
|
||||||
match serde_json::from_reader(f) {
|
|
||||||
Ok(data) => {
|
|
||||||
match (data) {
|
|
||||||
serde_json::Value::Array(arr) =>{
|
|
||||||
let mut idx = 0;
|
|
||||||
for item in arr {
|
|
||||||
if let serde_json::Value::Object(obj) = item {
|
|
||||||
//meta.deserialize_json(idx, &obj);
|
|
||||||
idx = idx + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
serde_json::Value::Object(obj) =>{
|
|
||||||
//meta.deserialize_json(0, &obj);
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_metalist(&mut self, idx: i32) -> Option<&Vec::<Rc::<T>>> {
|
|
||||||
if idx >= 0 && idx as usize <= self.meta_classes.len() {
|
|
||||||
return Some(&self.meta_classes[idx as usize].wrap_list);
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_byid(&mut self, idx: i32, id: i64) -> Option<&Rc<T>> {
|
|
||||||
return self.internal_get_byid(idx as usize, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_byname(&mut self, idx: i32, name: String) -> Option<&Rc<T>> {
|
|
||||||
return self.internal_get_byname(idx as usize, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn internal_get_byid(&mut self, idx: usize, id: i64) -> Option<&Rc<T>> {
|
|
||||||
if idx < self.meta_classes.len() {
|
|
||||||
match self.meta_classes[idx].wrap_id_hash.get(&id) {
|
|
||||||
Some(v) => {
|
|
||||||
return Some(v);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn internal_get_byname(&mut self, idx: usize, name: String) -> Option<&Rc<T>> {
|
|
||||||
if idx < self.meta_classes.len() {
|
|
||||||
match self.meta_classes[idx].wrap_name_hash.get(&name) {
|
|
||||||
Some(v) => {
|
|
||||||
return Some(v);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -130,6 +130,14 @@ impl Timer {
|
|||||||
t.borrow_mut().timer_type = timer_type;
|
t.borrow_mut().timer_type = timer_type;
|
||||||
t.borrow_mut().expire_time = expire_time;
|
t.borrow_mut().expire_time = expire_time;
|
||||||
t.borrow_mut().expires = (self.get_tick_count)() + expire_time as i64;
|
t.borrow_mut().expires = (self.get_tick_count)() + expire_time as i64;
|
||||||
|
match attacher {
|
||||||
|
Some(v) => {
|
||||||
|
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
return Rc::downgrade(&t.borrow().wp);
|
return Rc::downgrade(&t.borrow().wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
pub enum XValue<T> {
|
|
||||||
_IntVal(i64),
|
|
||||||
_UserData(T)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl<T> XValue<T> {
|
|
||||||
|
|
||||||
pub fn new() -> Self {
|
|
||||||
return XValue::<T>::_IntVal(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_i64(&self) -> i64 {
|
|
||||||
match self {
|
|
||||||
XValue::_IntVal(v) => {
|
|
||||||
return *v;
|
|
||||||
},
|
|
||||||
XValue::_UserData(_v) => {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_i64(&mut self, val: i64) {
|
|
||||||
match self {
|
|
||||||
XValue::_IntVal(v) => {
|
|
||||||
*v = val;
|
|
||||||
},
|
|
||||||
XValue::_UserData(_v) => {
|
|
||||||
*self = XValue::<T>::_IntVal(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user