rm trailing white space
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / Types / Iterator.php
blobef55e2874cc8c87ba6cb195a62333d92d2e31351
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 //
4 // Copyright (c) 2003 Laurent Bedubourg
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
21 //
23 /**
24 * Iterable interface.
26 * An iterable object can produce Iterator(s) related to itself.
28 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
30 class Iterable
32 /**
33 * Retrieve iterable size.
35 function size(){}
37 /**
38 * Get an initialized iterator for this object.
40 function &getNewIterator(){}
44 /**
45 * Iterator interface.
47 * This class provides common methods for Iterator objects.
49 * An iterator is a 'pointer' to a data item extracted from some collection of
50 * resources.
52 * The aim of Iterator is to allow some abstraction between your program
53 * resources and the way you fetch these resources.
55 * Thus, you can loop over a file content and later replace this file with a
56 * database backend whithout changing the program logic.
58 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
60 class Iterator
62 /**
63 * Reset iterator to first item.
65 * This method should throw an exception for once only iterators.
67 * @throws ResetFailed
69 function reset()
71 return PEAR::raiseError('\'reset\' method not implemented');
74 /**
75 * Test if current item is not the end of iterator.
77 * @return boolean
79 function isValid()
81 return PEAR::raiseError('\'isValid\' method not implemented');
84 /**
85 * Iterate on the next element and returns the next item.
87 * @return mixed (by reference)
89 function &next()
91 return PEAR::raiseError('\'next\' method not implemented');
94 // ----------------------------------------------------------------------
95 // getters
96 // ----------------------------------------------------------------------
98 /**
99 * Retrieve the current item index.
101 * @return int
103 function index()
105 return PEAR::raiseError('\'index\' method not implemented');
109 * Retrieve current item value.
111 * @return mixed (by reference)
113 function &value()
115 return PEAR::raiseError('\'value\' method not implemented');
118 // ----------------------------------------------------------------------
119 // optional methods
120 // ----------------------------------------------------------------------
123 * (optional) Additional index for hashes.
125 * @return string
127 function key()
129 return $this->index();
133 * (optional) Remove the current value from container.
135 * Implement this method only when the iterator can do a secured remove
136 * without breaking other iterators works.
138 function remove()
140 return PEAR::raiseError('\'remove\' method not implemented');
145 * Exception thrown by iterators that can be reseted only once.
147 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
149 class ResetFailed extends PEAR_Error