From f63e012aeaba7a54c8cc5905e367950f62fd5a6d Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Sun, 28 Dec 2025 17:54:46 +0300 Subject: [PATCH] Missed root getter/setter support for wrappers --- src/_common_macros.rs | 33 ++++++++++++ .../_directed_common_macros.rs | 39 ++++++++++++++ src/directed_context/dynamic_wrapper.rs | 42 ++++----------- src/directed_context/fixed_wrapper.rs | 54 +++++-------------- src/relation_context/converter.rs | 29 ++++------ 5 files changed, 104 insertions(+), 93 deletions(-) create mode 100644 src/directed_context/_directed_common_macros.rs diff --git a/src/_common_macros.rs b/src/_common_macros.rs index 80fac2b..9a26d71 100644 --- a/src/_common_macros.rs +++ b/src/_common_macros.rs @@ -43,3 +43,36 @@ macro_rules! _delegate_parent_getter { } }; } + +macro_rules! _delegate_root_getter { + ($name:ident $($mut:tt)?) => { + impl BinaryTreeRootGetter + for $name<& $($mut)? Ctx> + { + fn getRoot(&self) -> Option { + return self.ctx.getRoot(); + } + } + }; +} + + +macro_rules! _delegate_root_relation_setter { + ($name:ident) => { + unsafe impl BinaryTreeRootRelationSetterContext + for $name<&mut Ctx> + { + fn xSetRootRelation(&mut self, newRoot: Option) { + self.ctx.xSetRootRelation(newRoot) + } + + fn setRootRelation(&mut self, newRoot: Self::NodeRef) { + self.ctx.setRootRelation(newRoot) + } + + fn clearRoot(&mut self) { + self.ctx.clearRoot() + } + } + }; +} \ No newline at end of file diff --git a/src/directed_context/_directed_common_macros.rs b/src/directed_context/_directed_common_macros.rs new file mode 100644 index 0000000..235ffa6 --- /dev/null +++ b/src/directed_context/_directed_common_macros.rs @@ -0,0 +1,39 @@ +macro_rules! _delegate_root_setter { + ($name:ident) => { + impl BinaryTreeRootSetter + for $name <&mut Ctx> + { + fn xSetRoot(&mut self, newRoot: Option) { + self.ctx.xSetRoot(newRoot); + } + + fn setRoot(&mut self, newRoot: Self::NodeRef) { + self.ctx.setRoot(newRoot); + } + + fn clearRoot(&mut self) { + self.ctx.clearRoot(); + } + } + }; +} + +macro_rules! _delegate_parent_setter { + ($name:ident) => { + unsafe impl BinaryTreeParentSetterContext + for $name<&mut Ctx> + { + fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { + self.ctx.xSetParent(node, newParent); + } + + fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef) { + self.ctx.setParent(node, newParent); + } + + fn clearParent(&mut self, node: Self::NodeRef) { + self.ctx.clearParent(node) + } + } + }; +} \ No newline at end of file diff --git a/src/directed_context/dynamic_wrapper.rs b/src/directed_context/dynamic_wrapper.rs index 8f69fb0..0fd41bf 100644 --- a/src/directed_context/dynamic_wrapper.rs +++ b/src/directed_context/dynamic_wrapper.rs @@ -3,6 +3,7 @@ use crate::base_context::{ BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, }; +use crate::base_context::{BinaryTreeRootGetter, BinaryTreeRootSetter}; use crate::directed_context::context::{ DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, }; @@ -12,6 +13,7 @@ use crate::relation_context::{ }; include!("../_common_macros.rs"); +include!("_directed_common_macros.rs"); pub struct DynamicDirectedBinaryTreeContextFromContext { ctx: CtxRef, @@ -46,10 +48,13 @@ _mut_switch!(_delegate_node_ref!( DynamicDirectedBinaryTreeContextFromContext )); -_mut_switch!(_delegate_parent_getter!( +_mut_switch!(_delegate_root_getter!( DynamicDirectedBinaryTreeContextFromContext )); +_mut_switch!(_delegate_parent_getter!( + DynamicDirectedBinaryTreeContextFromContext +)); impl DirectedBinaryTreeChildrenGetterContext for DynamicDirectedBinaryTreeContextFromContext<&Ctx> @@ -87,6 +92,9 @@ impl DirectedBinaryTreeChildrenGetterConte } } +_delegate_root_setter!(DynamicDirectedBinaryTreeContextFromContext); +_delegate_parent_setter!(DynamicDirectedBinaryTreeContextFromContext); + unsafe impl DirectedBinaryTreeChildrenSetterContext for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> { @@ -133,37 +141,7 @@ unsafe impl DirectedBinaryTreeChildrenSett } } -unsafe impl BinaryTreeParentSetterContext - for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> -{ - fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { - self.ctx.xSetParent(node, newParent); - } - - fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef) { - self.ctx.setParent(node, newParent); - } - - fn clearParent(&mut self, node: Self::NodeRef) { - self.ctx.clearParent(node) - } -} - -unsafe impl BinaryTreeRootRelationSetterContext - for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> -{ - fn xSetRootRelation(&mut self, newRoot: Option) { - self.ctx.xSetRootRelation(newRoot) - } - - fn setRootRelation(&mut self, newRoot: Self::NodeRef) { - self.ctx.setRootRelation(newRoot) - } - - fn clearRoot(&mut self) { - self.ctx.clearRoot() - } -} +_delegate_root_relation_setter!(DynamicDirectedBinaryTreeContextFromContext); unsafe impl DirectedBinaryTreeRelationSetterContext for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> diff --git a/src/directed_context/fixed_wrapper.rs b/src/directed_context/fixed_wrapper.rs index 2e53710..ffdc5d1 100644 --- a/src/directed_context/fixed_wrapper.rs +++ b/src/directed_context/fixed_wrapper.rs @@ -1,7 +1,8 @@ use crate::NodeRefContainer; use crate::base_context::{ BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, - BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, + BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter, + BinaryTreeRootSetter, }; use crate::directed_context::{ DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, @@ -12,6 +13,7 @@ use crate::relation_context::{ }; include!("../_common_macros.rs"); +include!("_directed_common_macros.rs"); pub struct FixedLeftDirectedBinaryTreeContextFromContext { ctx: CtxRef, @@ -27,6 +29,9 @@ _mut_switch!(_ctx_wrapper_constructor!(FixedRightDirectedBinaryTreeContextFromCo _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_parent_getter!(FixedLeftDirectedBinaryTreeContextFromContext)); _mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext)); @@ -53,27 +58,11 @@ _mut_switch!(_children_get!( FixedRightDirectedBinaryTreeContextFromContext getRightChild getLeftChild )); -macro_rules! _parent_set { - ($name:ident) => { - unsafe impl BinaryTreeParentSetterContext - for $name<&mut Ctx> - { - fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option) { - self.ctx.xSetParent(node, newParent); - } +_delegate_root_setter!(FixedLeftDirectedBinaryTreeContextFromContext); +_delegate_root_setter!(FixedRightDirectedBinaryTreeContextFromContext); - fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef) { - self.ctx.setParent(node, newParent); - } - - fn clearParent(&mut self, node: Self::NodeRef) { - self.ctx.clearParent(node) - } - } - }; -} -_parent_set!(FixedLeftDirectedBinaryTreeContextFromContext); -_parent_set!(FixedRightDirectedBinaryTreeContextFromContext); +_delegate_parent_setter!(FixedLeftDirectedBinaryTreeContextFromContext); +_delegate_parent_setter!(FixedRightDirectedBinaryTreeContextFromContext); macro_rules! _children_set { ( @@ -121,27 +110,8 @@ _children_set!( xSetLeftChild setLeftChild clearLeftChild ); -macro_rules! _root_relation_set { - ($name:ident) => { - unsafe impl BinaryTreeRootRelationSetterContext - for $name<&mut Ctx> - { - fn xSetRootRelation(&mut self, newRoot: Option) { - self.ctx.xSetRootRelation(newRoot) - } - - fn setRootRelation(&mut self, newRoot: Self::NodeRef) { - self.ctx.setRootRelation(newRoot) - } - - fn clearRoot(&mut self) { - self.ctx.clearRoot() - } - } - }; -} -_root_relation_set!(FixedLeftDirectedBinaryTreeContextFromContext); -_root_relation_set!(FixedRightDirectedBinaryTreeContextFromContext); +_delegate_root_relation_setter!(FixedLeftDirectedBinaryTreeContextFromContext); +_delegate_root_relation_setter!(FixedRightDirectedBinaryTreeContextFromContext); macro_rules! _relation_set { ( diff --git a/src/relation_context/converter.rs b/src/relation_context/converter.rs index 21c9720..86abefa 100644 --- a/src/relation_context/converter.rs +++ b/src/relation_context/converter.rs @@ -1,7 +1,8 @@ use crate::NodeRefContainer; use crate::base_context::{ BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, - BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootSetter, + BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter, + BinaryTreeRootSetter, }; use crate::directed_context::{ DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, @@ -21,27 +22,17 @@ pub struct DirectedBinaryTreeRelationContextFromBaseContextConverter { ctx: CtxRef, } -_mut_switch!(_ctx_wrapper_constructor!( - BinaryTreeRelationContextFromBaseContextConverter -)); -_mut_switch!(_ctx_wrapper_constructor!( - DirectedBinaryTreeRelationContextFromBaseContextConverter -)); +_mut_switch!(_ctx_wrapper_constructor!(BinaryTreeRelationContextFromBaseContextConverter)); +_mut_switch!(_ctx_wrapper_constructor!(DirectedBinaryTreeRelationContextFromBaseContextConverter)); -_mut_switch!(_delegate_node_ref!( - BinaryTreeRelationContextFromBaseContextConverter -)); -_mut_switch!(_delegate_node_ref!( - DirectedBinaryTreeRelationContextFromBaseContextConverter -)); +_mut_switch!(_delegate_node_ref!(BinaryTreeRelationContextFromBaseContextConverter)); +_mut_switch!(_delegate_node_ref!(DirectedBinaryTreeRelationContextFromBaseContextConverter)); +_mut_switch!(_delegate_root_getter!(BinaryTreeRelationContextFromBaseContextConverter)); +_mut_switch!(_delegate_root_getter!(DirectedBinaryTreeRelationContextFromBaseContextConverter)); -_mut_switch!(_delegate_parent_getter!( - BinaryTreeRelationContextFromBaseContextConverter -)); -_mut_switch!(_delegate_parent_getter!( - DirectedBinaryTreeRelationContextFromBaseContextConverter -)); +_mut_switch!(_delegate_parent_getter!(BinaryTreeRelationContextFromBaseContextConverter)); +_mut_switch!(_delegate_parent_getter!(DirectedBinaryTreeRelationContextFromBaseContextConverter)); macro_rules! _children_get { ($name:ident $ctx:ident $d1:ident $d2:ident $($mut:tt)? ) => {