datex-core 0.0.14

The DATEX Core Rust implementation
Documentation
use crate::collections::HashMap;

use crate::{
    prelude::*,
    shared_values::{PointerAddress, ReferencedSharedContainer},
    values::core_values::endpoint::Endpoint,
};

#[derive(Debug, Default)]
pub struct PointerAvailabilityLookup {
    local_endpoint: Endpoint,
    #[allow(unused)]
    lookup: HashMap<Endpoint, Vec<ReferencedSharedContainer>>,
}

impl PointerAvailabilityLookup {
    pub fn new(origin: Endpoint) -> Self {
        Self {
            local_endpoint: origin,
            lookup: HashMap::new(),
        }
    }
    pub fn is_available_for_endpoint(
        &self,
        endpoint: &Endpoint,
        pointer_address: &PointerAddress,
    ) -> bool {
        endpoint.is_local_or_equals_endpoint(&self.local_endpoint)
            && matches!(pointer_address, PointerAddress::SelfOwned(_)) // TODO handle the lookup
    }
    pub fn is_available_for_all_endpoints(
        &self,
        endpoints: &[Endpoint],
        pointer_address: &PointerAddress,
    ) -> bool {
        for endpoint in endpoints {
            if !self.is_available_for_endpoint(endpoint, pointer_address) {
                return false;
            }
        }
        true
    }
}