2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 Eugene Shalygin
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
33 // Interval is defined via [first;last]
34 template <typename Index
>
38 using IndexType
= Index
;
40 constexpr IndexInterval(const IndexType first
, const IndexType last
)
44 Q_ASSERT(first
<= last
);
47 constexpr IndexType
first() const
52 constexpr IndexType
last() const
63 constexpr IndexInterval
<T
> makeInterval(const T first
, const T last
)
68 // range is defined via first index and size
69 template <typename Index
, typename IndexDiff
= Index
>
73 using IndexType
= Index
;
74 using IndexDiffType
= IndexDiff
;
79 explicit constexpr Iterator(const IndexType index
)
84 constexpr Iterator(const Iterator
&) = default;
86 constexpr IndexType
operator*() const
91 constexpr Iterator
&operator++()
97 constexpr Iterator
operator++(int)
99 const Iterator iter
{*this};
104 constexpr bool operator==(const Iterator
&other
) const
106 return (*(*this) == *other
);
109 constexpr bool operator!=(const Iterator
&other
) const
111 return !(*this == other
);
118 constexpr IndexRange()
124 constexpr IndexRange(const IndexType first
, const IndexDiffType size
)
130 constexpr IndexRange(const IndexInterval
<IndexType
> &interval
)
131 : m_first
{interval
.first()}
132 , m_size
{interval
.last() - interval
.first() + 1}
136 constexpr Iterator
begin() const
138 return Iterator
{m_first
};
141 constexpr Iterator
end() const
143 return Iterator
{m_first
+ m_size
};
146 constexpr IndexDiffType
size() const
151 constexpr IndexType
first() const
156 constexpr IndexType
last() const
158 return (m_first
+ m_size
- 1);
161 constexpr bool isEmpty() const
163 return (m_size
== 0);
168 IndexDiffType m_size
;