use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Error;
use std::io::ErrorKind;
pub struct LineIO {
reader: BufReader<File>,
}
impl LineIO {
pub fn new(filename: &String) -> std::io::Result<LineIO> {
let f = File::open(filename)?;
let reader = BufReader::with_capacity(32000, f);
Ok(LineIO {
reader,
})
}
pub fn getline(&mut self) -> std::io::Result<String> {
loop {
let mut line = String::new();
let _len = self.reader.read_line(&mut line).unwrap();
if _len == 0 {
return std::result::Result::Err(Error::new(ErrorKind::Other, "end of file"));
}
if line.starts_with("#") {
continue;
}
if _len == 1 {
continue;
}
return Ok(line.trim().to_string());
}
}
pub fn to_usize(s: &String) -> Vec<usize> {
s.split_whitespace().map(|v| v.parse().unwrap()).collect()
}
pub fn to_f32(s: &String) -> Vec<f32> {
s.split_whitespace().map(|v| v.parse().unwrap()).collect()
}
pub fn to_u32(s: &String) -> Vec<u32> {
s.split_whitespace().map(|v| v.parse().unwrap()).collect()
}
pub fn to_i32(s: &String) -> Vec<i32> {
s.split_whitespace().map(|v| v.parse().unwrap()).collect()
}
}