Missed root getter/setter support for wrappers

This commit is contained in:
Andrew Golovashevich 2025-12-28 17:54:46 +03:00
parent cfa721f501
commit f63e012aea
5 changed files with 104 additions and 93 deletions

View File

@ -43,3 +43,36 @@ macro_rules! _delegate_parent_getter {
} }
}; };
} }
macro_rules! _delegate_root_getter {
($name:ident $($mut:tt)?) => {
impl<Ctx: BinaryTreeRootGetter> BinaryTreeRootGetter
for $name<& $($mut)? Ctx>
{
fn getRoot(&self) -> Option<Self::NodeRef> {
return self.ctx.getRoot();
}
}
};
}
macro_rules! _delegate_root_relation_setter {
($name:ident) => {
unsafe impl<Ctx: BinaryTreeRootRelationSetterContext> BinaryTreeRootRelationSetterContext
for $name<&mut Ctx>
{
fn xSetRootRelation(&mut self, newRoot: Option<Self::NodeRef>) {
self.ctx.xSetRootRelation(newRoot)
}
fn setRootRelation(&mut self, newRoot: Self::NodeRef) {
self.ctx.setRootRelation(newRoot)
}
fn clearRoot(&mut self) {
self.ctx.clearRoot()
}
}
};
}

View File

@ -0,0 +1,39 @@
macro_rules! _delegate_root_setter {
($name:ident) => {
impl<Ctx: BinaryTreeRootSetter> BinaryTreeRootSetter
for $name <&mut Ctx>
{
fn xSetRoot(&mut self, newRoot: Option<Self::NodeRef>) {
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<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
for $name<&mut Ctx>
{
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
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)
}
}
};
}

View File

