25
25
* Defines the interface to the CachedDirectory class.
28
#ifndef DRIZZLED_CACHED_DIRECTORY_H
29
#define DRIZZLED_CACHED_DIRECTORY_H
28
#ifndef MYSYS_CACHED_DIRECTORY_H
29
#define MYSYS_CACHED_DIRECTORY_H
44
39
* A utility class to handle processing the entries/files within a directory.
46
41
* This class will allow the user to either get a list of the entry names
47
* within a given directory.
42
* within a given directory, or, alternatively, apply a function to each
43
* entry as it is read from the directory.
49
45
class CachedDirectory
63
51
std::string filename;
64
explicit Entry(std::string in_name)
52
Entry(std::string in_name)
65
53
: filename(in_name)
68
56
typedef std::vector<Entry *> Entries;
58
int error; ///< Error code stored from various syscalls
59
Entries entries; ///< Entries in the directory
62
* Encapsulate the logic to open the directory.
63
* @param[in] dirPath The path to the directory to open and read.
64
* @retval true Success
65
* @retval false Failure
67
bool open(const std::string &dirPath);
70
explicit CachedDirectory()
75
75
* Constructor taking full directory path as sole parameter.
77
77
* @param[in] Path to the directory to open
78
* @param[in] File extensions to allow
80
CachedDirectory(const std::string& in_path);
83
* Constructor taking full directory path as sole parameter.
85
* @param[in] Path to the directory to open
86
* @param[in] File extensions to allow
88
CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
89
CachedDirectory(const std::string& in_path, enum CachedDirectory::FILTER filter);
92
* Destructor. Cleans up any resources we've taken
79
CachedDirectory(const std::string &in_path);
81
* Destructor. Cleans up any resources we've taken
94
83
~CachedDirectory();
114
* Returns the current path for the cached directory
116
inline const char *getPath() const
122
* Return the list of entries read from the directory
103
* Return a list of directory entries populated in the call to open().
106
* You must call the open() method before getList() if you want the
107
* list contain any elements.
125
110
* A vector of strings containing the directory entry names.
132
std::string path; ///< Path to the directory
133
int error; ///< Error code stored from various syscalls
134
Entries entries; ///< Entries in the directory
137
* Encapsulate the logic to open the directory.
138
* @param[in] The path to the directory to open and read
140
* @retval true Success
141
* @retval false Failure
143
bool open(const std::string &in_path);
146
* Encapsulate the logic to open the directory with a set of allowed
147
* file extensions to filter for.
149
* @param[in] The path to the directory to open and read
150
* @param[in] File extensions to allow
152
* @retval true Success
153
* @retval false Failure
155
bool open(const std::string &in_path, std::set<std::string> &allowable_exts);
156
bool open(const std::string &in_path, std::set<std::string> &allowed_exts, enum CachedDirectory::FILTER filter);
158
friend std::ostream& operator<<(std::ostream& output, CachedDirectory &directory)
160
output << "CachedDirectory:(Path: " << directory.getPath() << ")\n";
162
CachedDirectory::Entries files= directory.getEntries();
164
for (CachedDirectory::Entries::iterator fileIter= files.begin();
165
fileIter != files.end(); fileIter++)
167
CachedDirectory::Entry *entry= *fileIter;
168
output << "\t(" << entry->filename << ")\n";
171
return output; // for multiple << operators.
176
} /* namespace drizzled */
178
#endif /* DRIZZLED_CACHED_DIRECTORY_H */
118
#endif /* MYSYS_CACHED_DIRECTORY_H */