python-on-a-chip online compiler

Dependencies:   mbed TSI

Embed: (wiki syntax)

« Back to documentation index

list.c File Reference

list.c File Reference

List Object Type. More...

Go to the source code of this file.

Functions

PmReturn_t list_append (pPmObj_t plist, pPmObj_t pobj)
 Appends the given obj to the end of the given list.
PmReturn_t list_getItem (pPmObj_t plist, int16_t index, pPmObj_t *r_pobj)
 Gets the object in the list at the index.
PmReturn_t list_insert (pPmObj_t plist, int16_t index, pPmObj_t pobj)
 Inserts the object into the list at the desired index.
PmReturn_t list_new (pPmObj_t *r_pobj)
 Allocates a new List object.
PmReturn_t list_copy (pPmObj_t pobj, pPmObj_t *r_pobj)
 Makes a copy of the given list.
PmReturn_t list_replicate (pPmObj_t psrclist, int16_t n, pPmObj_t *r_pnewlist)
 Creates a new list with the contents of psrclist copied pint number of times.
PmReturn_t list_setItem (pPmObj_t plist, int16_t index, pPmObj_t pobj)
 Sets the item in the list at the index.
PmReturn_t list_remove (pPmObj_t plist, pPmObj_t item)
 Removes a given object from the list.
PmReturn_t list_index (pPmObj_t plist, pPmObj_t pitem, uint16_t *r_index)
 Finds the first index of the item that matches pitem.
PmReturn_t list_delItem (pPmObj_t plist, int16_t index)
 Removes the item at the given index.
PmReturn_t list_print (pPmObj_t plist)
 Prints out a list.
PmReturn_t list_clear (pPmObj_t plist)
 Removes all items from the list and zeroes the length.

Detailed Description

List Object Type.

List object type operations.

Definition in file list.c.


Function Documentation

PmReturn_t list_append ( pPmObj_t  plist,
pPmObj_t  pobj 
)

Appends the given obj to the end of the given list.

Allocate the memory for the node. Do not copy obj, just reuse ptr.

Parameters:
plistPtr to list
pobjPtr to item to append
Returns:
Return status

Definition at line 25 of file list.c.

PmReturn_t list_clear ( pPmObj_t  plist )

Removes all items from the list and zeroes the length.

Parameters:
plistList to clear
Returns:
Return status

Definition at line 399 of file list.c.

PmReturn_t list_copy ( pPmObj_t  pobj,
pPmObj_t r_pobj 
)

Makes a copy of the given list.

Allocate the necessary memory for root and nodes. Duplicate ptrs to objs.

Parameters:
pobjPtr to source list
r_pobjReturn; Addr of ptr to return obj
Returns:
Return status

Definition at line 163 of file list.c.

PmReturn_t list_delItem ( pPmObj_t  plist,
int16_t  index 
)

Removes the item at the given index.

Raises a TypeError if the first argument is not a list. Raises an IndexError if the index is out of bounds.

Parameters:
plistPtr to list obj
indexIndex of item to remove
Returns:
Return status

Definition at line 317 of file list.c.

PmReturn_t list_getItem ( pPmObj_t  plist,
int16_t  index,
pPmObj_t r_pobj 
)

Gets the object in the list at the index.

Parameters:
plistPtr to list obj
indexIndex into list
r_pobjReturn by reference; ptr to item
Returns:
Return status

Definition at line 61 of file list.c.

PmReturn_t list_index ( pPmObj_t  plist,
pPmObj_t  pitem,
uint16_t *  r_index 
)

Finds the first index of the item that matches pitem.

Returns an ValueError Exception if the item is not found.

Parameters:
plistPtr to list obj
pitemPtr to object to be removed
r_indexReturn by reference; ptr to index (C uint16)
Returns:
Return status

Definition at line 275 of file list.c.

PmReturn_t list_insert ( pPmObj_t  plist,
int16_t  index,
pPmObj_t  pobj 
)

Inserts the object into the list at the desired index.

Parameters:
plistPtr to list obj
pobjPtr to obj to insert
indexIndex of where to insert obj
Returns:
Return status

Definition at line 92 of file list.c.

PmReturn_t list_new ( pPmObj_t r_pobj )

Allocates a new List object.

If there is not enough memory to allocate the List, the return status will indicate an OutOfMemoryError that must be passed up to the interpreter. Otherwise, a ptr to the list is returned by reference and the return status is OK.

Parameters:
r_pobjReturn; addr of ptr to obj
Returns:
Return status

Definition at line 143 of file list.c.

PmReturn_t list_print ( pPmObj_t  pobj )

Prints out a list.

Uses obj_print() to print elements.

Parameters:
pobjObject to print.
Returns:
Return status

Definition at line 357 of file list.c.

PmReturn_t list_remove ( pPmObj_t  plist,
pPmObj_t  item 
)

Removes a given object from the list.

Parameters:
plistPtr to list obj
itemPtr to object to be removed
Returns:
Return status

Definition at line 244 of file list.c.

PmReturn_t list_replicate ( pPmObj_t  psrclist,
int16_t  n,
pPmObj_t r_pnewlist 
)

Creates a new list with the contents of psrclist copied pint number of times.

This implements the python code "[0,...] * N" where the list can be any list and N is an integer.

Parameters:
psrclistThe source list to replicate
nThe integer number of times to replicate it
r_pnewlistReturn; new list with its contents set.
Returns:
Return status

Definition at line 170 of file list.c.

PmReturn_t list_setItem ( pPmObj_t  plist,
int16_t  index,
pPmObj_t  pobj 
)

Sets the item in the list at the index.

Parameters:
plistPtr to list
indexIndex into list
pobjPtr to obj to put into list
Returns:
Return status

Definition at line 213 of file list.c.