<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="redland-iterator">
<refmeta>
<refentrytitle role="top_of_page" id="redland-iterator.top_of_page">Iterator</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>REDLAND Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Iterator</refname>
<refpurpose>Iterate a sequence of objects across some other object.</refpurpose>
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
</refnamediv>

<refsynopsisdiv id="redland-iterator.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>
typedef             <link linkend="librdf-iterator">librdf_iterator</link>;
<link linkend="void">void</link>*               (<link linkend="librdf-iterator-map-handler">*librdf_iterator_map_handler</link>)      (<link linkend="librdf-iterator">librdf_iterator</link> *iterator,
                                                         <link linkend="void">void</link> *map_context,
                                                         <link linkend="void">void</link> *item);
<link linkend="void">void</link>                (<link linkend="librdf-iterator-map-free-context-handler">*librdf_iterator_map_free_context_handler</link>)
                                                        (<link linkend="void">void</link> *map_context);
<link linkend="librdf-iterator">librdf_iterator</link>*    <link linkend="librdf-new-iterator">librdf_new_iterator</link>                 (<link linkend="librdf-world">librdf_world</link> *world,
                                                         <link linkend="void">void</link> *context,
                                                         <link linkend="int">int</link> (is_end_methodvoid*) (),
                                                         <link linkend="int">int</link> (next_methodvoid*) (),
                                                         <link linkend="void">void</link>* (get_methodvoid*, int) (),
                                                         <link linkend="void">void</link> (finished_methodvoid*) ());
