use std::any::TypeId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VariableType {
Genuine,
Chained,
List,
Shadow(ShadowVariableKind),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ShadowVariableKind {
Custom,
InverseRelation,
Index,
NextElement,
PreviousElement,
Anchor,
Cascading,
Piggyback,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ValueRangeType {
Collection,
CountableRange {
from: i64,
to: i64,
},
EntityDependent,
}
impl VariableType {
pub fn is_genuine(&self) -> bool {
matches!(
self,
VariableType::Genuine | VariableType::Chained | VariableType::List
)
}
pub fn is_shadow(&self) -> bool {
matches!(self, VariableType::Shadow(_))
}
pub fn is_list(&self) -> bool {
matches!(self, VariableType::List)
}
pub fn is_chained(&self) -> bool {
matches!(self, VariableType::Chained)
}
pub fn is_basic(&self) -> bool {
matches!(self, VariableType::Genuine)
}
}
impl ShadowVariableKind {
pub fn requires_listener(&self) -> bool {
matches!(
self,
ShadowVariableKind::Custom | ShadowVariableKind::Cascading
)
}
pub fn is_automatic(&self) -> bool {
matches!(
self,
ShadowVariableKind::InverseRelation
| ShadowVariableKind::Index
| ShadowVariableKind::NextElement
| ShadowVariableKind::PreviousElement
| ShadowVariableKind::Anchor
)
}
pub fn is_piggyback(&self) -> bool {
matches!(self, ShadowVariableKind::Piggyback)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChainedVariableInfo {
pub anchor_type_id: TypeId,
pub entity_type_id: TypeId,
pub has_anchor_shadow: bool,
}
impl ChainedVariableInfo {
pub fn new<Anchor: 'static, Entity: 'static>() -> Self {
Self {
anchor_type_id: TypeId::of::<Anchor>(),
entity_type_id: TypeId::of::<Entity>(),
has_anchor_shadow: false,
}
}
pub fn with_anchor_shadow<Anchor: 'static, Entity: 'static>() -> Self {
Self {
anchor_type_id: TypeId::of::<Anchor>(),
entity_type_id: TypeId::of::<Entity>(),
has_anchor_shadow: true,
}
}
pub fn is_anchor_type(&self, type_id: TypeId) -> bool {
self.anchor_type_id == type_id
}
pub fn is_entity_type(&self, type_id: TypeId) -> bool {
self.entity_type_id == type_id
}
}