Skip to content

Commit

Permalink
implement module impls_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandalen committed May 15, 2022
1 parent d5ee5ea commit b7d6b62
Show file tree
Hide file tree
Showing 69 changed files with 2,328 additions and 1,776 deletions.
22 changes: 11 additions & 11 deletions module/rust/for_each/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ dbg!( "c" );
# Sample :: map-style call

Macro `for_each` may be called either in function-style way or in map-style way.
Use keys @PREFIX @POSTFIX @EACH to pass options as entries of a map.
Options @PREFIX and @POSTFIX are optional and their entries could be ommited, but entry @EACH is mandatory.
Order of options should always be @PREFIX, @POSTFIX, @EACH.
Use keys @Prefix @Postfix @Each to pass options as entries of a map.
Options @Prefix and @Postfix are optional and their entries could be ommited, but entry @Each is mandatory.
Order of options should always be @Prefix, @Postfix, @Each.

```rust
use for_each::for_each;

for_each!
{
dbg where
@PREFIX { "prefix".to_string() + }
@POSTFIX { + "postfix" }
@EACH "a" "b" "c"
@Prefix { "prefix".to_string() + }
@Postfix { + "postfix" }
@Each "a" "b" "c"
};

// generates
Expand All @@ -61,9 +61,9 @@ use for_each::for_each;
for_each!
{
dbg where
@PREFIX { "prefix".to_string() + }
@POSTFIX { + "postfix" }
@EACH { "a" + "1" } { "b" + "2" } { "c" + "3" }
@Prefix { "prefix".to_string() + }
@Postfix { + "postfix" }
@Each { "a" + "1" } { "b" + "2" } { "c" + "3" }
};

// generates
Expand All @@ -81,8 +81,8 @@ Use map call style and omit path to callback macro with keyword `where` to invok
use for_each::for_each;
for_each!
{
@PREFIX { dbg! }
@EACH ( "a" ) ( "b" ) ( "c" )
@Prefix { dbg! }
@Each ( "a" ) ( "b" ) ( "c" )
};
// generates
dbg!( "a" );
Expand Down
1 change: 0 additions & 1 deletion module/rust/former_meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ path = "rust/impl/former/meta/lib.rs"
[dependencies]
proc-macro2 = "~1.0"
quote = "~1.0"
# heck = "~0.4"
syn = { version = "~1.0", features = [ "full", "extra-traits", "parsing", "printing" ] }
iter_tools = { path = "../../rust/iter_tools", version = "~0.1" }
werror = { path = "../../rust/werror", version = "~0.1" }
Expand Down
1 change: 1 addition & 0 deletions module/rust/proc_macro_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ path = "sample/rust/proc_macro_tools_trivial/src/main.rs"

[dependencies]
proc-macro2 = { version = "~1.0" }
quote = { version = "~1.0" }
syn = { version = "~1.0", features = [ "full", "extra-traits", "parsing" ] }
winterval = { version = "~0.1", path = "../../rust/winterval" }
# inspect_type = { version = "~0.1", path = "../../rust/inspect_type" }
Expand Down
3 changes: 1 addition & 2 deletions module/rust/time_tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ fn main()
{
/* get milliseconds from UNIX epoch */
let now = time::now();
let now_chrono = chrono::prelude::Utc::now().timestamp_millis();
assert_eq!( now, now_chrono );
println!( "now {}", now );

/* get nanoseconds from UNIX epoch */
let now = time::now();
Expand Down
1 change: 1 addition & 0 deletions module/rust/wtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ former = { version = "~0.1", path = "../../rust/former" }
woptions = { version = "~0.1", path = "../../rust/woptions" }
iter_tools = { version = "~0.1", path = "../../rust/iter_tools" }
meta_tools = { version = "~0.2", path = "../../rust/meta_tools" }
impls_index = { version = "~0.1", path = "../../rust/impls_index" } # despite impls_index is imported by meta_tools it should also be imported immediatly
typing_tools = { version = "~0.1", path = "../../rust/typing_tools" }
time_tools = { version = "~0.1", path = "../../rust/time_tools" }
wstring_tools = { version = "~0.1", path = "../../rust/wstring_tools" }
Expand Down
2 changes: 1 addition & 1 deletion module/rust_alias/former_derive/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Not intended to be used without runtime. This module and runtime is aggregate in

### To add to your project

```
```bash
cargo add former_derive
```
1 change: 1 addition & 0 deletions module/rust_alias/wTools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ default = [ "in_wtools" ]

[dependencies]
wtools = { version = "~0.2", path = "../../rust/wtools" }
impls_index = { version = "~0.1", path = "../../rust/impls_index" } # despite impls_index is imported by wtools it should also be imported immediatly

[dev-dependencies]
rustversion = "~1.0"
Expand Down
189 changes: 99 additions & 90 deletions rust/impl/automata/canonical/cell_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,115 +6,142 @@ pub mod internal
use std::collections::HashMap;
use wtools::prelude::*;

macro_rules! ID
{
() => { < < Self as NodeFactoryInterface >::NodeHandle as HasId >::Id };
}

///
/// Node factory.
///
#[ derive( Debug ) ]
pub struct CellNodeFactory
{
/// Map id to node.
pub id_to_node_map : HashMap< ID!(), crate::NodeCell< Node > >,
}
include!( "./factory_impl.rs" );

