use daemonic_system_call::DaemonicSystemCall;
use crate::{AXIOMS, AXIOM_OFFSET};
use crate::{const_daemonic_hash, Observation};
use crate::DaemonicError;
use crate::GlassStable;
use crate::daemonic::{Anchor, AnchorDomainSet, SemanticAnchor, SpatialAnchor, StructuralAnchor, SymbolicAnchor};
use crate::daemonic::daemonic_hasher::{DaemonicHashable, DaemonicHasher};
use crate::daemonic::frame::{Frame, FrameType, ReferenceFrame};
use crate::daemonic::glass::{daemonic_system_call, Glass, Severity};
pub(crate) const TOPOLOGY_ANCHOR: u64 = {
let raw = const_daemonic_hash(
"trait TopologyAnchor<TOP = TopologySegment>: SpatialAnchor + StructuralAnchor".as_bytes(),
0x474C415353_u64, );
raw | 1
};
pub trait TopologyAnchor<TOP = TopologySegment>: SpatialAnchor + StructuralAnchor
where
TOP: TopologyAnchor,
{
type Segment: TopologyAnchor = TOP;
fn new_anchor(s: &'static str) -> TopologySegment {
TopologySegment {
label: s, hash: const_daemonic_hash(s.as_bytes(), AXIOM_OFFSET),
crypto_id: const_daemonic_hash(s.as_bytes(), TOPOLOGY_ANCHOR),
depth: s.matches("::").count() as u16, }
}
fn parent(&self) -> Option<Self::Segment>;
fn children(&self) -> &[Self::Segment];
fn is_leaf(&self) -> bool {
self.children().is_empty()
}
fn segments(&self) -> &Self::Segment;
fn depth(&self) -> usize;
}
#[derive(Clone, Eq, PartialEq, Debug, Copy)]
pub struct TopologySegment {
pub(crate) label: &'static str,
pub(crate) hash: u64,
pub(crate) crypto_id: u64,
pub(crate) depth: u16,
}
impl DaemonicHashable for TopologySegment {
fn declare_hashable<GLASS: DaemonicHasher<GLASS> + Glass<GLASS>>(&self, state: &mut GLASS) {
DaemonicHashable::declare_hashable(&self, state);
DaemonicHashable::declare_hashable(&self.label, state);
DaemonicHashable::declare_hashable(&self.hash, state);
DaemonicHashable::declare_hashable(&self.crypto_id, state);
DaemonicHashable::declare_hashable(&self.depth, state);
}
}
impl TopologySegment {
pub fn new(s: &'static str) -> TopologySegment {
TopologySegment {
label: s, hash: const_daemonic_hash(s.as_bytes(), AXIOM_OFFSET),
crypto_id: const_daemonic_hash(s.as_bytes(), TOPOLOGY_ANCHOR),
depth: s.matches("::").count() as u16, }
}
pub fn iter() {todo!()}
}
impl Frame for TopologySegment {
fn frame_type(&self) -> FrameType {
todo!()
}
}
impl ReferenceFrame for TopologySegment {
fn origin(&self) -> &TopologySegment {
todo!()
}
fn transform_to<GLASS>(&self, observation: &impl Glass<GLASS>, target_frame: &dyn ReferenceFrame) -> Option<Observation<GLASS>>
where
GLASS: Clone,
Self: Sized,
{
todo!()
}
}
impl SymbolicAnchor for TopologySegment {
type Anchor = TopologySegment;
fn meaningful_within(&self) -> impl ReferenceFrame {
TopologySegment::new("Daemonic::Anchor::Spatial::Topology::TopologySegment")
}
}
impl Anchor for TopologySegment {
fn anchor_domains(&self) -> AnchorDomainSet {
todo!()
}
}
impl SpatialAnchor for TopologySegment {
fn anchor_position(&self) -> &TopologySegment {
todo!()
}
fn neighbors(&self) -> TopologySegment {
todo!()
}
}
impl StructuralAnchor for TopologySegment {
fn contract_description(&self) -> &str {
todo!()
}
}
impl TopologyAnchor for TopologySegment {
fn parent(&self) -> Option<TopologySegment> {
todo!()
}
fn children(&self) -> &[TopologySegment] {
todo!()
}
fn segments(&self) -> &Self::Segment {
todo!()
}
fn depth(&self) -> usize {
todo!()
}
}
impl SemanticAnchor for TopologySegment {}
unsafe impl DaemonicSystemCall for TopologySegment {}
impl Glass<TopologySegment> for TopologySegment {
type Anchor = TopologySegment;
fn position(&self) -> &TopologySegment {
self
}
fn severity(&self) -> Severity {
Severity::Stable
}
fn tier(&self) -> crate::daemonic::glass::ObservationTier {
crate::daemonic::glass::ObservationTier::Composed
}
fn payload(&self) -> Option<&TopologySegment> {
Some(self)
}
fn into_payload(self) -> Option<TopologySegment>
where
Self: Sized,
{
Some(self)
}
}
impl GlassStable<TopologySegment> for TopologySegment
{
fn value(&self) -> Observation<&TopologySegment> {
let pos = TopologySegment::new("Daemonic::Anchor::Spatial::TopologySegment");
Observation::stable(&self.payload().unwrap(), &pos)
}
fn into_value(self) -> Observation<TopologySegment>
where
Self: Sized,
{
let pos = TopologySegment::new("Daemonic::Anchor::Spatial::TopologySegment");
Observation::stable(self.into_payload().unwrap(), &pos)
}
}
pub const DAEMONIC_SEG: TopologySegment = TopologySegment {
label: "Daemonic",
hash: const_daemonic_hash("Daemonic".as_bytes(), 0x4441454D4F4E4943),
crypto_id: const_daemonic_hash("Daemonic".as_bytes(), AXIOM_OFFSET),
depth: 0,
};
pub const GLASS_SEG: TopologySegment = TopologySegment {
label: "Daemonic::Glass",
hash: const_daemonic_hash("Glass".as_bytes(), 0x4441454D4F4E4943),
crypto_id: const_daemonic_hash("Daemonic::Glass".as_bytes(), AXIOM_OFFSET),
depth: 1,
};