Direction dispatcher
This commit is contained in:
parent
03b6925b0c
commit
58be1f0023
@ -1,4 +1,4 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::{NodeRef, NodeRefContainer};
|
||||
|
||||
pub enum BinaryTreeDirection {
|
||||
LEFT,
|
||||
@ -62,3 +62,7 @@ pub unsafe trait BinaryTreeParentSetterContext: NodeRefContainer {
|
||||
|
||||
fn clearParent(&mut self, node: Self::NodeRef);
|
||||
}
|
||||
|
||||
pub trait BinaryTreeDirectionDispatcherClojure: NodeRefContainer {
|
||||
fn determineDirection(&self, node: Self::NodeRef) -> Option<BinaryTreeDirection>;
|
||||
}
|
||||
@ -29,4 +29,8 @@ pub unsafe trait DirectedBinaryTreeChildrenSetterContext: NodeRefContainer {
|
||||
|
||||
fn clearForwardChild(&mut self, node: Self::NodeRef);
|
||||
fn clearOppositeChild(&mut self, node: Self::NodeRef);
|
||||
}
|
||||
|
||||
pub trait DirectedBinaryTreeDirectionDispatcherClojure: NodeRefContainer {
|
||||
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection>;
|
||||
}
|
||||
@ -1,12 +1,16 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::base_context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
|
||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext,
|
||||
BinaryTreeDirectionDispatcherClojure, BinaryTreeParentGetterContext,
|
||||
BinaryTreeParentSetterContext,
|
||||
};
|
||||
use crate::base_context::{BinaryTreeRootGetter, BinaryTreeRootSetter};
|
||||
use crate::directed_context::context::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
};
|
||||
use crate::directed_context::{
|
||||
DirectedBinaryTreeDirection, DirectedBinaryTreeDirectionDispatcherClojure,
|
||||
};
|
||||
use crate::relation_context::{
|
||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||
DirectedBinaryTreeRelationSetterContext,
|
||||
@ -188,3 +192,21 @@ unsafe impl<Ctx: BinaryTreeRelationSetterContext> DirectedBinaryTreeRelationSett
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctx: BinaryTreeDirectionDispatcherClojure> DirectedBinaryTreeDirectionDispatcherClojure
|
||||
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
|
||||
{
|
||||
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection> {
|
||||
match self.ctx.determineDirection(node) {
|
||||
None => return None,
|
||||
Some(BinaryTreeDirection::LEFT) => match self.dir {
|
||||
BinaryTreeDirection::LEFT => return Some(DirectedBinaryTreeDirection::FORWARD),
|
||||
BinaryTreeDirection::RIGHT => return Some(DirectedBinaryTreeDirection::OPPOSITE),
|
||||
},
|
||||
Some(BinaryTreeDirection::RIGHT) => match self.dir {
|
||||
BinaryTreeDirection::LEFT => return Some(DirectedBinaryTreeDirection::OPPOSITE),
|
||||
BinaryTreeDirection::RIGHT => return Some(DirectedBinaryTreeDirection::FORWARD),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::base_context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
|
||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
|
||||
BinaryTreeRootSetter,
|
||||
BinaryTreeRootSetter, BinaryTreeDirectionDispatcherClojure
|
||||
};
|
||||
use crate::directed_context::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
DirectedBinaryTreeDirectionDispatcherClojure, DirectedBinaryTreeDirection
|
||||
};
|
||||
use crate::relation_context::{
|
||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||
@ -23,17 +24,33 @@ pub struct FixedRightDirectedBinaryTreeContextFromContext<CtxRef> {
|
||||
ctx: CtxRef,
|
||||
}
|
||||
|
||||
_mut_switch!(_ctx_wrapper_constructor!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_ctx_wrapper_constructor!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_ctx_wrapper_constructor!(
|
||||
FixedLeftDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
_mut_switch!(_ctx_wrapper_constructor!(
|
||||
FixedRightDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
|
||||
_mut_switch!(_delegate_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_node_ref!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_node_ref!(
|
||||
FixedLeftDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
_mut_switch!(_delegate_node_ref!(
|
||||
FixedRightDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
|
||||
_mut_switch!(_delegate_root_getter!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_root_getter!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_root_getter!(
|
||||
FixedLeftDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
_mut_switch!(_delegate_root_getter!(
|
||||
FixedRightDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
|
||||
_mut_switch!(_delegate_parent_getter!(FixedLeftDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext));
|
||||
_mut_switch!(_delegate_parent_getter!(
|
||||
FixedLeftDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
_mut_switch!(_delegate_parent_getter!(
|
||||
FixedRightDirectedBinaryTreeContextFromContext
|
||||
));
|
||||
|
||||
macro_rules! _children_get {
|
||||
($name:ident $fwd:ident $op:ident $($mut:tt)? ) => {
|
||||
@ -166,3 +183,27 @@ _relation_set!(
|
||||
xSetRightRelation setRightRelation clearRightChild
|
||||
xSetLeftRelation setLeftRelation clearLeftChild
|
||||
);
|
||||
|
||||
macro_rules! _direction_selector {
|
||||
($name:ident $left:ident $right:ident $($mut:tt)?) => {
|
||||
impl<Ctx: BinaryTreeDirectionDispatcherClojure> DirectedBinaryTreeDirectionDispatcherClojure
|
||||
for $name<& $($mut)? Ctx>
|
||||
{
|
||||
fn determineDirection(&self, node: Self::NodeRef) -> Option<DirectedBinaryTreeDirection> {
|
||||
match self.ctx.determineDirection(node) {
|
||||
None => return None,
|
||||
Some(BinaryTreeDirection::LEFT) => return Some(DirectedBinaryTreeDirection::$left),
|
||||
Some(BinaryTreeDirection::RIGHT) => return Some(DirectedBinaryTreeDirection::$right)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
_mut_switch!(_direction_selector!(
|
||||
FixedLeftDirectedBinaryTreeContextFromContext
|
||||
FORWARD OPPOSITE
|
||||
));
|
||||
_mut_switch!(_direction_selector!(
|
||||
FixedRightDirectedBinaryTreeContextFromContext
|
||||
OPPOSITE FORWARD
|
||||
));
|
||||
|
||||
@ -1,12 +1,6 @@
|
||||
use crate::NodeRefContainer;
|
||||
use crate::base_context::{
|
||||
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
|
||||
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
|
||||
BinaryTreeRootSetter,
|
||||
};
|
||||
use crate::directed_context::{
|
||||
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
|
||||
};
|
||||
use crate::base_context::{BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection, BinaryTreeDirectionDispatcherClojure, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter, BinaryTreeRootSetter};
|
||||
use crate::directed_context::{DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeDirection, DirectedBinaryTreeDirectionDispatcherClojure};
|
||||
use crate::relation_context::{
|
||||
BinaryTreeRelationSetterContext, BinaryTreeRootRelationSetterContext,
|
||||
DirectedBinaryTreeRelationSetterContext,
|
||||
@ -123,3 +117,23 @@ unsafe impl<Ctx: BinaryTreeParentSetterContext + DirectedBinaryTreeChildrenSette
|
||||
self.ctx.clearOppositeChild(parent);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! _direction_selector {
|
||||
($name:ident $ctx:ident $enum:ident $($mut:tt)?) => {
|
||||
impl<Ctx: $ctx> $ctx
|
||||
for $name<& $($mut)? Ctx>
|
||||
{
|
||||
fn determineDirection(&self, node: Self::NodeRef) -> Option<$enum> {
|
||||
return self.ctx.determineDirection(node)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
_mut_switch!(_direction_selector!(
|
||||
BinaryTreeRelationContextFromBaseContextConverter
|
||||
BinaryTreeDirectionDispatcherClojure BinaryTreeDirection
|
||||
));
|
||||
_mut_switch!(_direction_selector!(
|
||||
DirectedBinaryTreeRelationContextFromBaseContextConverter
|
||||
DirectedBinaryTreeDirectionDispatcherClojure DirectedBinaryTreeDirection
|
||||
));
|
||||
Loading…
Reference in New Issue
Block a user