]> git.decadent.org.uk Git - videolink.git/blob - link_iterator.cpp
Brought documentation up to date.
[videolink.git] / link_iterator.cpp
1 // Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #include "link_iterator.hpp"
5
6 #include <cassert>
7
8 #include <nsIDOMHTMLCollection.h>
9 #include <nsIDOMHTMLDocument.h>
10
11 link_iterator::link_iterator()
12 {}
13
14 link_iterator::link_iterator(nsIDOMDocument * document)
15 {
16     nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(document));
17     if (!htmlDoc)
18         return;
19
20     htmlDoc->GetLinks(getter_AddRefs(collection_));
21     assert(collection_);
22
23     index_ = 0;
24     length_ = 0;
25     collection_->GetLength(&length_);
26     if (length_ == 0)
27         collection_ = 0;
28 }
29
30 already_AddRefed<nsIDOMNode> link_iterator::operator*() const
31 {
32     assert(collection_);
33     nsIDOMNode * result = 0;
34     collection_->Item(index_, &result);
35     assert(result);
36     return dont_AddRef(result);
37 }
38
39 link_iterator & link_iterator::operator++()
40 {
41     assert(collection_);
42     ++index_;
43     if (index_ == length_)
44         collection_ = 0;
45     return *this;
46 }
47
48 bool link_iterator::operator==(const link_iterator & other) const
49 {
50     return (collection_ == other.collection_
51             && (!collection_ || index_ == other.index_));
52 }