YCPBuiltinMap.cc File Reference

#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 Documentation

#define ETC   0, NULL, constTypePtr(), NULL
#define ETCf   NULL, constTypePtr(), NULL

Function Documentation

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]

Parameters:
map MAP
any KEY
any VALUE
Returns:
map

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().

static YCPValue m_changemap ( YCPMap map,
const YCPValue key,
const YCPValue value 
) [static]

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.

Parameters:
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.

Parameters:
any KEY
any VALUE
map MAP
blocl EXPR
Returns:
map filter (`k, `v, $[1:"a", 2:"b", 3:3, 5:5], { return (k == v); }) -> $[3:3, 5:5]

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.

Parameters:
any KEY
any VALUE
map MAP
any EXPR
Returns:
map

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().

static YCPValue m_haskey ( const YCPMap map,
const YCPValue value 
) [static]

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.

Parameters:
map MAP
any KEY
Returns:
boolean

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().

static YCPValue m_isempty ( const YCPMap m  )  [static]

isempty isempty-map Returns whether the map m is empty.

Parameters:
map m Map
Returns:
boolean Emptiness of 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.

Parameters:
any KEY
any VALUE
map MAP
block EXPR
Returns:
list

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.

Parameters:
any KEY
any VALUE
map MAP
block EXPR
Returns:
map

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().

static YCPValue m_remove ( const YCPMap map,
const YCPValue key 
) [static]

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.

Parameters:
map MAP
any KEY
Returns:
map

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().

static YCPValue m_size ( const YCPValue map  )  [static]

size size-map Size of a map

Returns the number of key/value pairs in the map MAP.

Parameters:
map MAP
Returns:
integer

size($["a":1, "aa":2, "b":3]) -> 3

References YCPElement::isNull().

Referenced by YCPBuiltinMap::YCPBuiltinMap().

static YCPValue m_tomap ( const YCPValue v  )  [static]

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;

Parameters:
any VALUE
Returns:
map

References YCPElement::isNull(), and YT_MAP.

Referenced by YCPBuiltinMap::YCPBuiltinMap().

static YCPValue m_unionmap ( const YCPMap map1,
const YCPMap map2 
) [static]

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 MAP1and all of the second map MAP2. If elements have identical keys, values from MAP2 overwrite elements from MAP1.

Parameters:
map MAP1
map MAP2
Returns:
map

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().


Variable Documentation


Generated on a sunny day for yast2-core by doxygen 1.6.3