pub mod xcsp3_core {
use crate::errors::xcsp3error::xcsp3_core::Xcsp3Error;
use crate::variables::xdomain::xcsp3_core::XDomainInteger;
use crate::variables::xvariable_array::xcsp3_core::XVariableArray;
use crate::variables::xvariable_int::xcsp3_core::XVariableInt;
use std::fmt::{Display, Formatter};
use crate::variables::xvariable_tree::xcsp3_core::XVariableTree;
#[derive(Clone)]
pub enum XVariableType {
XVariableNone(Xcsp3Error),
XVariableArray(XVariableArray),
XVariableInt(XVariableInt),
XVariableTree(XVariableTree),
}
impl XVariableType {
pub fn new_int(id: &str, domain: XDomainInteger) -> XVariableType {
XVariableType::XVariableInt(XVariableInt::new(id.to_string(), domain))
}
pub fn new_array(id: &str, sizes: &str, domain: XDomainInteger) -> XVariableType {
match XVariableArray::new(id, sizes, domain) {
Ok(array) => XVariableType::XVariableArray(array),
Err(e) => XVariableType::XVariableNone(e),
}
}
pub fn new_tree(
id: &str,
sizes: &str,
domain_for: Vec<&String>,
domain_value: Vec<&String>,
) -> Result<Self, Xcsp3Error> {
match XVariableTree::new(id, sizes, domain_for, domain_value) {
Ok(t) => Ok(XVariableType::XVariableTree(t)),
Err(e) => Err(e),
}
}
pub fn get_id(&self) -> String {
match self {
XVariableType::XVariableArray(v) => v.id.clone(),
XVariableType::XVariableInt(v) => v.id.clone(),
XVariableType::XVariableTree(v) => v.id.clone(),
_ => String::default(),
}
}
}
impl Display for XVariableType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
XVariableType::XVariableArray(a) => a.to_string(),
XVariableType::XVariableInt(i) => i.to_string(),
XVariableType::XVariableTree(t) => t.to_string(),
_ => {
String::from(
"XVariableNone: there must be an error when parse this variable.",
)
}
}
)
}
}
}