79 lines
1.7 KiB
Rust
79 lines
1.7 KiB
Rust
use crate::discriptor_table::{Descriptor, TableT, TableType};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct DD {
|
|
pub f: i32,
|
|
pub x: i32,
|
|
pub y: i32,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct DSeq {
|
|
pub d: Descriptor,
|
|
pub del: Vec<DD>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct DTable {
|
|
current_seq: Option<DSeq>,
|
|
}
|
|
|
|
impl TableT for DTable {
|
|
type Seq = DSeq;
|
|
|
|
fn table_type() -> TableType {
|
|
TableType::D
|
|
}
|
|
|
|
fn parse_line(&mut self, line: &str) -> Option<Self::Seq> {
|
|
let fields: Vec<&str> = line.split(';').collect();
|
|
|
|
if fields.len() < 6 {
|
|
return None;
|
|
}
|
|
|
|
let parse_i = |s: &str| s.trim().parse::<i32>().unwrap_or(0);
|
|
|
|
let isf = parse_i(fields[0]);
|
|
let isx = parse_i(fields[1]);
|
|
let isy = parse_i(fields[2]);
|
|
let idf = parse_i(fields[3]);
|
|
let idx = parse_i(fields[4]);
|
|
let idy = parse_i(fields[5]);
|
|
|
|
let mut finished_seq = None;
|
|
let current = &mut self.current_seq;
|
|
|
|
if isf == 3 || isx != 0 || isy != 0 {
|
|
if let Some(prev) = current.take() {
|
|
finished_seq = Some(prev);
|
|
}
|
|
|
|
*current = Some(DSeq {
|
|
d: Descriptor {
|
|
f: isf,
|
|
x: isx,
|
|
y: isy,
|
|
},
|
|
del: Vec::new(),
|
|
});
|
|
}
|
|
|
|
if idf != 0 || idx != 0 || idy != 0 {
|
|
if let Some(seq) = current.as_mut() {
|
|
seq.del.push(DD {
|
|
f: idf,
|
|
x: idx,
|
|
y: idy,
|
|
});
|
|
}
|
|
}
|
|
|
|
finished_seq
|
|
}
|
|
|
|
fn finish(&mut self) -> Option<Self::Seq> {
|
|
self.current_seq.take()
|
|
}
|
|
}
|