Anyone? I've tried anything.
The iterators work fine for dumping just the keys, but otherwise I'm lost :)
Thanks in advance
The iterators work fine for dumping just the keys, but otherwise I'm lost :)
Thanks in advance
Type TTest Field ID:Int Field Name:String Function Create:TTest(ID:Int , Name:String) Local T:TTest = New TTest T.ID = ID T.Name = Name Return T End Function Method ToString:String() Return ID + " , " + Name End Method End Type Local Map:TMap = New TMap Map.Insert("test1" , TTest.Create(1 , "Test1") ) Map.Insert("test2" , TTest.Create(2 , "Test2") ) Map.Insert("test3" , TTest.Create(3 , "Test3") ) Map.Insert("test4" , TTest.Create(4 , "Test4") ) Map.Insert("test5" , TTest.Create(5 , "Test5") ) 'Getting all Keys For Local S:String = EachIn Map.Keys() Print S Next 'Getting All Values For Local T:TTest = EachIn MAp.Values() Print T.ToString() Next 'Receiving The Node for 1 special Key Local N:TNode = Map._FindNode("test3") Print String(N._Key) + " : " + TTest(N._Value).ToString()
Strict Global testmap:tmap Global tempstring1:String Global tempstring2:String testmap = New tmap tempstring1 = "test" tempstring2 = "54" testmap.insert( "test", tempstring2 ) Print String(testmap.valueforkey( "test" )) testmap.insert( "wibbleding", "66" ) Print String(testmap.valueforkey( "wibbleding" )) Global Enumer:TEnumer Enumer = testmap.keys() 'ObjectEnumerator() returns an enum object. NextObject() is an overridden function that exists in 'TKeyEnum and TValueEnum, both extended from TNodeEnum. TEnumer has a field, _enum , which is of type 'TNodeEnum. TMap.Keys() and TMap.Values() both return a TEnumer whos _enum field is filled with 'either a TKeyEnum or TValueEnum object, respectively. 'And in this Case'since Enumer was created with the keys() function, it will return the key of each object in the map 'if values are desired instead, create the Enumer with tmap.values(). Then nextobject() will return 'all of the values in the map. While Enumer._enum.HasNext() Print "inside HasNext() loop" Print String(enumer.ObjectEnumerator().nextobject()) EndWhile 'this demonstrates how to cycle through a map and print all key,value pairs. Global Enumer2:TNodeEnum 'here, ObjectEnumerator() inside of the TMap returns a TNodeEnum pointing to the root node of the map Enumer2 = testmap.ObjectEnumerator() Local tempnode:tNode While Enumer2.HasNext() 'true while there are nodes left to traverse 'NextObject returns a node but returns it as type object so it has to be cast tempnode = tnode(Enumer2.NextObject()) 'cast the returned object to a tnode, since it is one Print "Key:" + String(tempnode._key) Print "Value:" + String(tempnode._value) EndWhile