Compare commits
No commits in common. "91e56d876d6998d2a6045d0e1e31cd36312783e7" and "473dd5f4dceafe8faedd7cba03686d143ee92d8b" have entirely different histories.
91e56d876d
...
473dd5f4dc
4 changed files with 13 additions and 159 deletions
|
@ -41,12 +41,13 @@ async fn main() {
|
|||
nested::editors::list::init_ctx( ctx.clone() );
|
||||
nested_tty::setup_edittree_hook(&ctx);
|
||||
|
||||
|
||||
/* Create a Representation-Tree of type <List Char>
|
||||
*/
|
||||
let rt_string = ReprTree::new_arc( Context::parse(&ctx, "<List Char>") );
|
||||
|
||||
/* Setup an Editor for this ReprTree
|
||||
* (this will add the representation <List Char>~EditTree to the ReprTree)
|
||||
* (by adding the representation <List Char>~EditTree to the ReprTree)
|
||||
*/
|
||||
let edittree_list = ctx.read().unwrap()
|
||||
.setup_edittree(
|
||||
|
@ -71,24 +72,7 @@ async fn main() {
|
|||
.get_port::<dyn ListView<char>>()
|
||||
.unwrap();
|
||||
|
||||
|
||||
/* Lets add another morphism which will store the values
|
||||
* of the character-list in a `Vec<char>`
|
||||
*/
|
||||
ctx.read().unwrap().morphisms.apply_morphism(
|
||||
rt_string.clone(),
|
||||
&Context::parse(&ctx, "<List Char>"),
|
||||
&Context::parse(&ctx, "<List Char>~<Vec Char>")
|
||||
);
|
||||
|
||||
/* Access the Vec<char> object (wrapped behind a VecBuffer<char>)
|
||||
* from the ReprTree.
|
||||
*/
|
||||
let chars_vec = rt_string
|
||||
.descend(Context::parse(&ctx, "<Vec Char>")).unwrap()
|
||||
.vec_buffer::<char>();
|
||||
|
||||
/* transform `ListView<char>` into a `TerminalView`
|
||||
/* transform ListView<char> into a TerminalView
|
||||
*/
|
||||
let string_view_tty = chars_view
|
||||
.to_sequence()
|
||||
|
@ -138,16 +122,4 @@ async fn main() {
|
|||
/* write the changes in the view of `term_port` to the terminal
|
||||
*/
|
||||
app.show().await.expect("output error!");
|
||||
|
||||
/* need to call update because changes are applied lazily
|
||||
*/
|
||||
chars_vec.get_port().0.update();
|
||||
|
||||
/* Vec<char> to String
|
||||
*/
|
||||
let string = chars_vec.data
|
||||
.read().unwrap()
|
||||
.iter().collect::<String>();
|
||||
|
||||
eprintln!("value of the editor was: {}\n\n", string);
|
||||
}
|
||||
|
|
|
@ -39,20 +39,6 @@ pub fn init_ctx( ctx: Arc<RwLock<Context>> ) {
|
|||
_ => 0
|
||||
};
|
||||
|
||||
/* get char representation or create it if not available
|
||||
*/
|
||||
let char_rt =
|
||||
if let Some(crt) = src_rt.descend(Context::parse(&ctx, "Char")) {
|
||||
crt
|
||||
} else {
|
||||
let crt = ReprTree::from_singleton_buffer(
|
||||
Context::parse(&ctx, "Char"),
|
||||
SingletonBuffer::new('\0')
|
||||
);
|
||||
src_rt.insert_branch(crt.clone());
|
||||
crt
|
||||
};
|
||||
|
||||
/* Create EditTree object
|
||||
*/
|
||||
let mut edittree = DigitEditor::new(
|
||||
|
|
|
@ -2,9 +2,7 @@ use {
|
|||
r3vi::{
|
||||
view::{
|
||||
ViewPort,
|
||||
OuterViewPort, Observer,
|
||||
singleton::*,
|
||||
list::*
|
||||
OuterViewPort, Observer, singleton::*
|
||||
},
|
||||
buffer::{singleton::*, vec::*}
|
||||
},
|
||||
|
@ -91,30 +89,5 @@ pub fn init_ctx(ctx: Arc<RwLock<Context>>) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
let mt = crate::repr_tree::MorphismType {
|
||||
src_type: Context::parse(&ctx, "<List Char>"),
|
||||
dst_type: Context::parse(&ctx, "<List Char>~<Vec Char>")
|
||||
};
|
||||
ctx.write().unwrap().morphisms.add_morphism(
|
||||
mt,
|
||||
{
|
||||
let ctx = ctx.clone();
|
||||
move |src_rt, σ| {
|
||||
let buf = VecBuffer::<char>::new();
|
||||
let mut leaf = ReprLeaf::from_vec_buffer(buf);
|
||||
leaf.attach_to(
|
||||
src_rt.read().unwrap()
|
||||
.get_port::<dyn ListView<char>>()
|
||||
.unwrap()
|
||||
);
|
||||
src_rt.write().unwrap().insert_leaf(
|
||||
vec![ Context::parse(&ctx, "<Vec Char>") ].into_iter(),
|
||||
leaf
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,7 @@ use {
|
|||
AnyViewPort, AnyInnerViewPort, AnyOuterViewPort,
|
||||
port::UpdateTask,
|
||||
View,
|
||||
singleton::*,
|
||||
sequence::*,
|
||||
list::*
|
||||
singleton::*, sequence::*
|
||||
},
|
||||
buffer::{singleton::*, vec::*}
|
||||
},
|
||||
|
@ -37,7 +35,7 @@ pub struct ReprLeaf {
|
|||
out_port: AnyViewPort,
|
||||
in_port: AnyInnerViewPort,
|
||||
data: Option< Arc<dyn Any + Send + Sync> >,
|
||||
|
||||
|
||||
/// keepalive for the observer that updates the buffer from in_port
|
||||
keepalive: Option<Arc<dyn Any + Send + Sync>>,
|
||||
}
|
||||
|
@ -105,19 +103,6 @@ impl ReprLeaf {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_vec_buffer<T>( buffer: VecBuffer<T> ) -> Self
|
||||
where T: Clone + Send + Sync + 'static
|
||||
{
|
||||
eprintln!("ReprLeaf from vec buffer (LEN ={})", buffer.len());
|
||||
let in_port = ViewPort::< dyn ListView<T> >::new();
|
||||
ReprLeaf {
|
||||
keepalive: Some(buffer.attach_to(in_port.outer())),
|
||||
in_port: in_port.inner().into(),
|
||||
out_port: buffer.get_port().0.into(),
|
||||
data: Some(buffer.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_singleton_buffer<T>(&mut self) -> Option<SingletonBuffer<T>>
|
||||
where T: Clone + Send + Sync + 'static
|
||||
{
|
||||
|
@ -151,50 +136,6 @@ impl ReprLeaf {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_vec_buffer<T>(&mut self) -> Option<VecBuffer<T>>
|
||||
where T: Clone + Send + Sync + 'static
|
||||
{
|
||||
let vec_port = self.get_port::< RwLock<Vec<T>> >().unwrap().0;
|
||||
|
||||
let data_arc =
|
||||
if let Some(data) = self.data.as_ref() {
|
||||
eprintln!("downcast existing vec-data");
|
||||
data.clone().downcast::<RwLock<Vec<T>>>().ok()
|
||||
} else {
|
||||
vec_port.update();
|
||||
if let Some(value) = vec_port.outer().get_view() {
|
||||
let value = value.read().unwrap().clone();
|
||||
eprintln!("make new data ARC from old VECTOR-value");
|
||||
Some(Arc::new(RwLock::new( value )))
|
||||
} else {
|
||||
eprintln!("no data vec");
|
||||
Some(Arc::new(RwLock::new( Vec::new() )))
|
||||
// None
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(data_arc) = data_arc {
|
||||
eprintln!("ReprLeaf: have Vec-like data-arc");
|
||||
eprintln!("LEN = {}", data_arc.read().unwrap().len());
|
||||
|
||||
self.data = Some(data_arc.clone() as Arc<dyn Any + Send + Sync>);
|
||||
let buf = VecBuffer {
|
||||
data: data_arc,
|
||||
port: vec_port.inner()
|
||||
};
|
||||
self.keepalive = Some(buf.attach_to(
|
||||
self.in_port.0.clone()
|
||||
.downcast::< dyn ListView<T> >()
|
||||
.ok().unwrap()
|
||||
.outer()
|
||||
));
|
||||
Some(buf)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_port<V>(&self) -> Option<OuterViewPort<V>>
|
||||
where V: View + ?Sized + 'static,
|
||||
V::Msg: Clone
|
||||
|
@ -250,15 +191,6 @@ impl ReprTree {
|
|||
Arc::new(RwLock::new(rt))
|
||||
}
|
||||
|
||||
|
||||
pub fn from_vec_buffer<T>( type_tag: impl Into<TypeTerm>, buf: VecBuffer<T> ) -> Arc<RwLock<Self>>
|
||||
where T: Clone + Send + Sync + 'static
|
||||
{
|
||||
let mut rt = ReprTree::new(type_tag);
|
||||
rt.leaf = Some(ReprLeaf::from_vec_buffer(buf));
|
||||
Arc::new(RwLock::new(rt))
|
||||
}
|
||||
|
||||
/// find, and if necessary, create corresponding path in repr-tree.
|
||||
/// Attach src_port to input of that node
|
||||
pub fn attach_leaf_to<V>(
|
||||
|
@ -339,24 +271,14 @@ impl ReprTree {
|
|||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
leaf.as_singleton_buffer::<T>()
|
||||
} else {
|
||||
// create new singleton buffer
|
||||
/*
|
||||
// default value??
|
||||
let buf = SingletonBuffer::<T>::default();
|
||||
self.leaf = Some(ReprLeaf::from_singleton_buffer(buf.clone()));
|
||||
Some(buf)
|
||||
*/
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vec_buffer<T: Clone + Send + Sync + 'static>(&mut self) -> Option<VecBuffer<T>> {
|
||||
if let Some(leaf) = self.leaf.as_mut() {
|
||||
leaf.as_vec_buffer::<T>()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
/*
|
||||
pub fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> Option<VecBuffer<T>> {
|
||||
}
|
||||
*/
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
|
@ -414,7 +336,7 @@ pub trait ReprTreeExt {
|
|||
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>>;
|
||||
|
||||
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T>;
|
||||
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
|
||||
// fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T>;
|
||||
}
|
||||
|
||||
impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
||||
|
@ -449,10 +371,11 @@ impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
|||
fn singleton_buffer<T: Clone + Send + Sync + 'static>(&self) -> SingletonBuffer<T> {
|
||||
self.write().unwrap().singleton_buffer::<T>().expect("")
|
||||
}
|
||||
|
||||
/*
|
||||
fn vec_buffer<T: Clone + Send + Sync + 'static>(&self) -> VecBuffer<T> {
|
||||
self.write().unwrap().vec_buffer::<T>().expect("")
|
||||
self.read().unwrap().vec_buffer::<T>().expect("")
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
|
Loading…
Reference in a new issue