classwork.pp |
Class AnIterator
UnitDeclaration
DescriptionThis class represents an abstract iterator. This class is not meant to be instantiated directly; rather, it defines those methods which its descendants are required to implement. In addition to the methods defined by this class, descendants will also provide some method for retrieving and manipulating the "current" item. Note that when an instance of AnIterator or its descendants is created, they are expected to position themselves at the first item to be returned; this behavior allows calls to AnIterator.next to be positioned at the bottom of a loop, as shown in the following example: // Calculate a checksum for the stream function AStream.checksum: int64; var // Stores the size of the file streamSize: int64; // Stores the position in the stream before the checksum was calculated previousPosition: int64; // Used to iterate over the stream Element: AStreamIterator; begin result := 0; streamSize := Self.length; if streamSize > 0 then begin // Store the current position previousPosition := Self.position; Element := AStreamIterator(Self.iterator); while Element.continues do begin result := result + Element.value; Element.next; end; Element.free; // Seek the previous position Self.setPosition(previousPosition); end; end; Hierarchy
OverviewMethods
DescriptionMethods
Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11 |