use crate::model::features::Featured;
use crate::model::graph::{GraphFactoryRef, GraphRef};
use crate::model::Provided;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::Debug;
use std::rc::Rc;
use std::sync::Arc;
pub trait DataSetFactory: Debug + Provided {
fn data_set(&self, default_graph: Option<GraphRef>) -> DataSetRef;
fn data_set_from(
&self,
default_graph: Option<GraphRef>,
graphs: HashMap<GraphNameRef, GraphRef>,
) -> DataSetRef {
let data_set = self.data_set(default_graph);
{
let mut data_set = data_set.borrow_mut();
for (name, graph) in graphs {
data_set.insert(name, graph);
}
}
data_set
}
}
pub type DataSetFactoryRef = Arc<dyn DataSetFactory>;
pub trait DataSet: Debug + Featured {
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn has_default_graph(&self) -> bool;
fn default_graph(&self) -> Option<&GraphRef>;
fn has_graph_named(&self, name: &GraphNameRef) -> bool;
fn graph_named(&self, name: &GraphNameRef) -> Option<&GraphRef>;
fn graphs<'a>(&'a self) -> Box<dyn Iterator<Item = (&'a GraphNameRef, &'a GraphRef)> + 'a>;
fn set_default_graph(&mut self, graph: GraphRef);
fn unset_default_graph(&mut self);
fn insert(&mut self, name: GraphNameRef, graph: GraphRef);
fn remove(&mut self, name: &GraphNameRef);
fn clear(&mut self);
fn factory(&self) -> DataSetFactoryRef;
fn graph_factory(&self) -> GraphFactoryRef;
}
pub type DataSetRef = Rc<RefCell<dyn DataSet>>;
pub mod name;
pub use name::{GraphName, GraphNameRef};