@ -3,6 +3,7 @@ use crate::base_context::{
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection, BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeDirection,
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext,
}; };
use crate::base_context::{BinaryTreeRootGetter, BinaryTreeRootSetter};
use crate::directed_context::context::{ use crate::directed_context::context::{
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
}; };
@ -12,6 +13,7 @@ use crate::relation_context::{
}; };
include!("../_common_macros.rs"); include!("../_common_macros.rs");
include!("_directed_common_macros.rs");
pub struct DynamicDirectedBinaryTreeContextFromContext<CtxRef> { pub struct DynamicDirectedBinaryTreeContextFromContext<CtxRef> {
ctx: CtxRef, ctx: CtxRef,
@ -46,10 +48,13 @@ _mut_switch!(_delegate_node_ref!(
DynamicDirectedBinaryTreeContextFromContext DynamicDirectedBinaryTreeContextFromContext
)); ));
_mut_switch!(_delegate_parent_getter!( _mut_switch!(_delegate_root_getter!(
DynamicDirectedBinaryTreeContextFromContext DynamicDirectedBinaryTreeContextFromContext
)); ));
_mut_switch!(_delegate_parent_getter!(
DynamicDirectedBinaryTreeContextFromContext
));
impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterContext
for DynamicDirectedBinaryTreeContextFromContext<&Ctx> for DynamicDirectedBinaryTreeContextFromContext<&Ctx>
@ -87,6 +92,9 @@ impl<Ctx: BinaryTreeChildrenGetterContext> DirectedBinaryTreeChildrenGetterConte
} }
} }
_delegate_root_setter!(DynamicDirectedBinaryTreeContextFromContext);
_delegate_parent_setter!(DynamicDirectedBinaryTreeContextFromContext);
unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSetterContext unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSetterContext
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
{ {
@ -133,37 +141,7 @@ unsafe impl<Ctx: BinaryTreeChildrenSetterContext> DirectedBinaryTreeChildrenSett
} }
} }
unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext _delegate_root_relation_setter!(DynamicDirectedBinaryTreeContextFromContext);
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
{
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
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<Ctx: BinaryTreeRootRelationSetterContext> BinaryTreeRootRelationSetterContext
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>
{
fn xSetRootRelation(&mut self, newRoot: Option<Self::NodeRef>) {
self.ctx.xSetRootRelation(newRoot)
}
fn setRootRelation(&mut self, newRoot: Self::NodeRef) {
self.ctx.setRootRelation(newRoot)
}
fn clearRoot(&mut self) {
self.ctx.clearRoot()
}
}
unsafe impl<Ctx: BinaryTreeRelationSetterContext> DirectedBinaryTreeRelationSetterContext unsafe impl<Ctx: BinaryTreeRelationSetterContext> DirectedBinaryTreeRelationSetterContext
for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx> for DynamicDirectedBinaryTreeContextFromContext<&mut Ctx>

View File

@ -1,7 +1,8 @@
use crate::NodeRefContainer; use crate::NodeRefContainer;
use crate::base_context::{ use crate::base_context::{
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
BinaryTreeRootSetter,
}; };
use crate::directed_context::{ use crate::directed_context::{
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
@ -12,6 +13,7 @@ use crate::relation_context::{
}; };
include!("../_common_macros.rs"); include!("../_common_macros.rs");
include!("_directed_common_macros.rs");
pub struct FixedLeftDirectedBinaryTreeContextFromContext<CtxRef> { pub struct FixedLeftDirectedBinaryTreeContextFromContext<CtxRef> {
ctx: CtxRef, ctx: CtxRef,
@ -27,6 +29,9 @@ _mut_switch!(_ctx_wrapper_constructor!(FixedRightDirectedBinaryTreeContextFromCo
_mut_switch!(_delegate_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext)); _mut_switch!(_delegate_node_ref!(FixedLeftDirectedBinaryTreeContextFromContext));
_mut_switch!(_delegate_node_ref!(FixedRightDirectedBinaryTreeContextFromContext)); _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!(FixedLeftDirectedBinaryTreeContextFromContext));
_mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext)); _mut_switch!(_delegate_parent_getter!(FixedRightDirectedBinaryTreeContextFromContext));
@ -53,27 +58,11 @@ _mut_switch!(_children_get!(
FixedRightDirectedBinaryTreeContextFromContext getRightChild getLeftChild FixedRightDirectedBinaryTreeContextFromContext getRightChild getLeftChild
)); ));
macro_rules! _parent_set { _delegate_root_setter!(FixedLeftDirectedBinaryTreeContextFromContext);
($name:ident) => { _delegate_root_setter!(FixedRightDirectedBinaryTreeContextFromContext);
unsafe impl<Ctx: BinaryTreeParentSetterContext> BinaryTreeParentSetterContext
for $name<&mut Ctx>
{
fn xSetParent(&mut self, node: Self::NodeRef, newParent: Option<Self::NodeRef>) {
self.ctx.xSetParent(node, newParent);
}
fn setParent(&mut self, node: Self::NodeRef, newParent: Self::NodeRef) { _delegate_parent_setter!(FixedLeftDirectedBinaryTreeContextFromContext);
self.ctx.setParent(node, newParent); _delegate_parent_setter!(FixedRightDirectedBinaryTreeContextFromContext);
}
fn clearParent(&mut self, node: Self::NodeRef) {
self.ctx.clearParent(node)
}
}
};
}
_parent_set!(FixedLeftDirectedBinaryTreeContextFromContext);
_parent_set!(FixedRightDirectedBinaryTreeContextFromContext);
macro_rules! _children_set { macro_rules! _children_set {
( (
@ -121,27 +110,8 @@ _children_set!(
xSetLeftChild setLeftChild clearLeftChild xSetLeftChild setLeftChild clearLeftChild
); );
macro_rules! _root_relation_set { _delegate_root_relation_setter!(FixedLeftDirectedBinaryTreeContextFromContext);
($name:ident) => { _delegate_root_relation_setter!(FixedRightDirectedBinaryTreeContextFromContext);
unsafe impl<Ctx: BinaryTreeRootRelationSetterContext> BinaryTreeRootRelationSetterContext
for $name<&mut Ctx>
{
fn xSetRootRelation(&mut self, newRoot: Option<Self::NodeRef>) {
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);
macro_rules! _relation_set { macro_rules! _relation_set {
( (

View File

@ -1,7 +1,8 @@
use crate::NodeRefContainer; use crate::NodeRefContainer;
use crate::base_context::{ use crate::base_context::{
BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext, BinaryTreeChildrenGetterContext, BinaryTreeChildrenSetterContext,
BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootSetter, BinaryTreeParentGetterContext, BinaryTreeParentSetterContext, BinaryTreeRootGetter,
BinaryTreeRootSetter,
}; };
use crate::directed_context::{ use crate::directed_context::{
DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext, DirectedBinaryTreeChildrenGetterContext, DirectedBinaryTreeChildrenSetterContext,
@ -21,27 +22,17 @@ pub struct DirectedBinaryTreeRelationContextFromBaseContextConverter<CtxRef> {
ctx: CtxRef, ctx: CtxRef,
} }
_mut_switch!(_ctx_wrapper_constructor!( _mut_switch!(_ctx_wrapper_constructor!(BinaryTreeRelationContextFromBaseContextConverter));
BinaryTreeRelationContextFromBaseContextConverter _mut_switch!(_ctx_wrapper_constructor!(DirectedBinaryTreeRelationContextFromBaseContextConverter));
));
_mut_switch!(_ctx_wrapper_constructor!(
DirectedBinaryTreeRelationContextFromBaseContextConverter
));
_mut_switch!(_delegate_node_ref!( _mut_switch!(_delegate_node_ref!(BinaryTreeRelationContextFromBaseContextConverter));
BinaryTreeRelationContextFromBaseContextConverter _mut_switch!(_delegate_node_ref!(DirectedBinaryTreeRelationContextFromBaseContextConverter));
));
_mut_switch!(_delegate_node_ref!(
DirectedBinaryTreeRelationContextFromBaseContextConverter
));
_mut_switch!(_delegate_root_getter!(BinaryTreeRelationContextFromBaseContextConverter));
_mut_switch!(_delegate_root_getter!(DirectedBinaryTreeRelationContextFromBaseContextConverter));
_mut_switch!(_delegate_parent_getter!( _mut_switch!(_delegate_parent_getter!(BinaryTreeRelationContextFromBaseContextConverter));
BinaryTreeRelationContextFromBaseContextConverter _mut_switch!(_delegate_parent_getter!(DirectedBinaryTreeRelationContextFromBaseContextConverter));
));
_mut_switch!(_delegate_parent_getter!(
DirectedBinaryTreeRelationContextFromBaseContextConverter
));
macro_rules! _children_get { macro_rules! _children_get {
($name:ident $ctx:ident $d1:ident $d2:ident $($mut:tt)? ) => { ($name:ident $ctx:ident $d1:ident $d2:ident $($mut:tt)? ) => {