File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,46 @@ inline std::ostream& operator<<(std::ostream& os, bytes const& _bytes)
48
48
namespace util
49
49
{
50
50
51
+ namespace detail
52
+ {
53
+
54
+ template <typename Predicate>
55
+ struct RecursiveFileCollector
56
+ {
57
+ Predicate predicate;
58
+ std::vector<boost::filesystem::path> result {};
59
+
60
+ RecursiveFileCollector& operator ()(boost::filesystem::path const & _directory)
61
+ {
62
+ if (!boost::filesystem::is_directory (_directory))
63
+ return *this ;
64
+ auto iterator = boost::filesystem::directory_iterator (_directory);
65
+ auto const iteratorEnd = boost::filesystem::directory_iterator ();
66
+
67
+ while (iterator != iteratorEnd)
68
+ {
69
+ if (boost::filesystem::is_directory (iterator->status ()))
70
+ (*this )(iterator->path ());
71
+
72
+ if (predicate (iterator->path ()))
73
+ result.push_back (iterator->path ());
74
+
75
+ ++iterator;
76
+ }
77
+ return *this ;
78
+ }
79
+ };
80
+
81
+ template <typename Predicate>
82
+ RecursiveFileCollector (Predicate) -> RecursiveFileCollector<Predicate>;
83
+ }
84
+
85
+ template <typename Predicate>
86
+ std::vector<boost::filesystem::path> findFilesRecursively (boost::filesystem::path const & _rootDirectory, Predicate _predicate)
87
+ {
88
+ return detail::RecursiveFileCollector{_predicate}(_rootDirectory).result ;
89
+ }
90
+
51
91
// / Retrieves and returns the contents of the given file as a std::string.
52
92
// / If the file doesn't exist, it will throw a FileNotFound exception.
53
93
// / If the file exists but is not a regular file, it will throw NotAFile exception.
You can’t perform that action at this time.
0 commit comments