Browse Source

Added index operators to maps.

woollybah 6 years ago
parent
commit
17b1086b59

+ 56 - 0
docs/api/brl/brl.map/tintmap.md

@@ -7,6 +7,62 @@ sidebar_label: TIntMap
 A key/value (Int/Object) map.
 
 
+## Operators
+
+### `Method Operator[]:Object(key:Int)`
+
+Finds a value given a <b>key</b> using index syntax.
+
+If the map does not contain <b>key</b>, a [Null](../../../brl/brl.blitz/#null) object is returned.
+
+
+#### Returns
+The value associated with <b>key</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TIntMap = New TIntMap
+
+map.Insert(1, "Hello")
+map.Insert(2, "World")
+
+For Local k:TIntKey = EachIn map.Keys()
+	Print k.value + " = " + String(map[k.value]) ' retrieve value using index operator
+Next
+```
+<br/>
+
+### `Method Operator[]=(key:Int, value:Object)`
+
+Inserts a key/value pair into the map using index syntax.
+
+If the map already contains <b>key</b>, its value is overwritten with <b>value</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TIntMap = New TIntMap
+
+map[1] = "Hello" ' insert value using index operator
+map[2] = "World"
+
+For Local k:TIntKey = EachIn map.Keys()
+	Print k.value + " = " + String(map.ValueForKey(k.value))
+Next
+```
+<br/>
+
 ## Methods
 
 ### `Method Clear()`

+ 56 - 0
docs/api/brl/brl.map/tmap.md

@@ -7,6 +7,62 @@ sidebar_label: TMap
 An key/value (Object/Object) map backed by a Red/Black tree.
 
 
+## Operators
+
+### `Method Operator[]:Object(key:Object)`
+
+Finds a value given a <b>key</b> using index syntax.
+
+If the map does not contain <b>key</b>, a [Null](../../../brl/brl.blitz/#null) object is returned.
+
+
+#### Returns
+The value associated with <b>key</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TMap = New TMap
+
+map.Insert("one", "Hello")
+map.Insert("two", "World")
+
+For Local s:String = EachIn map.Keys()
+	Print s + " = " + String(map[s]) ' retrieve value using index operator
+Next
+```
+<br/>
+
+### `Method Operator[]=(key:Object, value:Object)`
+
+Inserts a key/value pair into the map using index syntax.
+
+If the map already contains <b>key</b>, its value is overwritten with <b>value</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TMap = New TMap
+
+map["one"] = "Hello" ' insert value using index operator
+map["two"] = "World"
+
+For Local s:String = EachIn map.Keys()
+	Print s + " = " + String(map.ValueForKey(s))
+Next
+```
+<br/>
+
 ## Methods
 
 ### `Method Clear()`

+ 56 - 0
docs/api/brl/brl.map/tptrmap.md

@@ -7,6 +7,62 @@ sidebar_label: TPtrMap
 A key/value (Byte Ptr/Object) map.
 
 
+## Operators
+
+### `Method Operator[]:Object(key:Byte Ptr)`
+
+Finds a value given a <b>key</b> using index syntax.
+
+If the map does not contain <b>key</b>, a [Null](../../../brl/brl.blitz/#null) object is returned.
+
+
+#### Returns
+The value associated with <b>key</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TPtrMap = New TPtrMap
+
+map.Insert(Byte Ptr(1), "Hello")
+map.Insert(Byte Ptr(2), "World")
+
+For Local k:TPtrKey = EachIn map.Keys()
+	Print Int(k.value) + " = " + String(map[k.value]) ' retrieve value using index operator
+Next
+```
+<br/>
+
+### `Method Operator[]=(key:Byte Ptr, value:Object)`
+
+Inserts a key/value pair into the map using index syntax.
+
+If the map already contains <b>key</b>, its value is overwritten with <b>value</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TPtrMap = New TPtrMap
+
+map[Byte Ptr(1)] = "Hello" ' insert value using index operator
+map[Byte Ptr(2)] = "World"
+
+For Local k:TPtrKey = EachIn map.Keys()
+	Print Int(k.value) + " = " + String(map.ValueForKey(k.value))
+Next
+```
+<br/>
+
 ## Methods
 
 ### `Method Clear()`

+ 56 - 0
docs/api/brl/brl.map/tstringmap.md

@@ -7,6 +7,62 @@ sidebar_label: TStringMap
 A key/value (String/Object) map.
 
 
+## Operators
+
+### `Method Operator[]:Object(key:String)`
+
+Finds a value given a <b>key</b> using index syntax.
+
+If the map does not contain <b>key</b>, a [Null](../../../brl/brl.blitz/#null) object is returned.
+
+
+#### Returns
+The value associated with <b>key</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TStringMap = New TStringMap
+
+map.Insert("one", "Hello")
+map.Insert("two", "World")
+
+For Local s:String = EachIn map.Keys()
+	Print s + " = " + String(map[s]) ' retrieve value using index operator
+Next
+```
+<br/>
+
+### `Method Operator[]=(key:String, value:Object)`
+
+Inserts a key/value pair into the map using index syntax.
+
+If the map already contains <b>key</b>, its value is overwritten with <b>value</b>.
+
+
+#### Example
+```blitzmax
+SuperStrict
+
+Framework brl.standardio
+Import brl.map
+
+Local map:TStringMap = New TStringMap
+
+map["one"] = "Hello" ' insert value using index operator
+map["two"] = "World"
+
+For Local s:String = EachIn map.Keys()
+	Print s + " = " + String(map.ValueForKey(s))
+Next
+```
+<br/>
+
 ## Methods
 
 ### `Method Clear()`