Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Examples

YCPBuiltinList.cc File Reference

#include <set>
#include <algorithm>
#include "ycp/YCPBuiltinList.h"
#include "ycp/YCPList.h"
#include "ycp/YCPMap.h"
#include "ycp/YCPSymbol.h"
#include "ycp/YCPString.h"
#include "ycp/YCPBoolean.h"
#include "ycp/YCPInteger.h"
#include "ycp/YCPVoid.h"
#include "ycp/YCPCode.h"
#include "ycp/YCPCodeCompare.h"
#include "ycp/YCPTerm.h"
#include "ycp/StaticDeclaration.h"
#include "ycp/y2log.h"

Functions

static YCPValue l_find (const YCPSymbol &symbol, const YCPList &list, const YCPCode &expr)
static YCPValue l_prepend (const YCPList &list, const YCPValue &value)
 Search for the first occurence of a certain element in a list.
static YCPValue l_contains (const YCPList &list, const YCPValue &value)
 Prepend a list with a new element.
static YCPValue l_setcontains (const YCPList &list, const YCPValue &value)
 Check if a list contains an element.
static YCPValue l_unionlist (const YCPList &list1, const YCPList &list2)
 Check if a sorted list contains an element.
static YCPValue l_mergelist (const YCPList &list1, const YCPList &list2)
 Union of lists.
static YCPValue l_filter (const YCPSymbol &symbol, const YCPList &list, const YCPCode &expr)
 Merge two lists into one.
static YCPValue l_maplist (const YCPSymbol &symbol, const YCPList &list, const YCPCode &expr)
 Filter a List.
static YCPValue l_listmap (const YCPSymbol &symbol, const YCPList &list, const YCPCode &expr)
 Maps an operation onto all elements of a list and thus creates a new list.
static YCPValue l_flatten (const YCPList &list)
 Maps an operation onto all elements of a list and thus creates a map.
static YCPValue l_toset (const YCPList &list)
 Flatten List.
static YCPValue l_sortlist (const YCPList &list)
 Sort list and remove duplicates.
static YCPValue l_sort (const YCPValue &sym1, const YCPValue &sym2, const YCPList &list, const YCPCode &order)
 Sort a List according to the YCP builtin predicate.
static YCPValue l_lsortlist (const YCPList &list)
 Sort list using an expression.
static YCPValue l_splitstring (const YCPString &s, const YCPString &c)
 Sort A List respecting locale.
static YCPValue l_changelist (YCPList &list, const YCPValue &value)
 Split a string by delimiter.
static YCPValue l_add (const YCPList &list, const YCPValue &value)
 Change a list.
static YCPValue l_size (const YCPValue &list)
 Create a new list with a new element.
static YCPValue l_remove (const YCPList &list, const YCPInteger &i)
 Return size of list.
static YCPValue l_select (const YCPValue &list, const YCPValue &i, const YCPValue &def)
 Remove element from a list.
static YCPValue l_foreach (const YCPValue &sym, const YCPList &list, const YCPCode &expr)
 Selet a list element (deprecated).
static YCPValue l_tolist (const YCPValue &v)
 Process the content of a list.

Variables

StaticDeclaration static_declarations

Function Documentation

static YCPValue l_add const YCPList list,
const YCPValue value
[static]
 

Change a list.

add

Parameters:
list LIST
any VAR
Returns:
list The new list Creates a new list that is identical to the list LIST but has the value VAR appended as additional element.
add ([1, 4], 8) -> [1, 4, 8]

static YCPValue l_changelist YCPList list,
const YCPValue value
[static]
 

Split a string by delimiter.

change

Parameters:
list LIST
any value
Returns:
list
DO NOT use this yet. Its for a special requst, not for common use!!! changes the list LIST adds a new element

See also:
add change ([1, 4], 8) -> [1, 4, 8]

static YCPValue l_contains const YCPList list,
const YCPValue value
[static]
 

Prepend a list with a new element.

contains

Parameters:
list LIST List
any ELEMENT Element
Returns:
boolean True if element is in the list.
Determines, if a certain value ELEMENT is contained in a list LIST.

contains ([1, 2, 5], 2) -> true

static YCPValue l_filter const YCPSymbol symbol,
const YCPList list,
const YCPCode expr
[static]
 

Merge two lists into one.

filter

Parameters:
any VAR Variable
list LIST List to be filtered
block<boolean> EXPR Block
Returns:
list For each element of the list LIST the expression expr is executed in a new context, where the variable VAR is assigned to that value. If the expression evaluates to true under this circumstances, the value is appended to the result list.
filter (integer v, [1, 2, 3, 5], { return (v > 2); }) -> [3, 5]

