use serde::{Deserialize, Serialize};
use crate::dag::Visitor;
#[derive(Debug, Serialize, Deserialize)]
pub struct MachNode {
pub name: String,
pub parent: u32,
pub index: u32,
pub children: Vec<u32>,
pub components: Vec<u32>,
}
impl Default for MachNode {
fn default() -> Self {
Self {
name: String::from("root"),
parent: 0,
index: 0,
children: Vec::new(),
components: Vec::new()
}
}
}
impl MachNode {
pub fn new(name: String) -> Self {
Self {
name: name,
..Default::default()
}
}
pub fn has_parent(&self) -> bool {
self.index != self.parent
}
pub fn has_children(&self) -> bool {
self.children.len() > 0
}
pub fn has_components(&self) -> bool {
self.components.len() > 0
}
pub fn accept(&self, visitor: &impl Visitor) {
visitor.visit(self);
}
pub fn accept_mut(&mut self, visitor: &mut impl Visitor) {
visitor.visit_mut(self);
}
}
impl From<(String, u32)> for MachNode {
fn from((name, parent): (String, u32)) -> Self {
Self {
name: name,
parent: parent,
..Default::default()
}
}
}