@PureLeo and @Demivec thanks for your replies.
I think i really messed up on communicating this.
I'm not trying to get a pointer to an element inside a map.
Neither do i want to copy a map.
What i'm looking for is to setup an alias to a map.
I want to point that alias at one map or another based on some logic, and then subsequently work with that map using the alias
Assuming the notation below were correct, which it is not i'd want to do the following
Code: Select all
; one real map
NewMap a.s()
; another real map
NewMap b.s()
; a pointer to a map
NewMap *pt.s()
; decide which real map to work with by pointing to pointer at it
*pt.s() = @a.s()
; now work with whatever map was chosen
*pt.s("key") = "valueA"
Debug *pt.s("key") ; should be "valueA"
; if i point my pointer at the other map
*pt.s() = @b.s()
; work with the map
*pt.s("key") = "valueB"
Debug *pt.s("key") ; should be "valueB"
; now point it back
*pt.s() = @a.s()
Debug *pt.s("key") ; should be "valueA"
I did manage to work around this by wrapping the map inside a structure, which is a rather ugly hack. That would look like this and works:
Code: Select all
; map struct
Structure ms
Map m.s()
EndStructure
; one real map struct
Define a.ms
; another real map struct
Define b.ms
; a pointer to a map struct
Define *pt.ms
; decide which real map to work with by pointing to pointer at it
*pt = @a
; now work with whatever map was chosen
*pt\m("key") = "valueA"
Debug *pt\m("key") ; should be "valueA"
; if i point my pointer at the other map
*pt = @b
; work with the map
*pt\m("key") = "valueB"
Debug *pt\m("key") ; should be "valueB"
; now point it back
*pt = @a
Debug *pt\m("key") ; should be "valueA"
So the question is, is there a way to do this with maps themselves, ideally without resorting to manual memory management.
Thanks
Mario