static YCPValue l_find const YCPSymbol symbol,
const YCPList list,
const YCPCode expr
[static]
 

find

Parameters:
any VAR
list LIST
block EXPR
Searches for a certain item in the list. It applies the expression EXPR to each element in the list and returns the first element the makes the expression evaluate to true, if VAR is bound to that element.

Returns:
any Returns nil, if nothing is found. find (integer n, [3,5,6,4], ``(n >= 5)) -> 5

static YCPValue l_flatten const YCPList list  )  [static]
 

Maps an operation onto all elements of a list and thus creates a map.

flatten

Parameters:
list<list> LIST
Returns:
list
Gets a list of lists LIST and creates a single list that is the concatenation of those lists in LIST.

flatten ([ [1, 2], [3, 4] ]) -> [1, 2, 3, 4] flatten ([ [1, 2], [6, 7], [3, 4] ]) -> [1, 2, 6, 7, 3, 4]

static YCPValue l_foreach const YCPValue sym,
const YCPList list,
const YCPCode expr
[static]
 

Selet a list element (deprecated).

foreach

Parameters:
any VAR
list LIST
block EXPR
For each element of the list LIST the expression EXPR is executed in a new context, where the variable VAR is assigned to that value. The return value of the last execution of EXPR is the value of the foreach construct.

Returns:
any return value of last execution of EXPR foreach (integer v, [1,2,3], { return v + 10; }) -> 13

static YCPValue l_listmap const YCPSymbol symbol,
const YCPList list,
const YCPCode expr
[static]
 

Maps an operation onto all elements of a list and thus creates a new list.

listmap

Parameters:
any VAR
list LIST
block EXPR
Returns:
map
For each element VAR of the list LIST in the expression EXPR is evaluated in a new context. 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.

listmap (integer k, [1,2,3], { return $[k:"xy"]; }) -> $[1:"xy", 2:"xy"] listmap (integer k, [1,2,3], { integer a = k+10; any b = sformat ("x%1", k); return $[a:b]; }) -> $[11:"x1", 12:"x2", 13:"x3"]

static YCPValue l_lsortlist const YCPList list  )  [static]
 

Sort list using an expression.

lsort

Parameters:
list LIST
Returns:
list Sorted list Sort the list LIST according to the YCP builtin predicate >. Strings are compared using the current locale. Duplicates are not removed.
lsort (["česky", "slovensky", "německy", 2, 1]) -> [1, 2, "česky", "německy", "slovensky"]

static YCPValue l_maplist const YCPSymbol symbol,
const YCPList list,
const YCPCode expr
[static]
 

Filter a List.

maplist

Parameters:
any VAR
list<any> LIST
block EXPR
Returns:
list<any>
For each element of the list LIST the expression EXPR is evaluated in a new context, where the variable VAR is assigned to that value. The result is the list of those evaluations.

maplist (integer v, [1, 2, 3, 5], { return (v + 1); }) -> [2, 3, 4, 6]

static YCPValue l_mergelist const YCPList list1,
const YCPList list2
[static]
 

Union of lists.

merge

Parameters:
list LIST1 First List
list LIST2 Second List
Returns:
list
Interprets two lists as sets and returns a new list that has all elements of the first list and all of the second list. Identical elements are preserved. The order of the elements in the new list is preserved. Elements of l1 are prior to elements from l2.

See also:
union merge ([1, 2], [3, 4]) -> [1, 2, 3, 4] merge ([1, 2, 3], [2, 3, 4]) -> [1, 2, 3, 2, 3, 4]

static YCPValue l_prepend const YCPList list,
const YCPValue value
[static]
 

Search for the first occurence of a certain element in a list.

prepend

Parameters:
list LIST List
any ELEMENT Element to prepend
Returns:
list Creates a new list that is identical to the list LIST but has the value ELEMENT prepended as additional element.
prepend ([1, 4], 8) -> [8, 1, 4]

static YCPValue l_remove const YCPList list,
const YCPInteger &  i
[static]
 

Return size of list.

remove

Parameters:
list LIST
integer e element index
Returns:
list Returns nil if the index is invalid. Remove the i'th value from a list. The first value has the index 0. The call remove ([1,2,3], 1) thus returns [1,3].
remove ([1, 2], 0) -> [2]

static YCPValue l_select const YCPValue list,
const YCPValue i,
const YCPValue def
[static]
 

Remove element from a list.

select

