/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see .
*/
#ifndef id040FEEC20F7B4F65A3EF67BA6460E737
#define id040FEEC20F7B4F65A3EF67BA6460E737
#include "dindexer-machinery/recorddata.hpp"
#include
#include
#include
#include
#include
namespace mchlib {
namespace implem {
template class DirIterator;
} //namespace implem
class PathName;
template class SetListingView;
template const PathName& get_pathname ( const implem::DirIterator& parIter );
template
implem::DirIterator first_file ( const SetListingView& parList );
template
implem::DirIterator first_file ( SetListingView& parList );
namespace implem {
template
class DirIterator : public boost::iterator_facade, FileRecordData, boost::forward_traversal_tag> {
friend class mchlib::SetListingView;
friend class boost::iterator_core_access;
template friend class DirIterator;
template friend const PathName& mchlib::get_pathname ( const DirIterator& parIter );
typedef boost::iterator_facade, FileRecordData, boost::random_access_traversal_tag> base_class;
typedef typename base_class::difference_type difference_type;
typedef typename base_class::reference reference;
struct enabler {};
public:
typedef typename std::conditional<
Const,
std::vector::const_iterator,
std::vector::iterator
>::type VecIterator;
DirIterator ( DirIterator&& parOther );
template
DirIterator ( DirIterator&& parOther, typename std::enable_if::VecIterator, VecIterator>::value, enabler>::type = enabler() );
DirIterator ( VecIterator parBegin, VecIterator parEnd, std::unique_ptr&& parBasePath );
~DirIterator ( void ) noexcept;
private:
void increment ( void );
difference_type distance_to ( const DirIterator& parOther ) const;
template
bool equal ( const DirIterator& parOther ) const;
reference dereference ( void ) const;
bool is_end ( void ) const;
VecIterator m_current;
VecIterator m_end;
std::unique_ptr m_base_path;
};
};
template
class SetListingView {
struct enabler {};
public:
typedef implem::DirIterator const_iterator;
typedef implem::DirIterator iterator;
typedef typename implem::DirIterator::VecIterator list_iterator;
explicit SetListingView ( const implem::DirIterator& parIter );
SetListingView ( list_iterator parBeg, list_iterator parEnd );
SetListingView ( SetListingView&& ) = default;
~SetListingView ( void ) noexcept = default;
const_iterator begin ( void ) const;
const_iterator cbegin ( void ) const;
const_iterator end ( void ) const;
const_iterator cend ( void ) const;
template ::type>
R begin ( void );
template ::type>
R end ( void );
private:
list_iterator m_begin;
list_iterator m_end;
};
class SetListing {
public:
typedef std::vector ListType;
typedef implem::DirIterator const_iterator;
explicit SetListing ( ListType&& parList, bool parSort=true );
~SetListing ( void ) noexcept;
const_iterator begin ( void ) const;
const_iterator cbegin ( void ) const;
const_iterator end ( void ) const;
const_iterator cend ( void ) const;
//ListType descend_copy ( const const_iterator& parItem ) const;
SetListingView make_view ( void );
SetListingView make_view ( void ) const;
SetListingView make_cview ( void ) const;
private:
ListType m_list;
};
template
inline const PathName& get_pathname (const implem::DirIterator& parIter) {
return *parIter.m_base_path;
}
template
inline implem::DirIterator first_file (const SetListingView& parList) {
auto end = parList.end();
for (auto it = parList.begin(); it != end; ++it) {
if (not it->is_directory)
return std::move(it);
}
return parList.end();
}
template
inline implem::DirIterator first_file (SetListingView& parList) {
auto end = parList.end();
for (auto it = parList.begin(); it != end; ++it) {
if (not it->is_directory)
return std::move(it);
}
return parList.end();
}
} //namespace mchlib
#endif