~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/cached_directory.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-11-28 22:02:19 UTC
  • mfrom: (1228 push)
  • mto: (1228.4.1 push)
  • mto: This revision was merged to the branch mainline in revision 1234.
  • Revision ID: osullivan.padraig@gmail.com-20091128220219-m3x28m8q2unbirke
MergeĀ fromĀ trunk.

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>
 
28
#ifndef MYSYS_CACHED_DIRECTORY_H
 
29
#define MYSYS_CACHED_DIRECTORY_H
32
30
 
33
31
#include <iostream>
34
32
#include <vector>
35
33
#include <set>
36
34
#include <string>
37
 
#include <cstdlib>
38
 
#include <cerrno>
 
35
#include <dirent.h>
 
36
#include <stdlib.h>
 
37
#include <errno.h>
39
38
 
40
 
namespace drizzled
41
 
{
42
39
 
43
40
/**
44
41
 * A utility class to handle processing the entries/files within a directory.
49
46
class CachedDirectory
50
47
{
51
48
public:
52
 
  enum FILTER {
53
 
    NONE,
54
 
    DIRECTORY,
55
 
    FILE,
56
 
    MAX
57
 
  };
58
 
 
59
49
  class Entry
60
50
  {
61
 
    Entry();
62
51
  public:
63
52
    std::string filename;
64
 
    explicit Entry(std::string in_name)
 
53
    Entry(std::string in_name)
65
54
      : filename(in_name)
66
55
    {}
67
56
  };
86
75
   * @param[in] File extensions to allow
87
76
   */
88
77
  CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
89
 
  CachedDirectory(const std::string& in_path, enum CachedDirectory::FILTER filter);
90
78
 
91
79
  /**
92
80
   * Destructor.  Cleans up any resources we've taken 
153
141
   * @retval false Failure
154
142
   */
155
143
  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
 
 
174
144
};
175
145
 
176
 
} /* namespace drizzled */
177
 
 
178
 
#endif /* DRIZZLED_CACHED_DIRECTORY_H */
 
146
#endif /* MYSYS_CACHED_DIRECTORY_H */