Parameters:
list LIST
integer INDEX
any DEFAULT
Returns:
any
Gets the INDEX'th value of a list. The first value has the index 0. The call select([1,2,3], 1) thus returns 2. Returns DEFAULT if the index is invalid or if the found entry has a different type than the default value. Functionality replaced by syntax: list numbers = [1, 2, 3, 4]; numbers[2]:nil -> 3 numbers[8]:5 -> 5

select ([1, 2], 22, 0) -> 0 select ([1, "two"], 0, "no") -> "no"

static YCPValue l_setcontains const YCPList list,
const YCPValue value
[static]
 

Check if a list contains an element.

setcontains

Parameters:
list LIST List
any ELEMENT Element
Returns:
boolean True if element is in the list. Determines, if a certain value ELEMENT is contained in a list LIST, but assumes that LIST is sorted. If LIST is not sorted, the result is undefined.
setcontains ([1, 2, 5], 2) -> true

static YCPValue l_size const YCPValue list  )  [static]
 

Create a new list with a new element.

size

Parameters:
list LIST
Returns:
integer size of the list
Returns the number of elements of the list LIST

size(["A", 1, true, "3", false]) -> 5

static YCPValue l_sort const YCPValue sym1,
const YCPValue sym2,
const YCPList list,
const YCPCode order
[static]
 

Sort a List according to the YCP builtin predicate.

sort sort_2

Parameters:
any x
any y
list LIST
block EXPR
Returns:
list
Sorts the list LIST. You have to specify an order on the list elements by naming formal variables x and y and specify an expression EXPR that evaluates to a boolean value depending on x and y. Return true if x>y to sort the list ascending.

The comparison must be an irreflexive one, that is ">" instead of ">=".

It is because we no longer use bubblesort (yuck) but std::sort which requires a <ulink url="href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">strict weak ordering</ulink>.

sort (integer x, integer y, [ 3,6,2,8 ], ``(x < y)) -> [ 2, 3, 6, 8 ] sort (string x, string y, [ "A","C","B" ], ``(x > y)) -> ["C", "B", "A"]

static YCPValue l_sortlist const YCPList list  )  [static]
 

Sort list and remove duplicates.

sort sort_1

Parameters:
list LIST
Returns:
list Sorted list
Sort the list LIST according to the YCP builtin predicate. Duplicates are not removed.

sort ([2, 1, true, 1]) -> [true, 1, 1, 2]

static YCPValue l_splitstring const YCPString s,
const YCPString c
[static]
 

Sort A List respecting locale.

splitstring

Parameters:
string STR
string DELIM
Returns:
list<string>
Splits STR into sub-strings at delimiter chars DELIM. the resulting pieces do not contain DELIM

If STR starts with DELIM, the first string in the result list is empty If STR ends with DELIM, the last string in the result list is empty. If STR does not contain DELIM, the result is a singleton list with STR.

See also:
mergestring splitstring ("/abc/dev/ghi", "/") -> ["", "abc", "dev", "ghi" ] splitstring ("abc/dev/ghi/", "/") -> ["abc", "dev", "ghi", "" ] splitstring ("abc/dev/ghi/", ".") -> ["abc/dev/ghi/" ] splitstring ("text/with:different/separators", "/:") -> ["text", "with", "different", "separators"]

static YCPValue l_tolist const YCPValue v  )  [static]
 

Process the content of a list.

tolist

Parameters:
any VAR
Returns:
list
If the value can't be converted to a list, nillist is returned. Functionality replaced by retyping: any l_1 = [1, 2, 3]; list <integer> l_2 = (list<integer>) l_1;

static YCPValue l_toset const YCPList list  )  [static]
 

Flatten List.

toset

Parameters:
list LIST
Returns:
list Sorted list with unique items Scans a list for duplicates, removes them and sorts the list.
toset ([1, 5, 3, 2, 3, true, false, true]) -> [false, true, 1, 2, 3, 5]

static YCPValue l_unionlist const YCPList list1,
const YCPList list2
[static]
 

Check if a sorted list contains an element.

union

Parameters:
list LIST1 First List
list LIST2 Second List
Returns:
list
Interprets two lists as sets and returns a new list that has all elements of the first list and all of the second list. Identical elements are merged. The order of the elements in the new list is preserved. Elements of l1 are prior to elements from l2.

WARNING: quadratic complexity so far

See also:
merge union ([1, 2], [3, 4]) -> [1, 2, 3, 4] union ([1, 2, 3], [2, 3, 4]) -> [1, 2, 3, 4] union ([1, 3, 5], [1, 2, 4, 6]) -> [1, 3, 5, 2, 4, 6]


Variable Documentation

StaticDeclaration static_declarations
 


Generated on Tue Mar 22 11:31:38 2005 for yast2-core by  doxygen 1.4.1