summaryrefslogtreecommitdiff
path: root/poppler-glib/src/index_iter.hg
blob: 086c805c4921503ea907bdd52540a827c92d770b (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Copyright (c) 2010  Glenn Rice <glennricster@gmail.com>
 *
 * This file is part of poppler-glibmm.
 *
 * poppler-glibmm is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * poppler-glibmm is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

_DEFS(poppler-glibmm,poppler-glib)
_CC_INCLUDE(poppler.h)
#include <poppler-glibmm/action.h>

namespace Poppler
{

/** Poppler::IndexIter is used to iterate through the index of a document
 * 
 * Certain documents have an index associated with them.  This index can be
 * used to help the user navigate the document, and is similar to a table of
 * contents.  Each node in the index will contain a Poppler::Action that can be
 * displayed to the user - typically a Poppler::ACTION_GOTO_DEST or a
 * Poppler::ACTION_URI.
 *
 * Here is a simple example of some code that walks the full index:
 *
 * @code
 * void walk_index(const Poppler::IndexIter& iter)
 * {
 *     do
 *     {
 *         // Get the the action and do something with it
 *         IndexIter child = iter.get_child();
 *         if (child) walk_index(child);
 *     }
 *     while (iter.next());
 * }
 * ...
 * {
 *     IndexIter iter = document->index_iter_new();
 *     if (iter) walk_index(iter);
 * }
 * @endcode
 **/
class IndexIter
{
  _CLASS_BOXEDTYPE(IndexIter, PopplerIndexIter, NONE, poppler_index_iter_copy, poppler_index_iter_free)
  _IGNORE(poppler_index_iter_copy, poppler_index_iter_free)

  public:
    _WRAP_METHOD(IndexIter get_child() const, poppler_index_iter_get_child)
    _WRAP_METHOD(bool is_open() const, poppler_index_iter_is_open)
    _WRAP_METHOD(Action get_action() const, poppler_index_iter_get_action)
    _WRAP_METHOD(bool next() const, poppler_index_iter_next)

    /** This typedef is just to make it more obvious that
     * our operator const void* should be used like operator bool().
     */
    typedef const void* BoolExpr;

    /** Tests whether the IndexIter is valid.
     * For instance,
     * @code
     * if (index_iter) do_something()
     * @endcode
     */
    inline operator BoolExpr() const { return gobj() ? GINT_TO_POINTER(1) : 0; }

  private:
    /** Relational operators are deleted to prevent invalid conversion
     * to const void*.
     */
    bool operator<(const IndexIter& src) const;

    /// See operator<().
    bool operator<=(const IndexIter& src) const;

    /// See operator<().
    bool operator>(const IndexIter& src) const;

    /// See operator<().
    bool operator>=(const IndexIter& src) const;

    /// See operator<().
    bool operator==(const IndexIter& src) const;

    /// See operator<().
    bool operator!=(const IndexIter& src) const;
};

} // namespace Poppler