1
edit
Changes
Iterator
,→References
An Iterator provides the user with a way to access the elements of some kind of list sequentially, while keeping the elements of that list from exposing their underlying representation.
__TOC__
=== Implicit Iterators ===
Some object-oriented languages have iterator support included within the language, without having to implement an explicit iterator object. Some of these language include:
* C#
* Java (After 5.0)
* Python
* PERL
=== UML ===
Design class diagram in UML of the Iterator Pattern being used in a system. [[Image:IteratorIterator1.gifpng]]
== Code Samples ==
The following are samples of code from C#, Java, Python, and PERL, displaying how they use their implicit iterators.
=== C# ===
foreach (Value v in list)
Console.WriteLine(v);
=== Java ===
for (Value v : list)
System.out.print(v);
=== Python ===
for Value in List:
print Value
=== PERL ===
foreach $val (@list) {
print "$val\n";
}
== Examples ==
=== C++ ===
This is a source code snippet from a file called [http://www.google.com/codesearch?hl=en&q=show:3faa7gjspWs:MYoIVGFTT9Q:S6XmQxn_Gd8&sa=N&ct=rd&cs_p=http://gentoo.osuosl.org/distfiles/gnome-vfsmm-1.3.5.tar.gz&cs_f=gnome-vfsmm-1.3.5/libgnomevfs/libgnomevfsmm/transfer.cc transfer.cc], created by the Gnome VFS Development Team. This particular function, transfer_list, transfers a list of URI's from the source list to the target list. The source code repository can be found [http://www.google.com/codesearch?hl=en&q=show:7egWPqDRuQg:6mN6dZ6BKgU&sa=N&ct=rdp&cs_p=http://gentoo.osuosl.org/distfiles/gnome-vfsmm-1.3.5.tar.gz here].
void transfer_list(const Glib::StringArrayHandle& source_uri_list, const Glib::StringArrayHandle& target_uri_list,
OverwriteMode overwrite_mode,
const SlotProgress& slot)
{
typedef std::list< Glib::RefPtr<Uri> > uri_list;
uri_list sources, targets;
//Build lists of RefPtr<Uri>s from the strings:
Glib::StringArrayHandle::const_iterator iter_target = target_uri_list.begin();
}
}
transfer_list_uris(sources, targets, options, error_mode, overwrite_mode, slot);
}
== References ==
* [http://en.wikipedia.org/wiki/Iterator Wikipedia entry on Iterator]
* [http://thor.info.uaic.ro/ Universitatea Alexandru Ioan Cuza]
* [http://www.google.com/codesearch?hl=en&q=show:7egWPqDRuQg:6mN6dZ6BKgU&sa=N&ct=rdp&cs_p=http://gentoo.osuosl.org/distfiles/gnome-vfsmm-1.3.5.tar.gz Gnome VFS Development Source Code]