mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Prepare to allow for non-const iterators.
WiP.
This commit is contained in:
parent
bed191c4fc
commit
b94bf308f5
2 changed files with 37 additions and 20 deletions
|
@ -15,36 +15,42 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef id040FEEC20F7B4F65A3EF67BA6460E737
|
||||
#define id040FEEC20F7B4F65A3EF67BA6460E737
|
||||
|
||||
#include "dindexer-machinery/recorddata.hpp"
|
||||
#include <vector>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <memory>
|
||||
|
||||
#ifndef id040FEEC20F7B4F65A3EF67BA6460E737
|
||||
#define id040FEEC20F7B4F65A3EF67BA6460E737
|
||||
#include <type_traits>
|
||||
|
||||
namespace mchlib {
|
||||
class PathName;
|
||||
class SetListingView;
|
||||
|
||||
namespace implem {
|
||||
class DirIterator : public boost::iterator_facade<DirIterator, FileRecordData, boost::forward_traversal_tag> {
|
||||
template <bool Const>
|
||||
class DirIterator : public boost::iterator_facade<DirIterator<Const>, FileRecordData, boost::forward_traversal_tag> {
|
||||
friend class mchlib::SetListingView;
|
||||
friend class boost::iterator_core_access;
|
||||
typedef boost::iterator_facade<DirIterator, FileRecordData, boost::random_access_traversal_tag> base_class;
|
||||
typedef base_class::difference_type difference_type;
|
||||
typedef base_class::reference reference;
|
||||
typedef boost::iterator_facade<DirIterator<Const>, FileRecordData, boost::random_access_traversal_tag> base_class;
|
||||
typedef typename base_class::difference_type difference_type;
|
||||
typedef typename base_class::reference reference;
|
||||
public:
|
||||
typedef std::vector<mchlib::FileRecordData>::const_iterator VecIterator;
|
||||
typedef typename std::conditional<
|
||||
Const,
|
||||
std::vector<mchlib::FileRecordData>::const_iterator,
|
||||
std::vector<mchlib::FileRecordData>::iterator
|
||||
>::type VecIterator;
|
||||
|
||||
DirIterator ( DirIterator&& parOther );
|
||||
DirIterator ( DirIterator<Const>&& parOther );
|
||||
DirIterator ( VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath );
|
||||
~DirIterator ( void ) noexcept;
|
||||
|
||||
private:
|
||||
void increment ( void );
|
||||
difference_type distance_to ( const DirIterator& parOther ) const;
|
||||
bool equal ( const DirIterator& parOther ) const;
|
||||
difference_type distance_to ( const DirIterator<Const>& parOther ) const;
|
||||
bool equal ( const DirIterator<Const>& parOther ) const;
|
||||
reference dereference ( void ) const;
|
||||
bool is_end ( void ) const;
|
||||
|
||||
|
@ -56,7 +62,7 @@ namespace mchlib {
|
|||
|
||||
class SetListingView {
|
||||
public:
|
||||
typedef implem::DirIterator const_iterator;
|
||||
typedef implem::DirIterator<true> const_iterator;
|
||||
typedef std::vector<FileRecordData>::const_iterator list_iterator;
|
||||
|
||||
explicit SetListingView ( const const_iterator& parIter );
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace mchlib {
|
||||
namespace {
|
||||
bool file_record_data_lt (const FileRecordData& parLeft, const FileRecordData& parRight) {
|
||||
|
@ -44,14 +45,18 @@ namespace mchlib {
|
|||
} //unnamed namespace
|
||||
|
||||
namespace implem {
|
||||
DirIterator::DirIterator (DirIterator&& parOther) :
|
||||
template class DirIterator<true>;
|
||||
|
||||
template <bool Const>
|
||||
DirIterator<Const>::DirIterator (DirIterator<Const>&& parOther) :
|
||||
m_current(std::move(parOther.m_current)),
|
||||
m_end(std::move(parOther.m_end)),
|
||||
m_base_path(std::move(parOther.m_base_path))
|
||||
{
|
||||
}
|
||||
|
||||
DirIterator::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath) :
|
||||
template <bool Const>
|
||||
DirIterator<Const>::DirIterator (VecIterator parBegin, VecIterator parEnd, std::unique_ptr<PathName>&& parBasePath) :
|
||||
m_current(parBegin),
|
||||
m_end(parEnd),
|
||||
m_base_path(std::move(parBasePath))
|
||||
|
@ -70,10 +75,12 @@ namespace mchlib {
|
|||
}
|
||||
}
|
||||
|
||||
DirIterator::~DirIterator() noexcept {
|
||||
template <bool Const>
|
||||
DirIterator<Const>::~DirIterator() noexcept {
|
||||
}
|
||||
|
||||
void DirIterator::increment() {
|
||||
template <bool Const>
|
||||
void DirIterator<Const>::increment() {
|
||||
assert(PathName(m_current->abs_path).pop_right() == *m_base_path);
|
||||
do {
|
||||
++m_current;
|
||||
|
@ -84,12 +91,14 @@ namespace mchlib {
|
|||
);
|
||||
}
|
||||
|
||||
auto DirIterator::distance_to (const DirIterator& parOther) const -> difference_type {
|
||||
template <bool Const>
|
||||
auto DirIterator<Const>::distance_to (const DirIterator<Const>& parOther) const -> difference_type {
|
||||
assert(false); //TODO: write implementation
|
||||
return std::distance(m_current, parOther.m_current);
|
||||
}
|
||||
|
||||
bool DirIterator::equal (const DirIterator& parOther) const {
|
||||
template <bool Const>
|
||||
bool DirIterator<Const>::equal (const DirIterator<Const>& parOther) const {
|
||||
return
|
||||
(m_end == parOther.m_end) and
|
||||
(
|
||||
|
@ -99,11 +108,13 @@ namespace mchlib {
|
|||
;
|
||||
}
|
||||
|
||||
auto DirIterator::dereference() const -> reference {
|
||||
template <bool Const>
|
||||
auto DirIterator<Const>::dereference() const -> reference {
|
||||
return const_cast<reference>(*m_current);
|
||||
}
|
||||
|
||||
bool DirIterator::is_end() const {
|
||||
template <bool Const>
|
||||
bool DirIterator<Const>::is_end() const {
|
||||
const bool is_this_end =
|
||||
not m_base_path or
|
||||
(m_current == m_end) or
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue