00001 00008 #include "eleve/config.hpp" 00009 00010 #include "runtime1.hpp" 00011 00012 #include <fstream> 00013 00014 #include <boost/filesystem/operations.hpp> 00015 #include <ql/utilities/tracing.hpp> 00016 00017 namespace eepgwde { namespace detail { 00018 00019 static boost::regex_constants::syntax_option_type 00020 flags = boost::regex_constants::basic; 00021 00022 namespace fs = boost::filesystem; 00023 00024 class Facilities::Impl { 00025 public: 00026 Impl() throw() {} 00027 ~Impl() throw() {} 00028 Facilities *owner; 00029 }; 00030 00032 Facilities::Facilities() throw(std::exception) : 00033 impl(new Facilities::Impl) { 00034 impl->owner = this; 00035 } 00036 00037 Facilities::~Facilities() throw(std::exception) {} 00038 00041 00042 int Facilities::files(std::insert_iterator< std::set<fs::path> > set_, 00043 fs::path full_path, boost::regex re) const { 00044 unsigned long file_count = 0; 00045 unsigned long err_count = 0; 00046 unsigned long matches = 0; 00047 00048 if (!fs::exists( full_path )) return -1; 00049 00050 if (!fs::is_directory( full_path)) return -1; 00051 00052 fs::directory_iterator end_iter; 00053 std::string t; 00054 boost::smatch what; 00055 00056 for ( fs::directory_iterator dir_itr( full_path ); 00057 dir_itr != end_iter; 00058 ++dir_itr ) { 00059 try { 00060 if ( fs::is_regular( dir_itr->status() ) ) { 00061 ++file_count; 00062 00063 t = dir_itr->path().leaf(); 00064 if (boost::regex_search(t, what, re)) { 00065 *set_++=dir_itr->path(); 00066 ++matches; 00067 } 00068 } 00069 } 00070 catch ( const std::exception & ex ) { 00071 ++err_count; 00072 } 00073 } 00074 return matches; 00075 } 00076 00081 00082 int Facilities::files 00083 (std::insert_iterator< std::set<fs::path> > set_) const { 00084 return files(set_, fs::path("."), boost::regex(".+") ); 00085 } 00086 00088 std::vector<std::string> Facilities::readlines(const fs::path & s) 00089 const throw(std::exception) { 00090 std::ifstream ifs(s.string().c_str(), ios::in); 00091 std::istream & is = ifs; 00092 return readlines(is); 00093 } 00094 00096 std::vector<std::string> Facilities::readlines(std::istream & is) const 00097 throw(std::exception) { 00098 if (is.bad()) { 00099 QL_TRACE("bad input stream"); 00100 throw std::runtime_error("input stream is bad"); 00101 } 00102 00103 std::vector<std::string> results; 00104 00105 char buffer[100]; 00106 while (!is.getline(buffer, 100).eof()) { 00107 results.push_back(std::string(buffer)); 00108 } 00109 00110 return results; 00111 } 00112 00113 }}