// trace_macros!( true );
impls!
{

///
/// Constructor.
/// Iterate output nodes of the node.
///
pub fn make() -> Self
fn node_extend_out_nodes< Id, Iter >
(
&mut self,
node_id : Id,
out_nodes_iter : Iter,
)
where
Iter : IntoIterator< Item = Id >,
Iter::IntoIter : Clone,
Id : Into< ID!() >,
{
let id_to_node_map = HashMap::new();
Self
let out_nodes_iter2 = out_nodes_iter.into_iter()
.map( | id |
{
id_to_node_map,
}
let id = id.into();
self.node( id );
id
});
self.node( node_id.into() ).borrow_mut().extend( out_nodes_iter2 );
// self.node_mut( node_id.into() ).extend( out_nodes_iter );
}

///
/// Get node, making a new one if no such exist. Returns id of the node.
///
//

pub fn node_making< Id >( &mut self, id : Id ) -> ID!()
fn out_nodes< 'a, 'b, Id >( &'a self, node_id : Id )
->
Box< dyn Iterator< Item = ID!() > + 'b >
where
Id : Into< ID!() >,
'a : 'b,
{
let id = id.into();
let node = self.node( node_id ).borrow();
let collected : Vec< ID!() > = node.out_nodes.iter().cloned().collect();
let iterator : Box< dyn Iterator< Item = ID!() > > = Box::new( collected.into_iter() );
iterator
}

let result = self.id_to_node_map
.entry( id )
.or_insert_with( || crate::NodeCell::make( Node::make_named( id ) ) )
;
}

result.borrow().id()
}
///
/// Node factory.
///
#[ derive( Debug ) ]
pub struct CellNodeFactory
{
/// Map id to node.
pub id_to_node_map : HashMap< ID!(), crate::NodeCell< Node > >,
}
// trace_macros!( false );

impl CellNodeFactory
{

index!
{
make,
node_making,
}

}

//

impl GraphBasicInterface
for CellNodeFactory
{
// type NodeHandle = crate::canonical::Node;
type NodeHandle = crate::NodeCell< crate::canonical::Node >;

fn node< Id >( &self, id : Id ) -> &Self::NodeHandle
where
Id : Into< ID!() >,
{
let id = id.into();
let got = self.id_to_node_map.get( &id );
if got.is_some()
{
let result : &Self::NodeHandle = got.unwrap().clone();
return result;
}
unreachable!( "No node with id {:?} found", id );
}
// fn node< Id >( &self, id : Id ) -> &Self::NodeHandle
// where
// Id : Into< ID!() >,
// {
// let id = id.into();
// let got = self.id_to_node_map.get( &id );
// if got.is_some()
// {
// let result : &Self::NodeHandle = got.unwrap().clone();
// return result;
// }
// unreachable!( "No node with id {:?} found", id );
// }
//
// fn node_mut< Id >( &mut self, id : Id ) -> &mut Self::NodeHandle
// where
// Id : Into< ID!() >,
// {
// let id = id.into();
// let got = self.id_to_node_map.get_mut( &id );
// if got.is_some()
// {
// let result : &mut Self::NodeHandle = got.unwrap();
// return result;
// }
// unreachable!( "No node with id {:?} found", id );
// }
//
// fn out_nodes< 'a, 'b, Id >( &'a self, node_id : Id )
// ->
// Box< dyn Iterator< Item = ID!() > + 'b >
// where
// Id : Into< ID!() >,
// 'a : 'b,
// {
// let node = self.node( node_id ).borrow();
// let collected : Vec< ID!() > = node.out_nodes.iter().cloned().collect();
// let iterator : Box< dyn Iterator< Item = ID!() > > = Box::new( collected.into_iter() );
// iterator
// }

fn node_mut< Id >( &mut self, id : Id ) -> &mut Self::NodeHandle
where
Id : Into< ID!() >,
index!
{
let id = id.into();
let got = self.id_to_node_map.get_mut( &id );
if got.is_some()
{
let result : &mut Self::NodeHandle = got.unwrap();
return result;
}
unreachable!( "No node with id {:?} found", id );
node,
node_mut,
out_nodes,
}

fn out_nodes< 'a, 'b, Id >( &'a self, node_id : Id )
->
Box< dyn Iterator< Item = ID!() > + 'b >
where
Id : Into< ID!() >,
'a : 'b,
}

//

impl GraphExtendableInterface
for CellNodeFactory
{

index!
{
let node = self.node( node_id ).borrow();
let collected : Vec< ID!() > = node.out_nodes.iter().cloned().collect();
let iterator : Box< dyn Iterator< Item = ID!() > > = Box::new( collected.into_iter() );
iterator
node_making,
}

}
Expand All @@ -125,27 +152,9 @@ pub mod internal
for CellNodeFactory
{

/// Iterate output nodes of the node.
fn node_extend_out_nodes< Id, Iter >
(
&mut self,
node_id : Id,
out_nodes_iter : Iter,
)
where
Iter : IntoIterator< Item = Id >,
Iter::IntoIter : Clone,
Id : Into< ID!() >,
index!
{
let out_nodes_iter2 = out_nodes_iter.into_iter()
.map( | id |
{
let id = id.into();
self.node( id );
id
});
self.node( node_id.into() ).borrow_mut().extend( out_nodes_iter2 );
// self.node_mut( node_id.into() ).extend( out_nodes_iter );
node_extend_out_nodes,
}

}
Expand All @@ -155,7 +164,7 @@ pub mod internal
impl NodeFactoryInterface
for CellNodeFactory
{
// type Node = Node;
// type NodeHandle = crate::canonical::Node;
type NodeHandle = crate::NodeCell< crate::canonical::Node >;
}

Expand Down
Loading

0 comments on commit b7d6b62

Please sign in to comment.