hmmm never thought to try it without the debugger, still need to create dummy map and the PB_FreeNumericMap macro will need some fix up for x86 linux and osx.
Code: Select all
;NumericMap hack for structured Numeric keyed Maps
;windows linux osx
NewMap dummy()
FreeMap(dummy())
Import ""
PB_InitMap()
PB_NewNumericMap(ElementSize.i,*StructureMap,*Address,HashTabelSize.l);
PB_FreeMap(*Map) ;
PB_ResetMap(*Map) ;
PB_ClearMap(*Map) ;
PB_MapSize(*Map) ;
PB_PushMapPosition(*map) ;
PB_PopMapPosition(*map) ;
PB_NextMapElement(*Map) ;
PB_FindNumericMapElement(*Map,Key.i) ;
PB_AddNumericMapElement(*Map,Key.i) ;
PB_AddNumericMapElement2(*Map,Key.i,ElementCheck=#PB_Map_ElementCheck);
PB_DeleteNumericMapElement2(*Map,Key.i) ;
PB_DeleteNumericMapElement(*Map) ;
PB_CopyMap(*Map,*DestinationMap) ;
PB_CopyMap2(*Map,*DestinationMap,Clear.l) ;
EndImport
Macro PB_FreeNumericMap(pmap)
EnableASM
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
PUSH pmap
POP rdi
CALL PB_FreeMap
CompilerElse
PUSH pmap
CALL _PB_FreeMap@4 ;might need changing for x86 linux osx
CompilerEndIf
DisableASM
EndMacro
Macro NewNumericMap(pmap,HashTableSize,StructureType,IsStructure=0)
Global structadr=0
EnableASM
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
CompilerIf IsStructure
lea rax,[s_#StructureType]
mov [v_structadr],rax
CompilerEndIf
CompilerElse
CompilerIf IsStructure
lea eax,[s_#StructureType]
mov [v_structadr],eax
CompilerEndIf
CompilerEndIf
DisableASM
PB_NewNumericMap(SizeOf(StructureType),structadr,@pmap,HashTableSize)
EndMacro
Procedure NumericMapkey(*Map)
Protected ele,key
ele = PeekI(*map)
key = PeekI(ele+SizeOf(Integer))
ProcedureReturn key
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
;Note you need to use a structured element pointer even for native types
OpenConsole()
;PB_InitMap()
Structure foo
List controls.i()
i.i
s.s
EndStructure
Procedure test()
Protected mp, *el.foo
NewNumericMap(mp,512,foo,#PB_Structure) ;create the map and pass map variable, number of elements, the name of the structure
*el = PB_AddNumericMapElement(mp,123)
AddElement(*el\controls())
*el\controls() = 111
AddElement(*el\controls())
*el\controls() = 112
*el\i = 123
*el\s = "Hello"
;
*el = PB_AddNumericMapElement2(mp,345)
AddElement(*el\controls())
*el\controls() = 113
AddElement(*el\controls())
*el\controls() = 114
*el\i = 345
*el\s = "World"
;
*el = PB_FindNumericMapElement(mp,123)
ForEach *el\controls()
PrintN( "list Controls " + *el\controls())
Next
PrintN( "integer " + *el\i)
PrintN( "string " + *el\s)
*el = PB_FindNumericMapElement(mp,345)
ForEach *el\controls()
PrintN( "list Controls " + *el\controls())
Next
PrintN( "integer " + *el\i)
PrintN( "string " + *el\s)
PrintN( "+++++++++++")
PrintN( "walk the map")
PrintN( "+++++++++++")
PB_ResetMap(mp)
Repeat
*el = PB_NextMapElement(mp)
If *el
PrintN( "mapkey " + NumericMapkey(mp))
ForEach *el\controls()
PrintN( "list Controls " + *el\controls())
Next
PrintN( "integer " + *el\i)
PrintN( "string " + *el\s)
EndIf
Until *el=0
PrintN( "++++++++++++++")
PrintN( "clear map")
PB_ClearMap(mp);
PB_ResetMap(mp)
Repeat
*el = PB_NextMapElement(mp)
If *el
PrintN( "mapkey " + NumericMapkey(mp))
ForEach *el\controls()
PrintN( "list Controls " + *el\controls())
Next
PrintN( "integer " + *el\i)
PrintN( "string " + *el\s)
EndIf
Until *el=0
PrintN( "should be nothing")
PB_FreeNumericMap(mp)
PrintN( "++++++++++++")
PrintN( "test with a native type via pointer")
Protected *elf.float
NewNumericMap(mp,512,float) ;create the map and pass map variable, number of elements, the name of the structure
*elf = PB_AddNumericMapElement(mp,123)
*elf\f = #PI
*elf = PB_AddNumericMapElement(mp,345)
*elf\f = 2*#PI
*elf = PB_FindNumericMapElement(mp,123)
PrintN(StrF(*elf\f))
*elf = PB_FindNumericMapElement(mp,345)
If *elf
PrintN(StrF(*elf\f))
EndIf
PrintN(Str(NumericMapkey(mp)))
PB_FreeNumericMap(mp)
EndProcedure
test()
Input()
CompilerEndIf