<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Parrot - Implementation of Iterator for Arrays.</title> <link rel="stylesheet" type="text/css" href="../../../resources/parrot.css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="wrapper"> <div id="header"> <a href="http://www.parrot.org"> <img border=0 src="../../../resources/parrot_logo.png" id="logo" alt="parrot"> </a> </div> <!-- "header" --> <div id="divider"></div> <div id="mainbody"> <div id="breadcrumb"> <a href="../../../html/index.html">Home</a> » <a href="../../../html/pmc.html">PMCs</a> » Implementation of Iterator for Arrays. </div> <h1><a name="NAME" >NAME</a></h1> <p>src/pmc/arrayiterator.pmc - Implementation of Iterator for Arrays.</p> <h1><a name="DESCRIPTION" >DESCRIPTION</a></h1> <p>Generic iterator for traversing arrays.</p> <h1><a name="SYNOPSIS" >SYNOPSIS</a></h1> <h2><a name="default_usage" >default usage</a></h2> <pre> .local pmc iterator, array, entry iterator = iter array iter_loop: unless iterator, iter_end # while (more values) entry = shift iterator # get an entry ... goto iter_loop iter_end:</pre> <h2><a name="iterate_from_the_end,_for_arrays" >iterate from the end, for arrays</a></h2> <pre> .local pmc iterator, array, entry iterator = iter array iterator = .ITERATE_FROM_END iter_loop: unless iterator, iter_end # while (more values) entry = pop iterator # get an entry ... goto iter_loop iter_end:</pre> <h2><a name="Warning!" >Warning!</a></h2> <p>NB: for different direction you have to use different ops!</p> <p>TODO: Discuss idea of having separate get_iter/get_reverse_iter VTABLEs to avoid this caveat.</p> <h1><a name="Vtable_functions" >Vtable functions</a></h1> <dl> <dt><a name="void_init()" ><b><code>void init()</b></code></a></dt> Raises an exception. Use <code>init_pmc()</code>. <dt><a name="void_init_pmc(PMC_*initializer)" ><b><code>void init_pmc(PMC *initializer)</b></code></a></dt> Initializes the iterator with an aggregate PMC. Defaults iteration mode to iterate from start. <dt><a name="void_mark()" ><b><code>void mark()</b></code></a></dt> Marks the current idx/key and the aggregate as live. <dt><a name="PMC_*clone()" ><b><code>PMC *clone()</b></code></a></dt> <dt><a name="INTVAL_get_bool()" ><b><code>INTVAL get_bool()</b></code></a></dt> Returns true if there is more elements to iterate over. <dt><a name="INTVAL_elements()" ><b><code>INTVAL elements()</b></code></a></dt> Returns the number of remaining elements in the array. <dt><a name="void_set_integer_native(INTVAL_value)" ><b><code>void set_integer_native(INTVAL value)</b></code></a></dt> Reset the Iterator. <code>value</code> must be one of <pre> ITERATE_FROM_START ... Iterate from start ITERATE_FROM_END ... Iterate from end</pre> <dt><a name="PMC_*get_pmc()" ><b><code>PMC *get_pmc()</b></code></a></dt> Returns this Iterator's array. <dt><a name="INTVAL_shift_integer()" ><b><code>INTVAL shift_integer()</b></code></a></dt> Returns the element for the current idx and sets the idx to the next one. <dt><a name="FLOATVAL_shift_float()" ><b><code>FLOATVAL shift_float()</b></code></a></dt> <dt><a name="STRING_*shift_string()" ><b><code>STRING *shift_string()</b></code></a></dt> <dt><a name="PMC_*shift_pmc()" ><b><code>PMC *shift_pmc()</b></code></a></dt> Returns the element for the current idx/key and sets the idx/key to the next one. <dt><a name="INTVAL_pop_integer()" ><b><code>INTVAL pop_integer()</b></code></a></dt> Returns the element for the current idx and sets the idx to the next one. <dt><a name="FLOATVAL_pop_float()" ><b><code>FLOATVAL pop_float()</b></code></a></dt> <dt><a name="STRING_*pop_string()" ><b><code>STRING *pop_string()</b></code></a></dt> <dt><a name="PMC_*pop_pmc()" ><b><code>PMC *pop_pmc()</b></code></a></dt> Returns the element for the current idx/key and sets the idx/key to the next one. <dt><a name="PMC_*get_pmc_keyed(PMC_*key)" ><b><code>PMC *get_pmc_keyed(PMC *key)</b></code></a></dt> Returns the element for <code>*key</code>. <dt><a name="PMC_*get_pmc_keyed_int(INTVAL_key)" ><b><code>PMC *get_pmc_keyed_int(INTVAL key)</b></code></a></dt> Returns the element for <code>key</code>. <dt><a name="INTVAL_get_integer_keyed(PMC_*key)" ><b><code>INTVAL get_integer_keyed(PMC *key)</b></code></a></dt> <dt><a name="INTVAL_get_integer_keyed_int(INTVAL_idx)" ><b><code>INTVAL get_integer_keyed_int(INTVAL idx)</b></code></a></dt> Get integer value of current position plus idx. <dt><a name="FLOATVAL_get_number_keyed(PMC_*key)" ><b><code>FLOATVAL get_number_keyed(PMC *key)</b></code></a></dt> <dt><a name="FLOATVAL_get_number_keyed_int(INTVAL_idx)" ><b><code>FLOATVAL get_number_keyed_int(INTVAL idx)</b></code></a></dt> Get number value of current position plus idx. <dt><a name="STRING_*get_string_keyed(PMC_*key)" ><b><code>STRING *get_string_keyed(PMC *key)</b></code></a></dt> <dt><a name="STRING_*get_string_keyed_int(INTVAL_idx)" ><b><code>STRING *get_string_keyed_int(INTVAL idx)</b></code></a></dt> Get string value of current position plus idx. <dt><a name="INTVAL_exists_keyed(PMC_*key)" ><b><code>INTVAL exists_keyed(PMC *key)</b></code></a></dt> Returns whether an element for <code>*key</code> exists in the array. <dt><a name="INTVAL_exists_keyed_int(INTVAL_idx)" ><b><code>INTVAL exists_keyed_int(INTVAL idx)</b></code></a></dt> Returns whether an element for <code>idx</code> exists in the aggregate. <dt><a name="INTVAL_defined_keyed(PMC_*key)" ><b><code>INTVAL defined_keyed(PMC *key)</b></code></a></dt> <dt><a name="INTVAL_defined_keyed_int(INTVAL_key)" ><b><code>INTVAL defined_keyed_int(INTVAL key)</b></code></a></dt> Returns the result of calling <code>defined_keyed(key)</code> on the aggregate.</dl> <h1><a name="Auxiliar_functions" >Auxiliar functions</a></h1> <dl> <dt><a name="static_void_out_of_bounds(PARROT_INTERP)" ><b><code>static void out_of_bounds(PARROT_INTERP)</b></code></a></dt> Throw out-of-bounds exception.</dl> </div> <!-- "mainbody" --> <div id="divider"></div> <div id="footer"> Copyright © 2002-2011, Parrot Foundation. </div> </div> <!-- "wrapper" --> </body> </html>