Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00028 #pragma once
00029
00030 #include <dirent.h>
00031
00032 #include <iostream>
00033 #include <vector>
00034 #include <set>
00035 #include <string>
00036 #include <cstdlib>
00037 #include <cerrno>
00038
00039 namespace drizzled
00040 {
00041
00048 class CachedDirectory
00049 {
00050 public:
00051 enum FILTER {
00052 NONE,
00053 DIRECTORY,
00054 FILE,
00055 MAX
00056 };
00057
00058 class Entry
00059 {
00060 Entry();
00061 public:
00062 std::string filename;
00063 explicit Entry(std::string in_name)
00064 : filename(in_name)
00065 {}
00066 };
00067 typedef std::vector<Entry *> Entries;
00071 CachedDirectory();
00072
00079 CachedDirectory(const std::string& in_path);
00080
00087 CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
00088 CachedDirectory(const std::string& in_path, enum CachedDirectory::FILTER filter, bool use_full_path= false);
00089
00093 ~CachedDirectory();
00094
00098 inline bool fail() const
00099 {
00100 return error != 0;
00101 }
00102
00107 inline int getError() const
00108 {
00109 return error;
00110 }
00111
00115 inline const char *getPath() const
00116 {
00117 return path.c_str();
00118 }
00119
00126 inline const Entries &getEntries()
00127 {
00128 return entries;
00129 }
00130 private:
00131 std::string path;
00132 int error;
00133 bool use_full_path;
00134 Entries entries;
00135
00143 bool open(const std::string &in_path);
00144
00155 bool open(const std::string &in_path, std::set<std::string> &allowable_exts);
00156 bool open(const std::string &in_path, std::set<std::string> &allowed_exts, enum CachedDirectory::FILTER filter);
00157
00158 friend std::ostream& operator<<(std::ostream& output, CachedDirectory &directory)
00159 {
00160 output << "CachedDirectory:(Path: " << directory.getPath() << ")\n";
00161
00162 CachedDirectory::Entries files= directory.getEntries();
00163
00164 for (CachedDirectory::Entries::iterator fileIter= files.begin();
00165 fileIter != files.end(); fileIter++)
00166 {
00167 CachedDirectory::Entry *entry= *fileIter;
00168 output << "\t(" << entry->filename << ")\n";
00169 }
00170
00171 return output;
00172 }
00173
00174 };
00175
00176 }
00177