#pragma once ///////////////////////////////////////////////////////////////////////// // MT1Q4.h - Extensible File Manager // // // // Jim Fawcett, CSE687 - Object Oriented Design, Midterm, Spring 2018 // ///////////////////////////////////////////////////////////////////////// /* * - This solution uses a template class where the template parameter * has application specific operations for discovered files and dirs. * - You could also use inheritance, and override virtual methods for * doFile and doDir in application specific derived classes. */ #include #include #include "FileSystem.h" template class FileMgr { public: using Patterns = std::vector; using Files = std::vector; using Dirs = std::vector; bool search(const std::string& path); void addPattern(const std::string& pattern) { patterns_.push_back(pattern); } private: std::vector patterns_; }; template bool FileMgr::search(const std::string& path) { if (!FileSystem::Directory::exists(path)) return false; App app; std::string fullPath = FileSystem::Path::getFullFileSpec(path); app.doDir(fullPath); for (auto patt : patterns_) { Files files = FileSystem::Directory::getFiles(fullPath, patt); for (auto file : files) app.doFile(file); } Dirs dirs = FileSystem::Directory::getDirectories(path); for (auto dir : dirs) { if (dir == "." || dir == "..") continue; std::string fullDir = fullPath + "\\" + dir; search(fullDir); } return true; }