CwUnit/Libsrc/ctQueue.inc at master · MarkGoldberg/CwUnit (github.com)
( Note: someday, I’ll create a repo for just ctQueue )
For your example, I threw the following together, I’d likely rename some things, and I’d also normally derive .ToString which is called by .Dump, which is very useful for debugging the contents of queues via OutputDebugString
Parent List --v
INCLUDE('ctQueue.inc'),ONCE
gtParentList GROUP,TYPE
ParentProperty STRING(50)
Children &ctQ_ChildList
END
qtParentList QUEUE(gtParentList),TYPE
END
ctQ_ParentList CLASS(ctQueue),TYPE,MODULE('ctQ_ParentList.clw'),LINK('ctQ_ParentList.clw')
Q &qtParentList
!------------------------
CONSTRUCT PROCEDURE()
Del PROCEDURE(),DERIVED
Add PROCEDURE(STRING xProperty),LONG,PROC
END
!for the 'ctQ_ParentList.clw'
MEMBER()
INCLUDE('ctQ_ParentList.inc'),ONCE
MAP
END
!=======================================
ctQ_ParentList.CONSTRUCT PROCEDURE()
CODE
SELF.Q &= NEW qtParentList
CLEAR(SELF.Q)
SELF.BaseQ &= SELF.Q
!=======================================
ctQ_ParentList.Del PROCEDURE()!,DERIVED
CODE
DISPOSE(SELF.Q.Children)
PARENT.Del()
!=======================================
ctQ_ParentList.Add PROCEDURE(STRING xProperty)
CODE
SELF.Q.ParentProperty = xProperty
SELF.Q.Children &= new ctQ_Childlist
ADD(SELF.Q)
RETURN ErrorCode()
ChildList --v
INCLUDE('ctQueue.inc'),ONCE
gtChildList GROUP,TYPE
ChildPropery STRING(50)
GrandChildren &ctQ_GrandChildren
END
qtChildList QUEUE(gtChildList),TYPE
END
ctQ_ChildList CLASS(ctQueue),TYPE,MODULE('ctQ_ChildList.clw'),LINK('ctQ_ChildList.clw')
Q &qtChildList
!------------------------
CONSTRUCT PROCEDURE()
Del PROCEDURE(),DERIVED
Add PROCEDURE(STRING xProperty),LONG,PROC
END
!for the 'ctQ_ChildList.clw'
MEMBER()
INCLUDE('ctQ_ChildList.inc'),ONCE
MAP
END
!=======================================
ctQ_ChildList.CONSTRUCT PROCEDURE()
CODE
SELF.Q &= NEW qtChildList
CLEAR(SELF.Q)
SELF.BaseQ &= SELF.Q
!=======================================
ctQ_ChildList.Del PROCEDURE()!,DERIVED
CODE
DISPOSE(SELF.Q.GrandChildren)
PARENT.Del()
!=======================================
ctQ_ChildList.Add PROCEDURE(STRING xProperty)
CODE
SELF.Q.ChildProperty = xProperty
SELF.Q.GrandChildren &= new ctQ_GrandChildList
ADD(SELF.Q)
RETURN ErrorCode()
GrandChild --v
INCLUDE('ctQueue.inc'),ONCE
gtGrandChildren GROUP,TYPE
GrandChildrenProperty STRING(50)
END
qtGrandChildren QUEUE(gtGrandChildren),TYPE
END
ctQ_GrandChildren CLASS(ctQueue),TYPE,MODULE('ctQ_GrandChildren.clw'),LINK('ctQ_GrandChildren.clw')
Q &qtGrandChildren
!------------------------
CONSTRUCT PROCEDURE()
Add PROCEDURE(STRING xProperty),LONG,PROC
END
!for the 'ctQ_GrandChildren.clw'
MEMBER()
INCLUDE('ctQ_GrandChildren.inc'),ONCE
MAP
END
!=======================================
ctQ_GrandChildren.CONSTRUCT PROCEDURE()
CODE
SELF.Q &= NEW qtGrandChildren
CLEAR(SELF.Q)
SELF.BaseQ &= SELF.Q
!=======================================
ctQ_GrandChildren.Add PROCEDURE(STRING xProperty)
CODE
SELF.Q.GrandChildrenProperty = xProperty
ADD(SELF.Q)
RETURN ErrorCode()
Here’s a very simple use of the classes
note: i’ll usually write a .Find method
I added the Grands reference as an example of using a short hand reference once the nesting gets a bit deep
MAP
END
INCLUDE('ctQ_ParentList.inc'),ONCE
Parents ctQ_ParentList
Grands &ctQ_GrandChildren
CODE
Parents.Add('Beatrice')
Parents.Q.Children.Add('Grace')
Parents.Q.Children.Q.GrandChildren.Add('Lora')
Parents.Q.Children.Add('Howard')
Grands &= Parents.Q.Children.Q.GrandChildren
Grands.Add('Julie')
Grands.Add('Mark')
Grands.Add('Deborah')