#include "ycp/YCPBuiltinMap.h"
#include "ycp/YCPMap.h"
#include "ycp/YCPSymbol.h"
#include "ycp/YCPBoolean.h"
#include "ycp/YCPInteger.h"
#include "ycp/YCPCode.h"
#include "ycp/YCPVoid.h"
#include "ycp/StaticDeclaration.h"
#include "ycp/y2log.h"
Defines | |
#define | ETC 0, NULL, constTypePtr(), NULL |
#define | ETCf NULL, constTypePtr(), NULL |
Functions | |
static YCPValue | m_haskey (const YCPMap &map, const YCPValue &value) |
static YCPValue | m_filter (const YCPSymbol &key, const YCPSymbol &value, const YCPMap &map, const YCPCode &expr) |
static YCPValue | m_mapmap (const YCPSymbol &key, const YCPSymbol &value, const YCPMap &map, const YCPCode &expr) |
static YCPValue | m_maplist (const YCPSymbol &key, const YCPSymbol &value, const YCPMap &map, const YCPCode &expr) |
static YCPValue | m_unionmap (const YCPMap &map1, const YCPMap &map2) |
static YCPValue | m_addmap (const YCPMap &map, const YCPValue &key, const YCPValue &value) |
static YCPValue | m_changemap (YCPMap &map, const YCPValue &key, const YCPValue &value) |
static YCPValue | m_isempty (const YCPMap &m) |
static YCPValue | m_size (const YCPValue &map) |
static YCPValue | m_foreach (const YCPValue &key, const YCPValue &val, const YCPMap &map, const YCPCode &expr) |
static YCPValue | m_tomap (const YCPValue &v) |
static YCPValue | m_remove (const YCPMap &map, const YCPValue &key) |
Variables | |
StaticDeclaration | static_declarations |
#define ETC 0, NULL, constTypePtr(), NULL |
#define ETCf NULL, constTypePtr(), NULL |
static YCPValue m_addmap | ( | const YCPMap & | map, | |
const YCPValue & | key, | |||
const YCPValue & | value | |||
) | [static] |
add add-map Add a key/value pair to a map
Adds the key/value pair k : v
to the map MAP
and returns the newly Created map. If the key KEY
exists in KEY
, the old key/value pair is replaced with the new one. Functionality partly replaced with syntax: map map m = $["a":1]; m["b"] = 2; -> $["a":1, "b":2]
map | MAP | |
any | KEY | |
any | VALUE |
add ($["a": 17, "b": 11], "c", 2) -> $["a":17, "b":11, "c":2] add ($["a": 17, "b": 11], "b", 2) -> $["a":17, "b":2]
References YCPMap::functionalAdd(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
change change-map Change element pair in a map. Deprecated, use MAP[KEY] = VALUE. Before Code 9, this was used to change a map directly without creating a copy. Now it is a synonym for add.
map | MAP | |
any | KEY | |
any | VALUE |
change ($[.a: 17, .b: 11], .b, nil) -> $[.a:17, .b:nil].
References YCPMap::add(), YCPElement::isNull(), ycp2error, and ycpinternal.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
static YCPValue m_filter | ( | const YCPSymbol & | key, | |
const YCPSymbol & | value, | |||
const YCPMap & | map, | |||
const YCPCode & | expr | |||
) | [static] |
filter filter-map Filter a Map For each key/value pair of the map MAP
the expression EXPR
is evaluated in a new block, where the variable KEY
is assigned to the key and VALUE
to the value of the pair. If the expression evaluates to true, the key/value pair is appended to the returned map.
any | KEY | |
any | VALUE | |
map | MAP | |
blocl | EXPR |
References YCPMap::add(), YCPMap::begin(), YCPMap::end(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
static YCPValue m_foreach | ( | const YCPValue & | key, | |
const YCPValue & | val, | |||
const YCPMap & | map, | |||
const YCPCode & | expr | |||
) | [static] |
foreach foreach-map Process the content of a map For each key:value pair of the map MAP
the expression EXPR
is executed in a new block, where the variables KEY
is bound to the key and VALUE
is bound to the value. The return value of the last execution of exp is the value of the foreach
construct.
any | KEY | |
any | VALUE | |
map | MAP | |
any | EXPR |
foreach (integer k, integer v, $[1:1,2:4,3:9], { y2debug("v = %1", v); return v; }) -> 9
References YCPMap::begin(), YCPMap::end(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
haskey Check if map has a certain key
Determines whether the map MAP
contains a pair with the key KEY
. Returns true if this is true.
map | MAP | |
any | KEY |
haskey($["a":1, "b":2], "a") -> true haskey($["a":1, "b":2], "c") -> false
References YCPMap::hasKey(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
isempty isempty-map Returns whether the map m
is empty.
map | m Map |
m
Notice that the map m
must not be nil.
isempty($[]) -> true isempty($[ `host : "pandora" ]) -> false
References YCPMap::isEmpty().
Referenced by YCPBuiltinMap::YCPBuiltinMap().
static YCPValue m_maplist | ( | const YCPSymbol & | key, | |
const YCPSymbol & | value, | |||
const YCPMap & | map, | |||
const YCPCode & | expr | |||
) | [static] |
maplist maplist-map Maps an operation onto all elements key/value and create a list Maps an operation onto all elements key/value pairs of a map and thus creates a list.
For each key/value pair of the map MAP
the expression e
is evaluated in a new block, where the variable KEY
is assigned to the key and VALUE
to the value of the pair. The result is the list of those evaluations.
any | KEY | |
any | VALUE | |
map | MAP | |
block | EXPR |
maplist (`k, `v, $[1:"a", 2:"b"], { return [k+10, v+"x"]; }) -> [ [11, "ax"], [ 12, "bx" ] ]
References YCPList::add(), YCPMap::begin(), YCPMap::end(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
static YCPValue m_mapmap | ( | const YCPSymbol & | key, | |
const YCPSymbol & | value, | |||
const YCPMap & | map, | |||
const YCPCode & | expr | |||
) | [static] |
mapmap Maps an operation onto all key/value pairs of a map
Maps an operation onto all key/value pairs of the map MAP
and thus creates a new map. For each key/value pair of the map MAP
the expression EXPR
is evaluated in a new block, where the variable KEY
is assigned to the key and VALUE
to the value of the pair. The result is the map of those evaluations.
The result of each evaluation must be a map with a single entry which will be added to the result map.
any | KEY | |
any | VALUE | |
map | MAP | |
block | EXPR |
mapmap (integer k, string v, $[1:"a", 2:"b"], { return ($[k+10 : v+"x"]); }) -> $[ 11:"ax", 12:"bx" ] mapmap (integer k, string v, $[1:"a", 2:"b"], { integer a = k + 10; string b = v + "x"; return $[a:b]; }) -> $[ 11:"ax", 12:"bx" ]
References YCPMap::add(), YCPMap::begin(), YCPMap::end(), YCPElement::isNull(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
remove remove-map Remove key/value pair from a map
Remove the value with the key KEY
from a map. Returns unchanged map if the key is invalid.
The yast2-core version < 2.17.16 returns nil if the key is invalid. This behavior has changed in version 2.17.16 to return unchanged map.
map | MAP | |
any | KEY |
remove($[1:2], 0) -> $[1:2] remove($[1:2], 1) -> $[] remove ($[1:2, 3:4], 1) -> $[3:4]
References YCPMap::hasKey(), YCPElement::isNull(), YCPMap::remove(), and ycp2error.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
size size-map Size of a map
Returns the number of key/value pairs in the map MAP
.
map | MAP |
size($["a":1, "aa":2, "b":3]) -> 3
References YCPElement::isNull().
Referenced by YCPBuiltinMap::YCPBuiltinMap().
tomap Converts a value to a map.
If the value can't be converted to a map, nilmap is returned. Functionality partly replaced with retyping: any a = $[1:1, 2:2]; map m = (map) a;
any | VALUE |
References YCPElement::isNull(), and YT_MAP.
Referenced by YCPBuiltinMap::YCPBuiltinMap().
union union-map Union of 2 maps Interprets two maps as sets and returns a new map that has all elements of the first map MAP1
and all of the second map MAP2
. If elements have identical keys, values from MAP2
overwrite elements from MAP1
.
map | MAP1 | |
map | MAP2 |
union($["a":1, "b":2], $[1:"a", 2:"b"]) -> $[1:"a", 2:"b", "a":1, "b":2] union($["a":1, "b":2], $["b":10, "c":20]) -> $["a":1, "b":10, "c":20]
References YCPMap::add(), YCPMap::begin(), YCPMap::end(), and YCPElement::isNull().
Referenced by YCPBuiltinMap::YCPBuiltinMap().