- Сообщения
- 3,573
- Репутация
- 634
- Версия AutoIt
- 3.3.16.1
- Версия
- 1.0
Работа с Map по типу Scripting.Dictionary
_mSetValueKey - устанавливает значение существующему ключу
_mGetValueKey - возвращает значение ключа
_mGetValueKeys - возвращает значения всех ключей
_mExistsKey - проверяет существование ключа
_mCreateKey - создает ключ и присваивает ему значение
_mGetKeys - возвращает в массиве все ключи или возвращает количество ключей
_mRemoveKey - удаляет один ключ
_mRemoveKeys - удаляет все ключи
_mSetValueKey - устанавливает значение существующему ключу
_mGetValueKey - возвращает значение ключа
_mGetValueKeys - возвращает значения всех ключей
_mExistsKey - проверяет существование ключа
_mCreateKey - создает ключ и присваивает ему значение
_mGetKeys - возвращает в массиве все ключи или возвращает количество ключей
_mRemoveKey - удаляет один ключ
_mRemoveKeys - удаляет все ключи
Код:
#include-once
;~ _mCreateKey
;~ _mGetKeys
;~ _mRemoveKey
;~ _mRemoveKeys
;~ _mSetValueKey
;~ _mGetValueKey
;~ _mGetValueKeys
;~ _mExistsKey
;~ _mSetValueKey: The function assigns a value to an existing key.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ $vValue - New key value
;~ Return values: Success - 1, Failure - 0
;~ Function in Scripting.Dictionary - $oDict.Key($vKey) = $vNewKey
Func _mSetValueKey(ByRef $mMap, $vKey, $vValue)
If Not (VarGetType($mMap) = 'Map') Then Return 0
If MapExists($mMap, $vKey) Then
$mMap[$vKey] = $vValue
Return 1
Else
Return 0
EndIf
EndFunc ;==>_mSetValueKey
;~ _mGetValueKey: The function returns the value of the key.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ Return values: Success - key value, Failure - 0
;~ Function in Scripting.Dictionary - $vValue = $oDict.Item($vKey)
Func _mGetValueKey($mMap, $vKey)
If Not (VarGetType($mMap) = 'Map') Then Return 0
If MapExists($mMap, $vKey) Then Return $mMap[$vKey]
Return 0
EndFunc ;==>_mGetValueKey
;~ _mGetValueKeys: The function returns the values of all keys.
;~ $mMap - Map variable
;~ Return values: Success - Array of key values (use UBound($Array)), Failure - 0
;~ Function in Scripting.Dictionary - $Array = $oDict.Items()
Func _mGetValueKeys($mMap)
If Not (VarGetType($mMap) = 'Map') Then Return 0
Local $aKeys = MapKeys($mMap)
Local $aKeysValue[UBound($aKeys)]
For $i = 0 To UBound($aKeys) - 1
$aKeysValue[$i] = $mMap[$aKeys[$i]]
Next
Return $aKeysValue
EndFunc ;==>_mGetValueKeys
;~ _mExistsKey: The function checks for the existence of a key.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ Return values: Success - 1, Failure - 0
;~ Function in Scripting.Dictionary - $fBool = $oDict.Exists($vKey)
Func _mExistsKey($mMap, $vKey)
If Not (VarGetType($mMap) = 'Map') Then Return 0
If MapExists($mMap, $vKey) Then Return 1
Return 0
EndFunc ;==>_mExistsKey
;~ _mCreateKey: The function creates a new key and assigns it a value.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ $vValue - key value
;~ Return values: Success - 1, Failure - 0
;~ Function in Scripting.Dictionary - $oDict.Add($vKey, $vValue)
Func _mCreateKey(ByRef $mMap, $vKey, $vValue = '')
If Not (VarGetType($mMap) = 'Map') Then Return 0
If Not MapExists($mMap, $vKey) Then
$mMap[$vKey] = $vValue
Return 1
Else
Return 0
EndIf
EndFunc ;==>_mCreateKey
;~ _mGetKeys: The function returns the names of all keys.
;~ $mMap - Map variable
;~ $iCount = 0 : return array of keys; Function in Scripting.Dictionary - $Array = $oDict.Keys()
;~ $iCount = 1 : return the number of keys; Function in Scripting.Dictionary - $iCount = $oDict.Count()
;~ Failure - return 0
Func _mGetKeys($mMap, $iCount = 0)
If Not (VarGetType($mMap) = 'Map') Then Return 0
If $iCount Then
Return UBound(MapKeys($mMap))
Else
Return MapKeys($mMap)
EndIf
EndFunc ;==>_mGetKeys
;~ _mRemoveKey: The function deletes the selected key.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ Return values: Success - 1, Failure - 0
;~ Function in Scripting.Dictionary - $oDict.Remove($vKey)
Func _mRemoveKey(ByRef $mMap, $vKey)
If Not (VarGetType($mMap) = 'Map') Then Return 0
If MapExists($mMap, $vKey) Then Return MapRemove($mMap, $vKey)
Return 0
EndFunc ;==>_mRemoveKey
;~ _mRemoveKeys: The function deletes all keys.
;~ $mMap - Map variable
;~ $vKey - Key name
;~ Return values: Success - 1, Failure - 0
;~ Function in Scripting.Dictionary - $oDict.RemoveAll()
Func _mRemoveKeys(ByRef $mMap)
If Not (VarGetType($mMap) = 'Map') Then Return 0
Local $aKeys = MapKeys($mMap)
If Not UBound($aKeys) Then Return 0
For $Key In $aKeys
MapRemove($mMap, $Key)
Next
Return 1
EndFunc ;==>_mRemoveKeys
;~ ---------------------------------------------------------------------
;~ Создание вложенных Map объектов
;~ #include <Array.au3>
;~ Local $Map[], $getmap, $a, $b, $setar[2], $c, $d, $getkeys, $getmap1
;~ Local $ar1[7] = [1, 2, 3, 4, 5, 6, 7]
;~ Local $ar2[8] = [8, 7, 6, 5, 4, 1, 2, 3]
;~ For $i = 0 To 1
;~ _PageCreate($Map, 'page' & $i); создаем ключ в основном Map, значение ключа это массив, в котором два Map
;~ $getmap = _mGetValueKey($Map, 'page' & $i); получаем значение ключа
;~ $a = $getmap[0]; первый Мар
;~ $b = $getmap[1]; второй Мар
;~ _mCreateKey($a, 'Key' & $i, $ar1); создаем в первом дочернем Мэр один ключ со значением
;~ _mCreateKey($b, 'Key' & $i + 1, $ar2); создаем во втором дочернем Мэр один ключ со значением
;~ ; помещамем их в массив
;~ $setar[0] = $a
;~ $setar[1] = $b
;~ _mSetValueKey($Map, 'page' & $i, $setar); обновляем значение основного ключа 'page' & $i
;~ Next
;~ $getkeys = _mGetKeys($Map)
;~ _ArrayDisplay($getkeys, 'all keys')
;~ For $i = 0 To UBound($getkeys) - 1
;~ $getmap1 = _mGetValueKey($Map, 'page' & $i)
;~ _ArrayDisplay($getmap1, 'page' & $i)
;~ $c = $getmap1[0]
;~ $d = $getmap1[1]
;~ $getkeys = _mGetKeys($c)
;~ _ArrayDisplay($getkeys, 'map & keys in $c')
;~ $getkeys = _mGetKeys($d)
;~ _ArrayDisplay($getkeys, 'map & keys in $d')
;~ _ArrayDisplay(_mGetValueKey($c, 'Key' & $i), 'value & keys in $c')
;~ _ArrayDisplay(_mGetValueKey($d, 'Key' & $i + 1), 'value & keys in $d')
;~ Next
;~ Func _PageCreate(ByRef $mMap, $vKey); создает вложенные Map
;~ Local $mMap1[], $mMap2[], $aMap[2]
;~ $aMap[0] = $mMap1
;~ $aMap[1] = $mMap2
;~ _mCreateKey($mMap, $vKey, $aMap)
;~ EndFunc ;==>_PageCreate
Вложения
Последнее редактирование: