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