|
|
@@ -364,7 +364,7 @@ namespace Astralis {
|
|
|
/// <summary>
|
|
|
/// A list of HTML nodes supporting iteration and manipulation
|
|
|
/// </summary>
|
|
|
- public class MarkupNodeList : GLib.Object {
|
|
|
+ public class MarkupNodeList : Invercargill.Enumerable<MarkupNode> {
|
|
|
private MarkupDocument document;
|
|
|
private List<Xml.Node*> nodes;
|
|
|
|
|
|
@@ -398,7 +398,7 @@ namespace Astralis {
|
|
|
/// <summary>
|
|
|
/// Gets the first node, or null if empty
|
|
|
/// </summary>
|
|
|
- public MarkupNode? first {
|
|
|
+ public new MarkupNode? first {
|
|
|
owned get {
|
|
|
if (nodes.is_empty()) {
|
|
|
return null;
|
|
|
@@ -411,7 +411,7 @@ namespace Astralis {
|
|
|
/// <summary>
|
|
|
/// Gets the last node, or null if empty
|
|
|
/// </summary>
|
|
|
- public MarkupNode? last {
|
|
|
+ public new MarkupNode? last {
|
|
|
owned get {
|
|
|
if (nodes.is_empty()) {
|
|
|
return null;
|
|
|
@@ -471,44 +471,57 @@ namespace Astralis {
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Gets an enumerator for iterating over the nodes
|
|
|
+ /// Gets information about this enumerable
|
|
|
/// </summary>
|
|
|
- public Enumerator iterator() {
|
|
|
- return new Enumerator(document, nodes);
|
|
|
+ public override Invercargill.EnumerableInfo get_info() {
|
|
|
+ return new Invercargill.EnumerableInfo.infer_ultimate(this, Invercargill.EnumerableCategory.IN_MEMORY);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Enumerator for iterating over MarkupNodeList
|
|
|
+ /// Gets a tracker for iterating over the nodes
|
|
|
/// </summary>
|
|
|
- public class Enumerator {
|
|
|
+ public override Invercargill.Tracker<MarkupNode> get_tracker() {
|
|
|
+ return new NodeTracker(document, nodes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Peeks at the count without full enumeration
|
|
|
+ /// </summary>
|
|
|
+ public override uint? peek_count() {
|
|
|
+ return (uint)nodes.length();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Tracker for iterating over MarkupNodeList
|
|
|
+ /// </summary>
|
|
|
+ private class NodeTracker : Invercargill.Tracker<MarkupNode> {
|
|
|
private MarkupDocument document;
|
|
|
private unowned List<Xml.Node*> nodes;
|
|
|
private unowned List<Xml.Node*>? current;
|
|
|
|
|
|
- internal Enumerator(MarkupDocument doc, List<Xml.Node*> nodes) {
|
|
|
+ internal NodeTracker(MarkupDocument doc, List<Xml.Node*> nodes) {
|
|
|
this.document = doc;
|
|
|
this.nodes = nodes;
|
|
|
this.current = null;
|
|
|
}
|
|
|
|
|
|
- public bool move_next() {
|
|
|
+ public override MarkupNode get_next() {
|
|
|
if (current == null) {
|
|
|
current = nodes.first();
|
|
|
} else {
|
|
|
current = current.next;
|
|
|
}
|
|
|
- return current != null;
|
|
|
+ // has_next() should be called before get_next()
|
|
|
+ // Returning null here would violate the non-nullable contract
|
|
|
+ assert(current != null);
|
|
|
+ return new MarkupNode(document, current.data);
|
|
|
}
|
|
|
|
|
|
- public MarkupNode? get() {
|
|
|
+ public override bool has_next() {
|
|
|
if (current == null) {
|
|
|
- return null;
|
|
|
+ return !nodes.is_empty();
|
|
|
}
|
|
|
- return new MarkupNode(document, current.data);
|
|
|
- }
|
|
|
-
|
|
|
- public void reset() {
|
|
|
- current = null;
|
|
|
+ return current.next != null;
|
|
|
}
|
|
|
}
|
|
|
}
|