~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/cached_directory.h

  • Committer: Olaf van der Spek
  • Date: 2011-10-10 09:27:50 UTC
  • mto: (2430.1.6 rf)
  • mto: This revision was merged to the branch mainline in revision 2436.
  • Revision ID: olafvdspek@gmail.com-20111010092750-ryxgmn7zj5yvxfkf
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 *   Defines the interface to the CachedDirectory class.
26
26
 */
27
27
 
28
 
#ifndef DRIZZLED_CACHED_DIRECTORY_H
29
 
#define DRIZZLED_CACHED_DIRECTORY_H
30
 
 
31
 
#include <dirent.h>
32
 
 
33
 
#include <iostream>
 
28
#pragma once
 
29
 
 
30
#include <iosfwd>
34
31
#include <vector>
35
32
#include <set>
36
33
#include <string>
37
34
#include <cstdlib>
38
35
#include <cerrno>
39
36
 
40
 
namespace drizzled
41
 
{
 
37
namespace drizzled {
42
38
 
43
39
/**
44
40
 * A utility class to handle processing the entries/files within a directory.
49
45
class CachedDirectory
50
46
{
51
47
public:
52
 
  enum FILTER {
 
48
  enum FILTER 
 
49
  {
53
50
    NONE,
54
51
    DIRECTORY,
55
52
    FILE,
86
83
   * @param[in] File extensions to allow
87
84
   */
88
85
  CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
89
 
  CachedDirectory(const std::string& in_path, enum CachedDirectory::FILTER filter);
 
86
  CachedDirectory(const std::string& in_path, CachedDirectory::FILTER filter, bool use_full_path= false);
90
87
 
91
88
  /**
92
89
   * Destructor.  Cleans up any resources we've taken 
124
121
   * @returns
125
122
   *   A vector of strings containing the directory entry names.
126
123
   */
127
 
  inline const Entries &getEntries()
 
124
  const Entries &getEntries() const
128
125
  {
129
126
    return entries;
130
127
  }
131
128
private:
132
129
  std::string path; ///< Path to the directory
133
130
  int error; ///< Error code stored from various syscalls
 
131
  bool use_full_path;
134
132
  Entries entries; ///< Entries in the directory
135
133
 
136
134
  /**
153
151
   * @retval false Failure
154
152
   */
155
153
  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);
157
 
 
158
 
  friend std::ostream& operator<<(std::ostream& output, CachedDirectory &directory)
159
 
  {
160
 
    output << "CachedDirectory:(Path: " << directory.getPath() << ")\n";
161
 
 
162
 
    CachedDirectory::Entries files= directory.getEntries();
163
 
 
164
 
    for (CachedDirectory::Entries::iterator fileIter= files.begin();
165
 
         fileIter != files.end(); fileIter++)
166
 
    {
167
 
      CachedDirectory::Entry *entry= *fileIter;
168
 
      output << "\t(" << entry->filename << ")\n";
169
 
    }
170
 
 
171
 
    return output;  // for multiple << operators.
172
 
  }
173
 
 
 
154
  bool open(const std::string &in_path, std::set<std::string> &allowed_exts, CachedDirectory::FILTER filter);
 
155
 
 
156
  friend std::ostream& operator<<(std::ostream&, const CachedDirectory&);
174
157
};
175
158
 
176
159
} /* namespace drizzled */
177
160
 
178
 
#endif /* DRIZZLED_CACHED_DIRECTORY_H */