1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-02 14:04:22 +00:00

Support const/non-const DirIterators and SetListingViews

This commit is contained in:
King_DuckZ 2016-02-16 18:51:17 +01:00
parent 84a2617c24
commit 0a3e469951
3 changed files with 84 additions and 26 deletions

View file

@ -23,17 +23,24 @@
#include <boost/iterator/iterator_facade.hpp>
#include <memory>
#include <type_traits>
#include <ciso646>
namespace mchlib {
namespace implem {
template <bool Const> class DirIterator;
} //namespace implem
class PathName;
class SetListingView;
template <bool Const> class SetListingView;
template <bool Const> const PathName& get_pathname ( const implem::DirIterator<Const>& parIter );
namespace implem {
template <bool Const>
class DirIterator : public boost::iterator_facade<DirIterator<Const>, FileRecordData, boost::forward_traversal_tag> {
friend class mchlib::SetListingView;
friend class mchlib::SetListingView<Const>;
friend class boost::iterator_core_access;
template <bool> friend class DirIterator;
template <bool B> friend const PathName& mchlib::get_pathname ( const DirIterator<B>& parIter );
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;
@ -66,12 +73,15 @@ namespace mchlib {
};
};
template <bool Const>
class SetListingView {
struct enabler {};
public:
typedef implem::DirIterator<true> const_iterator;
typedef std::vector<FileRecordData>::const_iterator list_iterator;
typedef implem::DirIterator<false> iterator;
typedef typename implem::DirIterator<Const>::VecIterator list_iterator;
explicit SetListingView ( const const_iterator& parIter );
explicit SetListingView ( const implem::DirIterator<Const>& parIter );
SetListingView ( list_iterator parBeg, list_iterator parEnd );
SetListingView ( SetListingView&& ) = default;
~SetListingView ( void ) noexcept = default;
@ -80,6 +90,10 @@ namespace mchlib {
const_iterator cbegin ( void ) const;
const_iterator end ( void ) const;
const_iterator cend ( void ) const;
template <bool B=not Const, typename R=typename std::enable_if<B, iterator>::type>
R begin ( void );
template <bool B=not Const, typename R=typename std::enable_if<B, iterator>::type>
R end ( void );
private:
list_iterator m_begin;
@ -89,7 +103,7 @@ namespace mchlib {
class SetListing {
public:
typedef std::vector<FileRecordData> ListType;
typedef SetListingView::const_iterator const_iterator;
typedef implem::DirIterator<true> const_iterator;
explicit SetListing ( ListType&& parList, bool parSort=true );
~SetListing ( void ) noexcept;
@ -100,11 +114,18 @@ namespace mchlib {
const_iterator cend ( void ) const;
//ListType descend_copy ( const const_iterator& parItem ) const;
SetListingView make_view ( void ) const;
SetListingView<false> make_view ( void );
SetListingView<true> make_view ( void ) const;
SetListingView<true> make_cview ( void ) const;
private:
ListType m_list;
};
template <bool Const>
inline const PathName& get_pathname (const implem::DirIterator<Const>& parIter) {
return *parIter.m_base_path;
}
} //namespace mchlib
#endif