From 8b1b9c48f4ee0ed4e527ef56d7f9df3233451712 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 20 Feb 2016 01:34:46 +0100 Subject: [PATCH] Flattening is useful, so move it out of the unit test. --- .../set_listing_helpers.hpp | 30 +++++++++++++++++++ test/unit/test_diriterator.cpp | 18 ++++------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/include/dindexer-machinery/set_listing_helpers.hpp b/include/dindexer-machinery/set_listing_helpers.hpp index 3d9efa7..1250c7c 100644 --- a/include/dindexer-machinery/set_listing_helpers.hpp +++ b/include/dindexer-machinery/set_listing_helpers.hpp @@ -21,6 +21,7 @@ #include "set_listing.hpp" #include #include +#include namespace mchlib { template @@ -35,6 +36,25 @@ namespace mchlib { template std::size_t count_listing_items_recursive ( const SetListingView& parList ); + template + std::vector::type> + flattened_listing ( const mchlib::SetListingView& parContent ); + + namespace implem { + template + void flattened_listing (const mchlib::SetListingView& parContent, std::vector::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(itcurr), parOut); + } + } + } + } //namespace implem + template inline std::size_t count_listing_dirs (const SetListingView& parList) { @@ -81,6 +101,16 @@ namespace mchlib { } return retval; } + + template + inline + std::vector::type> + flattened_listing (const mchlib::SetListingView& parContent) { + std::vector::type> retval; + + implem::flattened_listing(parContent, retval); + return std::move(retval); + } } //namespace mchlib #endif diff --git a/test/unit/test_diriterator.cpp b/test/unit/test_diriterator.cpp index 32c9ca8..1cbcfb6 100644 --- a/test/unit/test_diriterator.cpp +++ b/test/unit/test_diriterator.cpp @@ -16,6 +16,7 @@ */ #include "dindexer-machinery/set_listing.hpp" +#include "dindexer-machinery/set_listing_helpers.hpp" #include "helpers/lengthof.h" #include #include @@ -25,17 +26,6 @@ //TEST_F for class namespace { - void flatten_filelist (const mchlib::SetListingView& parContent, std::vector& 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(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 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) {