#ifndef __JSYSTEM_JGLOB__ #define __JSYSTEM_JGLOB__ #include #include #include #include /** * \file * File list. * \author mdejong */ namespace JSYSTEM {} namespace JPP { using namespace JSYSTEM; } namespace JSYSTEM { /** * Auxiliary class to list files. */ struct JGlob : public std::vector { /** * Default constructor. */ JGlob() {} /** * Constructor. * * \param pattern pattern */ JGlob(const std::string& pattern) { (*this)(pattern); } /** * Constructor. * * \param buffer list of patterns */ JGlob(const std::vector& buffer) { (*this)(buffer); } /** * Get list of files. * * \param pattern pattern * \return list of files */ const JGlob& operator()(const std::string& pattern) { this->clear(); evaluate(pattern); return *this; } /** * Get list of files. * * * \param buffer list of patterns * \return list of files */ const JGlob& operator()(const std::vector& buffer) { this->clear(); for (const std::string& pattern : buffer) { evaluate(pattern); } return *this; } private: /** * Process pattern. * * \param pattern pattern */ void evaluate(const std::string& pattern) { memset(&buffer, 0, sizeof(buffer)); const int value = glob(pattern.c_str(), GLOB_TILDE | GLOB_BRACE, NULL, &buffer); if (value == 0) { for(size_t i = 0; i < buffer.gl_pathc; ++i) { this->push_back(buffer.gl_pathv[i]); } } else { this->push_back(pattern); } globfree(&buffer); } glob_t buffer; }; /** * Function object to get list of files for given pattern. */ static JGlob getFilenames; } #endif