<link linkend="void">void</link>                <link linkend="librdf-free-iterator">librdf_free_iterator</link>                (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="int">int</link>                 <link linkend="librdf-iterator-end">librdf_iterator_end</link>                 (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="int">int</link>                 <link linkend="librdf-iterator-have-elements">librdf_iterator_have_elements</link>       (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="int">int</link>                 <link linkend="librdf-iterator-next">librdf_iterator_next</link>                (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="void">void</link>*               <link linkend="librdf-iterator-get-object">librdf_iterator_get_object</link>          (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="void">void</link>*               <link linkend="librdf-iterator-get-context">librdf_iterator_get_context</link>         (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="void">void</link>*               <link linkend="librdf-iterator-get-key">librdf_iterator_get_key</link>             (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="void">void</link>*               <link linkend="librdf-iterator-get-value">librdf_iterator_get_value</link>           (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);
<link linkend="int">int</link>                 <link linkend="librdf-iterator-add-map">librdf_iterator_add_map</link>             (<link linkend="librdf-iterator">librdf_iterator</link> *iterator,
                                                         <link linkend="librdf-iterator-map-handler">librdf_iterator_map_handler</link> map_function,
                                                         <link linkend="librdf-iterator-map-free-context-handler">librdf_iterator_map_free_context_handler</link> free_context,
                                                         <link linkend="void">void</link> *map_context);
<link linkend="librdf-iterator">librdf_iterator</link>*    <link linkend="librdf-new-empty-iterator">librdf_new_empty_iterator</link>           (<link linkend="librdf-world">librdf_world</link> *world);
</synopsis>
</refsynopsisdiv>









<refsect1 id="redland-iterator.description" role="desc">
<title role="desc.title">Description</title>
<para>
Provides a way to operate across a sequence of objects that are
generated one-by-one on demand.  The returned objects can be of any
type but the main public methods are on the <link linkend="librdf-model"><type>librdf_model</type></link> classs and
return sequence of <link linkend="librdf-node"><type>librdf_node</type></link> objects such as <link linkend="librdf-model-get-sources"><function>librdf_model_get_sources()</function></link>.
</para>
</refsect1>

<refsect1 id="redland-iterator.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="librdf-iterator" role="typedef">
<title>librdf_iterator</title>
<indexterm zone="librdf-iterator"><primary>librdf_iterator</primary></indexterm><programlisting>typedef struct librdf_iterator_s librdf_iterator;
</programlisting>
<para>
Redland iterator class.</para>
<para>

</para></refsect2>
<refsect2 id="librdf-iterator-map-handler" role="function">
<title>librdf_iterator_map_handler ()</title>
<indexterm zone="librdf-iterator-map-handler"><primary>librdf_iterator_map_handler</primary></indexterm><programlisting><link linkend="void">void</link>*               (*librdf_iterator_map_handler)      (<link linkend="librdf-iterator">librdf_iterator</link> *iterator,
                                                         <link linkend="void">void</link> *map_context,
                                                         <link linkend="void">void</link> *item);</programlisting>
<para>
Map function for a <link linkend="librdf-iterator"><type>librdf_iterator</type></link> map operation.
</para>
<para>
See <link linkend="librdf-iterator-add-map"><function>librdf_iterator_add_map()</function></link>.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> Iterator that this map is operating over.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>map_context</parameter>&nbsp;:</term>
<listitem><simpara> Map data context pointer.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>item</parameter>&nbsp;:</term>
<listitem><simpara> Pointer to the current item in the iteration.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> item in keep the iteration or NULL to remove it
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-map-free-context-handler" role="function">
<title>librdf_iterator_map_free_context_handler ()</title>
<indexterm zone="librdf-iterator-map-free-context-handler"><primary>librdf_iterator_map_free_context_handler</primary></indexterm><programlisting><link linkend="void">void</link>                (*librdf_iterator_map_free_context_handler)
                                                        (<link linkend="void">void</link> *map_context);</programlisting>
<para>
Free handler function for a <link linkend="librdf-iterator"><type>librdf_iterator</type></link> map operation.
</para>
<para>
See <link linkend="librdf-iterator-add-map"><function>librdf_iterator_add_map()</function></link>.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>map_context</parameter>&nbsp;:</term>
<listitem><simpara> Map data context pointer.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-new-iterator" role="function">
<title>librdf_new_iterator ()</title>
<indexterm zone="librdf-new-iterator"><primary>librdf_new_iterator</primary></indexterm><programlisting><link linkend="librdf-iterator">librdf_iterator</link>*    librdf_new_iterator                 (<link linkend="librdf-world">librdf_world</link> *world,
                                                         <link linkend="void">void</link> *context,
                                                         <link linkend="int">int</link> (is_end_methodvoid*) (),
                                                         <link linkend="int">int</link> (next_methodvoid*) (),
                                                         <link linkend="void">void</link>* (get_methodvoid*, int) (),
                                                         <link linkend="void">void</link> (finished_methodvoid*) ());</programlisting>
<para>
Constructor - create a new <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object.
The iterator object takes ownership of <parameter>context</parameter> and frees it with <parameter>finished_method</parameter>.
The finished method is not called if librdf_new_iterator fails and returns NULL.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>world</parameter>&nbsp;:</term>
<listitem><simpara> redland world object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>context</parameter>&nbsp;:</term>
<listitem><simpara> context to pass to the iterator functions
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>is_end_method</parameter>&nbsp;:</term>
<listitem><simpara> function to call to see if the iteration has ended
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>next_method</parameter>&nbsp;:</term>
<listitem><simpara> function to get the next element
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>get_method</parameter>&nbsp;:</term>
<listitem><simpara> function to get the next element
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>finished_method</parameter>&nbsp;:</term>
<listitem><simpara> function to destroy the iterator context (or NULL if not needed)
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> a new <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-free-iterator" role="function">
<title>librdf_free_iterator ()</title>
<indexterm zone="librdf-free-iterator"><primary>librdf_free_iterator</primary></indexterm><programlisting><link linkend="void">void</link>                librdf_free_iterator                (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Destructor - destroy a <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-end" role="function">
<title>librdf_iterator_end ()</title>
<indexterm zone="librdf-iterator-end"><primary>librdf_iterator_end</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_iterator_end                 (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Test if the iterator has finished.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> non 0 if the iterator has finished
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-have-elements" role="function">
<title>librdf_iterator_have_elements ()</title>
<indexterm zone="librdf-iterator-have-elements"><primary>librdf_iterator_have_elements</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_iterator_have_elements       (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Test if the iterator has finished.
</para>
<para>
DEPRECATED - use !librdf_iterator_end(iterator)</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> 0 if the iterator has finished
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-next" role="function">
<title>librdf_iterator_next ()</title>
<indexterm zone="librdf-iterator-next"><primary>librdf_iterator_next</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_iterator_next                (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Move to the next iterator element.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> non 0 if the iterator has finished
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-get-object" role="function">
<title>librdf_iterator_get_object ()</title>
<indexterm zone="librdf-iterator-get-object"><primary>librdf_iterator_get_object</primary></indexterm><programlisting><link linkend="void">void</link>*               librdf_iterator_get_object          (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Get the current object from the iterator.
</para>
<para>
This method returns a SHARED pointer to the current iterator object
which should be copied by the caller to preserve it if the iterator
is moved on librdf_iterator_next or if it should last after the
iterator is closed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> The next element or NULL if the iterator has finished.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-get-context" role="function">
<title>librdf_iterator_get_context ()</title>
<indexterm zone="librdf-iterator-get-context"><primary>librdf_iterator_get_context</primary></indexterm><programlisting><link linkend="void">void</link>*               librdf_iterator_get_context         (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Get the context of the current object on the iterator.
</para>
<para>
This method returns a SHARED pointer to the current context node object
which should be copied by the caller to preserve it if the iterator
is moved on librdf_iterator_next or if it should last after the
iterator is closed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> The context (can be NULL) or NULL if the iterator has finished.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-get-key" role="function">
<title>librdf_iterator_get_key ()</title>
<indexterm zone="librdf-iterator-get-key"><primary>librdf_iterator_get_key</primary></indexterm><programlisting><link linkend="void">void</link>*               librdf_iterator_get_key             (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Get the key of the current object on the iterator.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> The context or NULL if the iterator has finished.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-get-value" role="function">
<title>librdf_iterator_get_value ()</title>
<indexterm zone="librdf-iterator-get-value"><primary>librdf_iterator_get_value</primary></indexterm><programlisting><link linkend="void">void</link>*               librdf_iterator_get_value           (<link linkend="librdf-iterator">librdf_iterator</link> *iterator);</programlisting>
<para>
Get the value of the current object on the iterator.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> The context or NULL if the iterator has finished.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-iterator-add-map" role="function">
<title>librdf_iterator_add_map ()</title>
<indexterm zone="librdf-iterator-add-map"><primary>librdf_iterator_add_map</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_iterator_add_map             (<link linkend="librdf-iterator">librdf_iterator</link> *iterator,
                                                         <link linkend="librdf-iterator-map-handler">librdf_iterator_map_handler</link> map_function,
                                                         <link linkend="librdf-iterator-map-free-context-handler">librdf_iterator_map_free_context_handler</link> free_context,
                                                         <link linkend="void">void</link> *map_context);</programlisting>
<para>
Add a librdf_iterator mapping function.
</para>
<para>
Adds an iterator mapping function which operates over the iterator to
select which elements are returned; it will be applied as soon as
this method is called.
</para>
<para>
Several mapping functions can be added and they are applied in
the order given
</para>
<para>
The mapping function should return non 0 to allow the element to be
returned.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>iterator</parameter>&nbsp;:</term>
<listitem><simpara> the iterator
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>map_function</parameter>&nbsp;:</term>
<listitem><simpara> the function to operate
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>free_context</parameter>&nbsp;:</term>
<listitem><simpara> the function to use to free the context (or NULL)
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>map_context</parameter>&nbsp;:</term>
<listitem><simpara> the context to pass to the map function
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> Non 0 on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-new-empty-iterator" role="function">
<title>librdf_new_empty_iterator ()</title>
<indexterm zone="librdf-new-empty-iterator"><primary>librdf_new_empty_iterator</primary></indexterm><programlisting><link linkend="librdf-iterator">librdf_iterator</link>*    librdf_new_empty_iterator           (<link linkend="librdf-world">librdf_world</link> *world);</programlisting>
<para>
Constructor - create a new <link linkend="librdf-iterator"><type>librdf_iterator</type></link> with no content.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>world</parameter>&nbsp;:</term>
<listitem><simpara> redland world object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> a new <link linkend="librdf-iterator"><type>librdf_iterator</type></link> object or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>
