File: link_iterator.cpp

package info (click to toggle)
videolink 1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 368 kB
  • ctags: 502
  • sloc: cpp: 3,210; ansic: 880; makefile: 121
file content (52 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2005 Ben Hutchings <ben@decadent.org.uk>.
// See the file "COPYING" for licence details.

#include "link_iterator.hpp"

#include <cassert>

#include <nsIDOMHTMLCollection.h>
#include <nsIDOMHTMLDocument.h>

link_iterator::link_iterator()
{}

link_iterator::link_iterator(nsIDOMDocument * document)
{
    nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(document));
    if (!htmlDoc)
	return;

    htmlDoc->GetLinks(getter_AddRefs(collection_));
    assert(collection_);

    index_ = 0;
    length_ = 0;
    collection_->GetLength(&length_);
    if (length_ == 0)
	collection_ = 0;
}

already_AddRefed<nsIDOMNode> link_iterator::operator*() const
{
    assert(collection_);
    nsIDOMNode * result = 0;
    collection_->Item(index_, &result);
    assert(result);
    return dont_AddRef(result);
}

link_iterator & link_iterator::operator++()
{
    assert(collection_);
    ++index_;
    if (index_ == length_)
	collection_ = 0;
    return *this;
}

bool link_iterator::operator==(const link_iterator & other) const
{
    return (collection_ == other.collection_
	    && (!collection_ || index_ == other.index_));
}