Hello,
Here the example:
Code:
EnableExplicit
Structure tJOB
JobID.i
JobKey.s
*Parent.tJOB_CATEGORY
DataType.i
DataSize.i
*JobData
EndStructure
Structure tJOB_CATEGORY
CategoryName.s
List Jobs.tJOB()
EndStructure
Global NewMap JobCategories.tJOB_CATEGORY()
Global NewMap *Jobs.tJOB()
Procedure AddJob( Category.s, JobData )
Static JobID
Protected JobKey.s
Protected *Category.tJOB_CATEGORY, *NewJob.tJOB
*Category = FindMapElement( JobCategories(), Category )
If Not *Category
*Category = AddMapElement( JobCategories(), Category )
*Category\CategoryName = Category
EndIf
Repeat
JobID + 1
JobKey = Str(JobID)
Until Not FindMapElement( *Jobs(), JobKey )
*NewJob = AddElement( *Category\Jobs() )
*Jobs( JobKey ) = *NewJob
; With *NewJob
; With *Category\Jobs()
With *Jobs( JobKey )
\JobID = JobID
\JobKey = JobKey
\JobData = JobData
\Parent = *Category
EndWith
ProcedureReturn JobID
EndProcedure
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )
Debug LSet("",100,"-")
Debug "Access to jobs over the lists in the category structure."
Debug "The categories are maintained in a map JobCategories()."
ResetMap( JobCategories() )
While NextMapElement( JobCategories() )
With JobCategories()
Debug Str(ListSize(\Jobs())) + " jobs in category " + JobCategories()\CategoryName
ForEach \Jobs()
Debug " Job " + Str(\Jobs()\JobID) + " // JobData = " + Str(\Jobs()\JobData) + " // cateogory = " + \Jobs()\Parent\CategoryName
Next
EndWith
Wend
Debug ""
Debug LSet("",100,"-")
Debug "Access to the list items over the pointers,"
Debug "which are stored in the map *Jobs()"
Debug "Access to single items is possible using the JobID!"
ResetMap( *Jobs() )
While NextMapElement( *Jobs() )
With *Jobs()
Debug "-"
Debug "MapKey = " + MapKey(*Jobs())
Debug "JobKey = " + \JobKey
; ==> VERY STRANGE: only empty lines are print to the debug window!
Debug "JobID = " + Str(\JobID)
Debug "Data = " + Str(\JobData)
Debug "Parent = " + Str(\Parent)
EndWith
Wend
The single items of the list in the structure tJOB_CATEGORY contain job information. The size of one list element is SizeOf(tJOB).
In the example a pointer of each job element (independent of the category) is stored in the Map *Jobs.tJob(). The single elements in this map however have the size of an pointer (Integer) and not the size SizeOf(tJOB). This is a map of pointers to tJOB items.
Sadly there seems to be a bug, if you access the single job items over the map. You will get the wrong data even though inside the procedure AddJob the data is set using the map pointer.
Is the use of "Map *Job.tSTRUCTURE_NAME()" allowed to create a map of pointers to structured list elements?
cu, guido