use lines::Lines;
use std::ops::Deref;
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Keyword {
Comment,
Node,
Cnode,
Mass,
Nsmas,
Nsmas2,
Solid,
Hexa20,
Pent15,
Penta6,
Tetr10,
Tetr4,
Bshel,
Tshel,
Shell,
Shel6,
Shel8,
Membr,
Beam,
Sprgbm,
Bar,
Spring,
Joint,
Kjoin,
Mtojnt,
Sphel,
Sphelo,
Gap,
Impma,
Elink,
Llink,
Slink,
Plink,
Tied,
PartSolid,
PartBshel,
PartTetra,
PartSphel,
PartCos3d,
PartTshel,
PartShell,
PartMembr,
PartBar,
PartBeam,
PartSpring,
PartSprgbm,
PartMbspr,
PartJoint,
PartKjoin,
PartMbkjn,
PartMtojnt,
PartTied,
PartSlink,
PartElink,
PartLlink,
PartPlink,
PartGap,
Mtoco,
Otmco,
Rbody0,
Rbody1,
Rbody2,
Rbody3,
Group,
}
impl Keyword {
#[inline]
pub fn parse(s: &[u8]) -> Option<Keyword> {
use self::Keyword::*;
use byteorder::{BigEndian, ReadBytesExt};
let len = s.len();
if len == 0 {
None
} else if s[0] == b'#' || s[0] == b'$' {
Some(Comment)
} else if len < 8 {
None
} else {
let mut start = &s[0..8];
let num = match start.read_u64::<BigEndian>() {
Ok(n) => n,
Err(_) => return None,
};
match num {
5642803921800933152 => Some(Node),
4849901003360710432 => Some(Cnode),
5566822230893014816 => Some(Mass),
5643939700988194592 => Some(Nsmas),
5643939700989374240 => Some(Nsmas2),
6003100705867444000 => Some(Solid),
5207665581161983776 => Some(Hexa20),
5784115419937058592 => Some(Pent15),
5784115420205559584 => Some(Penta6),
6072352384568274720 => Some(Tetr10),
6072352384617557792 => Some(Tetr4),
4779243092037349152 => Some(Bshel),
6076279784720052000 => Some(Tshel),
6001122697468194592 => Some(Shell),
6001122697099095840 => Some(Shel6),
6001122697132650272 => Some(Shel8),
5567941461554507552 => Some(Membr),
4775294779403546400 => Some(Beam),
6003388769293381408 => Some(Sprgbm),
4774187377920847648 => Some(Bar),
6003388778084249376 => Some(Spring),
5354579082734481184 => Some(Joint),
5425235877383122720 => Some(Kjoin),
5572165819524460320 => Some(Mtojnt),
6003377765751992096 => Some(Sphel),
6003377765755072288 => Some(Sphelo),
5134473149087231776 => Some(Gap),
5281966230710791968 => Some(Impma),
4993446687463714592 => Some(Elink),
5497849845729210144 => Some(Llink),
6002253003994705696 => Some(Slink),
5786080221880921888 => Some(Plink),
6073461731384897312 => Some(Tied),
5782993917790138144 => {
if len < 24 {
None
} else {
let mut p = &s[16..24];
let num2 = match p.read_u64::<BigEndian>() {
Ok(n) => n,
Err(_) => return None,
};
match num2 {
2314885750653208900 | 2314941808515826720
| 2329292621345988640 | 6003100705867440160 => Some(PartSolid),
4779243092037345312 | 2324511927541964832
| 2314923133930654752 | 2314885677705610572 => Some(PartBshel),
6072352384835657760 | 2329563135716958240
| 2314942865212588320 | 2314885754780930625 => Some(PartTetra),
6003377765751988256 | 2329293703611162656
| 2314941812743425056 | 2314885750669722956 => Some(PartSphel),
4850186803352707104 | 2324789051414290464
| 2314924216445781024 | 2314885681934185284 => Some(PartCos3d),
6076279784720048160 | 2329578477122756640
| 2314942925139954720 | 2314885755015021900 => Some(PartTshel),
6001122697468190752 | 2329284894750679072
| 2314941778333813792 | 2314885750535310412 => Some(PartShell),
5567941461554503712 | 2327592780547891232
| 2314935168512709152 | 2314885724715696722 => Some(PartMembr),
4774187377920843808 | 2324492178658697248
| 2314923056786579488 | 2314885677404266528
| 2314885531391054368 | 2314885530820690258 => Some(PartBar),
4775294779403542560 | 2324496504445739040
| 2314923073684185120 | 2314885677470272800
| 2314885531391312205 => Some(PartBeam),
6003388778084245536 | 2329293746628085536
| 2314941812911459911 => Some(PartSpring),
6003388769293377568 | 2329293746593746208
| 2314941812911325773 => Some(PartSprgbm),
5567103693823680544 | 2327589508017692704
| 2314935155729388064 | 2314885724665761874 => Some(PartMbspr),
5354579082734477344 | 2326759333755625504
| 2314931912861176864 | 2314885711998307924 => Some(PartJoint),
5425235877383118880 | 2327035336859721760
| 2314932990998302240 | 2314885716209781070 => Some(PartKjoin),
5572165819524456480 | 2327609281946211360
| 2314935232971296340 => Some(PartMtojnt),
5567094871893745696 | 2327589473557028896
| 2314935155594776096 | 2314885724665236046 => Some(PartMbkjn),
6073461731384893472 | 2329567469101916192
| 2314942882139873312 | 2314885754847052832
| 2314885531693565252 => Some(PartTied),
6002253003994701856 | 2329289310010548256
| 2314941795580922656 | 2314885750602681931 => Some(PartSlink),
4993446687463710752 | 2325348660336599072
| 2314926402418133792 | 2314885690473139787 => Some(PartElink),
5497849845729206304 | 2327318985173573664
| 2314934098999528224 | 2314885720537910859 => Some(PartLlink),
5786080221880918048 | 2328444885080416288
| 2314938497046039328 | 2314885737717780043 => Some(PartPlink),
5134473149087227936 | 2325899544952315936
| 2314928554311163936 | 2314885698878971936
| 2314885531474939936 | 2314885530821017936 => Some(PartGap),
_ => None,
}
}
}
5572165789473058592 => Some(Mtoco),
5716278778525658912 => Some(Otmco),
5927387214544645920 => {
if len < 32 {
None
} else {
let mut p = &s[24..32];
let num3 = match p.read_u64::<BigEndian>() {
Ok(n) => n,
Err(_) => return None,
};
match num3 {
3467807035425300512 | 2319389130445824032
| 2314903123004497952 | 2314885599537930272
| 2314885531086888992 | 2314885530819502112
| 2314885530818457632 | 2314885530818453552 => Some(Rbody0),
3539864629463228448 | 2319670605422534688
| 2314904222516125728 | 2314885603832897568
| 2314885531103666208 | 2314885530819567648
| 2314885530818457888 | 2314885530818453553 => Some(Rbody1),
3611922223501156384 | 2319952080399245344
| 2314905322027753504 | 2314885608127864864
| 2314885531120443424 | 2314885530819633184
| 2314885530818458144 | 2314885530818453554 => Some(Rbody2),
3683979817539084320 | 2320233555375956000
| 2314906421539381280 | 2314885612422832160
| 2314885531137220640 | 2314885530819698720
| 2314885530818458400 | 2314885530818453555 => Some(Rbody3),
_ => None,
}
}
}
5139257352618258208 => Some(Group),
_ => None,
}
}
}
}
#[derive(Debug, Default)]
pub struct Keywords(Vec<Option<Keyword>>);
impl Keywords {
pub fn from_lines(lines: &Lines) -> Keywords {
let v: Vec<Option<Keyword>> = lines.iter().map(Keyword::parse).collect();
Keywords(v)
}
pub fn update(&mut self, first: usize, last: usize, linedata: &Vec<String>) {
let range = first..last;
let _ = self
.0
.splice(range, linedata.iter().map(|l| Keyword::parse(l.as_ref())));
}
}
impl Deref for Keywords {
type Target = [Option<Keyword>];
fn deref(&self) -> &[Option<Keyword>] {
&self.0
}
}