This is something I need for a project, an image worth 1000 words :
A linked list of hooks to hang different elements so this is the hook code to do that :
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Hook
; File Name : Hook - OOP.pb
; File version: 1.0.1
; Programming : OK
; Programmed by : StarBootics
; Date : 10-04-2019
; Last Update : 29-10-2020
; PureBasic code : V5.70 LTS
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DeclareModule Hook
Interface Hook
GetTag.l()
GetPointer.i()
SetTag(P_Tag.l)
SetPointer(P_Pointer.i)
Free()
EndInterface
Declare.i New(P_Tag.l, P_Pointer.i)
EndDeclareModule
Module Hook
Structure Private_Members
VirtualTable.i
Tag.l
Pointer.i
EndStructure
Procedure.l GetTag(*This.Private_Members)
ProcedureReturn *This\Tag
EndProcedure
Procedure.i GetPointer(*This.Private_Members)
ProcedureReturn *This\Pointer
EndProcedure
Procedure SetTag(*This.Private_Members, P_Tag.l)
*This\Tag = P_Tag
EndProcedure
Procedure SetPointer(*This.Private_Members, P_Pointer.i)
*This\Pointer = P_Pointer
EndProcedure
Procedure Free(*This.Private_Members)
FreeStructure(*This)
EndProcedure
Procedure.i New(P_Tag.l, P_Pointer.i)
*This.Private_Members = AllocateStructure(Private_Members)
*This\VirtualTable = ?START_METHODS
SetTag(*This, P_Tag)
SetPointer(*This, P_Pointer)
ProcedureReturn *This
EndProcedure
DataSection
START_METHODS:
Data.i @GetTag()
Data.i @GetPointer()
Data.i @SetTag()
Data.i @SetPointer()
Data.i @Free()
END_METHODS:
EndDataSection
EndModule
CompilerIf #PB_Compiler_IsMainFile
Enumeration
#HOOK_TAG_DODECAHEDRON
#HOOK_TAG_SPHERE
#HOOK_TAG_CUBE
#HOOK_TAG_PYRAMID
EndEnumeration
Structure Dodecahedron
Volume.d
Size.d
Whatever.s
EndStructure
Structure Sphere
Volume.d
Radius.d
Whatever.s
EndStructure
Structure Cube
Volume.d
Size.d
Whatever.s
EndStructure
Structure Pyramid
Volume.d
Size.d
Whatever.s
EndStructure
NewList MyList.Hook::Hook()
AddElement(MyList())
MyList() = Hook::New(#HOOK_TAG_DODECAHEDRON, AllocateStructure(Dodecahedron))
AddElement(MyList())
MyList() = Hook::New(#HOOK_TAG_SPHERE, AllocateStructure(Sphere))
AddElement(MyList())
MyList() = Hook::New(#HOOK_TAG_CUBE, AllocateStructure(Cube))
AddElement(MyList())
MyList() = Hook::New(#HOOK_TAG_PYRAMID, AllocateStructure(Pyramid))
ForEach MyList()
Select MyList()\GetTag()
Case #HOOK_TAG_DODECAHEDRON
If MyList()\GetPointer() <> #Null
Debug "Dodecahedron"
EndIf
Case #HOOK_TAG_SPHERE
If MyList()\GetPointer() <> #Null
Debug "Sphere"
EndIf
Case #HOOK_TAG_CUBE
If MyList()\GetPointer() <> #Null
Debug "Cube"
EndIf
Case #HOOK_TAG_PYRAMID
If MyList()\GetPointer() <> #Null
Debug "Pyramid"
EndIf
EndSelect
Next
ForEach Mylist()
If MyList()\GetPointer() <> #Null
FreeStructure(MyList()\GetPointer())
EndIf
Mylist()\Free()
Next
FreeList(MyList())
CompilerEndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
StarBootics