1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
* Defines the interface to the CachedDirectory class.
28
#ifndef DRIZZLED_CACHED_DIRECTORY_H
29
#define DRIZZLED_CACHED_DIRECTORY_H
44
* A utility class to handle processing the entries/files within a directory.
46
* This class will allow the user to either get a list of the entry names
47
* within a given directory.
64
explicit Entry(std::string in_name)
68
typedef std::vector<Entry *> Entries;
75
* Constructor taking full directory path as sole parameter.
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, bool use_full_path= false);
92
* Destructor. Cleans up any resources we've taken
97
* Returns whether the CachedDirectory object is in a failed state
99
inline bool fail() const
105
* Returns the stored error code of the last action the directory
106
* object took (open, read, etc)
108
inline int getError() const
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
125
* A vector of strings containing the directory entry names.
127
inline const Entries &getEntries()
132
std::string path; ///< Path to the directory
133
int error; ///< Error code stored from various syscalls
135
Entries entries; ///< Entries in the directory
138
* Encapsulate the logic to open the directory.
139
* @param[in] The path to the directory to open and read
141
* @retval true Success
142
* @retval false Failure
144
bool open(const std::string &in_path);
147
* Encapsulate the logic to open the directory with a set of allowed
148
* file extensions to filter for.
150
* @param[in] The path to the directory to open and read
151
* @param[in] File extensions to allow
153
* @retval true Success
154
* @retval false Failure
156
bool open(const std::string &in_path, std::set<std::string> &allowable_exts);
157
bool open(const std::string &in_path, std::set<std::string> &allowed_exts, enum CachedDirectory::FILTER filter);
159
friend std::ostream& operator<<(std::ostream& output, CachedDirectory &directory)
161
output << "CachedDirectory:(Path: " << directory.getPath() << ")\n";
163
CachedDirectory::Entries files= directory.getEntries();
165
for (CachedDirectory::Entries::iterator fileIter= files.begin();
166
fileIter != files.end(); fileIter++)
168
CachedDirectory::Entry *entry= *fileIter;
169
output << "\t(" << entry->filename << ")\n";
172
return output; // for multiple << operators.
177
} /* namespace drizzled */
179
#endif /* DRIZZLED_CACHED_DIRECTORY_H */