1
// libTorrent - BitTorrent library
2
// Copyright (C) 2005-2006, Jari Sundell
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// In addition, as a special exception, the copyright holders give
19
// permission to link the code of portions of this program with the
20
// OpenSSL library under certain conditions as described in each
21
// individual source file, and distribute linked combinations
24
// You must obey the GNU General Public License in all respects for
25
// all of the code used other than OpenSSL. If you modify file(s)
26
// with this exception, you may extend this exception to your version
27
// of the file(s), but you are not obligated to do so. If you do not
28
// wish to do so, delete this exception statement from your version.
29
// If you delete this exception statement from all source files in the
30
// program, then also delete it here.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
37
#ifndef LIBTORRENT_FILE_LIST_ITERATOR_H
38
#define LIBTORRENT_FILE_LIST_ITERATOR_H
40
#include <torrent/common.h>
41
#include <torrent/data/file_list.h>
47
// A special purpose iterator class for iterating through FileList as
49
class LIBTORRENT_EXPORT FileListIterator {
51
typedef FileList::iterator iterator;
52
typedef File* reference;
53
typedef File** pointer;
56
explicit FileListIterator(iterator pos, uint32_t depth = 0) : m_position(pos), m_depth(depth) {}
59
bool is_empty() const;
61
bool is_entering() const;
62
bool is_leaving() const { return m_depth < 0; }
64
uint32_t depth() const { return std::abs(m_depth); }
66
iterator base() const { return m_position; }
67
reference file() const { return *m_position; }
69
reference operator *() const { return *m_position; }
70
pointer operator ->() const { return &*m_position; }
72
FileListIterator& operator ++();
73
FileListIterator& operator --();
75
FileListIterator operator ++(int);
76
FileListIterator operator --(int);
78
FileListIterator& forward_current_depth();
79
FileListIterator& backward_current_depth();
81
friend bool operator ==(const FileListIterator& left, const FileListIterator& right);
82
friend bool operator !=(const FileListIterator& left, const FileListIterator& right);
89
inline FileListIterator
90
FileListIterator::operator ++(int) {
91
FileListIterator tmp = *this;
96
inline FileListIterator
97
FileListIterator::operator --(int) {
98
FileListIterator tmp = *this;
104
operator ==(const FileListIterator& left, const FileListIterator& right) {
105
return left.m_position == right.m_position && left.m_depth == right.m_depth;
109
operator !=(const FileListIterator& left, const FileListIterator& right) {
110
return left.m_position != right.m_position || left.m_depth != right.m_depth;
113
// Take a range as input and return the next entry at the same
114
// directory depth as first. If the returned iterator equals 'last' or
115
// is_leaving() == true then the search failed.
116
class LIBTORRENT_EXPORT file_list_collapsed_iterator : private FileListIterator {
118
typedef FileListIterator base_type;
119
typedef file_list_collapsed_iterator this_type;
121
using base_type::iterator;
122
using base_type::reference;
123
using base_type::pointer;
125
using base_type::is_file;
126
using base_type::is_empty;
127
using base_type::is_entering;
128
using base_type::is_leaving;
129
using base_type::depth;
130
using base_type::file;
132
file_list_collapsed_iterator() {}
133
file_list_collapsed_iterator(const FileListIterator& src) : FileListIterator(src) {}
134
explicit file_list_collapsed_iterator(iterator pos, uint32_t depth = 0) : FileListIterator(pos, depth) {}
136
base_type base() const { return *static_cast<const base_type*>(this); }
138
this_type& operator ++() { base_type::forward_current_depth(); return *this; }
139
this_type& operator --() { base_type::backward_current_depth(); return *this; }
141
this_type operator ++(int);
142
this_type operator --(int);
144
friend bool operator ==(const file_list_collapsed_iterator& left, const file_list_collapsed_iterator& right);
145
friend bool operator !=(const file_list_collapsed_iterator& left, const file_list_collapsed_iterator& right);
149
operator ==(const file_list_collapsed_iterator& left, const file_list_collapsed_iterator& right) {
150
return left.base() == right.base();
154
operator !=(const file_list_collapsed_iterator& left, const file_list_collapsed_iterator& right) {
155
return left.base() != right.base();
158
inline file_list_collapsed_iterator
159
file_list_collapsed_iterator::operator ++(int) {
160
this_type tmp = *this;
165
inline file_list_collapsed_iterator
166
file_list_collapsed_iterator::operator --(int) {
167
this_type tmp = *this;