use crate::bias;
use thiserror::Error;
pub fn is_valid_header(line: &str) -> bool {
line.starts_with("%=")
}
#[derive(Debug, Clone)]
pub enum DocumentType {
BiasSolutions,
TropoCoordinates,
}
impl Default for DocumentType {
fn default() -> Self {
Self::BiasSolutions
}
}
#[derive(Debug, Error, Clone)]
pub enum DocumentTypeError {
#[error("unknown file type \"{0}\"")]
UnknownDocumentType(String),
}
impl std::str::FromStr for DocumentType {
type Err = DocumentTypeError;
fn from_str(content: &str) -> Result<Self, Self::Err> {
if content.eq("TRO") {
Ok(Self::TropoCoordinates)
} else if content.eq("BIA") {
Ok(Self::BiasSolutions)
} else {
Err(DocumentTypeError::UnknownDocumentType(content.to_string()))
}
}
}
#[derive(Debug, Clone)]
pub enum Header {
BiasHeader(bias::header::Header),
}
impl Default for Header {
fn default() -> Self {
Self::BiasHeader(bias::header::Header::default())
}
}
impl std::str::FromStr for Header {
type Err = DocumentTypeError;
fn from_str(content: &str) -> Result<Self, Self::Err> {
if let Ok(hd) = bias::header::Header::from_str(content) {
Ok(Self::BiasHeader(hd))
} else {
Err(DocumentTypeError::UnknownDocumentType(content.to_string()))
}
}
}
impl Header {
pub fn bias_header(&self) -> Option<&bias::header::Header> {
match self {
Self::BiasHeader(h) => Some(h),
}
}
}