mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-02 14:04:22 +00:00
Flattening is useful, so move it out of the unit test.
This commit is contained in:
parent
f31463480f
commit
8b1b9c48f4
2 changed files with 36 additions and 12 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "set_listing.hpp"
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
namespace mchlib {
|
||||
template <bool Const>
|
||||
|
@ -35,6 +36,25 @@ namespace mchlib {
|
|||
template <bool Const>
|
||||
std::size_t count_listing_items_recursive ( const SetListingView<Const>& parList );
|
||||
|
||||
template <bool Const>
|
||||
std::vector<typename std::conditional<Const, const FileRecordData*, FileRecordData*>::type>
|
||||
flattened_listing ( const mchlib::SetListingView<Const>& parContent );
|
||||
|
||||
namespace implem {
|
||||
template <bool Const>
|
||||
void flattened_listing (const mchlib::SetListingView<Const>& parContent, std::vector<typename std::conditional<Const, const FileRecordData*, FileRecordData*>::type>& parOut) {
|
||||
const auto end = parContent.end();
|
||||
|
||||
for (auto itcurr = parContent.cbegin(); itcurr != end; ++itcurr) {
|
||||
parOut.push_back(&*itcurr);
|
||||
|
||||
if (itcurr->is_directory) {
|
||||
flattened_listing(mchlib::SetListingView<Const>(itcurr), parOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //namespace implem
|
||||
|
||||
template <bool Const>
|
||||
inline
|
||||
std::size_t count_listing_dirs (const SetListingView<Const>& parList) {
|
||||
|
@ -81,6 +101,16 @@ namespace mchlib {
|
|||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <bool Const>
|
||||
inline
|
||||
std::vector<typename std::conditional<Const, const FileRecordData*, FileRecordData*>::type>
|
||||
flattened_listing (const mchlib::SetListingView<Const>& parContent) {
|
||||
std::vector<typename std::conditional<Const, const FileRecordData*, FileRecordData*>::type> retval;
|
||||
|
||||
implem::flattened_listing(parContent, retval);
|
||||
return std::move(retval);
|
||||
}
|
||||
} //namespace mchlib
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "dindexer-machinery/set_listing.hpp"
|
||||
#include "dindexer-machinery/set_listing_helpers.hpp"
|
||||
#include "helpers/lengthof.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
|
@ -25,17 +26,6 @@
|
|||
//TEST_F for class
|
||||
|
||||
namespace {
|
||||
void flatten_filelist (const mchlib::SetListingView<true>& parContent, std::vector<std::string>& parOut) {
|
||||
const auto end = parContent.end();
|
||||
|
||||
for (auto itcurr = parContent.cbegin(); itcurr != end; ++itcurr) {
|
||||
parOut.push_back(itcurr->abs_path);
|
||||
|
||||
if (itcurr->is_directory) {
|
||||
flatten_filelist(mchlib::SetListingView<true>(itcurr), parOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
TEST(machinery, diriterator) {
|
||||
|
@ -174,8 +164,12 @@ TEST(machinery, diriterator) {
|
|||
EXPECT_EQ("Cowboy Bebop - Tank - The Best", i->abs_path);
|
||||
|
||||
std::vector<std::string> flattened;
|
||||
auto flattened_ptrs = mchlib::flattened_listing(lst.make_cview());
|
||||
flattened.reserve(lengthof(expected_list));
|
||||
flatten_filelist(lst.make_cview(), flattened);
|
||||
for (const auto itm : flattened_ptrs) {
|
||||
flattened.push_back(itm->abs_path);
|
||||
}
|
||||
|
||||
EXPECT_EQ(lengthof(expected_list), flattened.size());
|
||||
const auto count = std::min(lengthof(expected_list), flattened.size());
|
||||
for (std::size_t z = 0; z < count; ++z) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue