~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/cached_directory.h

  • Committer: Monty Taylor
  • Date: 2009-08-17 18:46:08 UTC
  • mto: (1182.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090817184608-0b2emowpjr9m6le7
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.

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
#ifndef MYSYS_CACHED_DIRECTORY_H
 
29
#define MYSYS_CACHED_DIRECTORY_H
 
30
 
34
31
#include <vector>
35
 
#include <set>
36
32
#include <string>
37
 
#include <cstdlib>
38
 
#include <cerrno>
 
33
#include <dirent.h>
 
34
#include <stdlib.h>
 
35
#include <errno.h>
39
36
 
40
 
namespace drizzled
41
 
{
42
37
 
43
38
/**
44
39
 * A utility class to handle processing the entries/files within a directory.
49
44
class CachedDirectory
50
45
{
51
46
public:
52
 
  enum FILTER {
53
 
    NONE,
54
 
    DIRECTORY,
55
 
    FILE,
56
 
    MAX
57
 
  };
58
 
 
59
47
  class Entry
60
48
  {
61
 
    Entry();
62
49
  public:
63
50
    std::string filename;
64
 
    explicit Entry(std::string in_name)
 
51
    Entry(std::string in_name)
65
52
      : filename(in_name)
66
53
    {}
67
54
  };
68
55
  typedef std::vector<Entry *> Entries;
 
56
private:
 
57
  int error; ///< Error code stored from various syscalls
 
58
  Entries entries; ///< Entries in the directory
 
59
 
69
60
  /**
70
 
   * Empty Constructor.
 
61
   * Encapsulate the logic to open the directory.
 
62
   * @param[in] dirPath The path to the directory to open and read.
 
63
   * @retval true Success
 
64
   * @retval false Failure
71
65
   */
72
 
  CachedDirectory();
 
66
  bool open(const std::string &dirPath);
 
67
 
 
68
public:
 
69
  explicit CachedDirectory()
 
70
    : error(0)
 
71
  {}
73
72
      
74
73
  /**
75
74
   * Constructor taking full directory path as sole parameter.
76
75
   *
77
76
   * @param[in] Path to the directory to open
78
 
   * @param[in] File extensions to allow
79
 
   */
80
 
  CachedDirectory(const std::string& in_path); 
81
 
 
82
 
  /**
83
 
   * Constructor taking full directory path as sole parameter.
84
 
   *
85
 
   * @param[in] Path to the directory to open
86
 
   * @param[in] File extensions to allow
87
 
   */
88
 
  CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
89
 
  CachedDirectory(const std::string& in_path, enum CachedDirectory::FILTER filter);
90
 
 
91
 
  /**
92
 
   * Destructor.  Cleans up any resources we've taken 
93
 
   */
 
77
   */
 
78
 CachedDirectory(const std::string &in_path); 
 
79
 /**
 
80
  * Destructor.  Cleans up any resources we've taken 
 
81
  */
94
82
  ~CachedDirectory();
95
83
 
96
84
  /**
110
98
    return error;
111
99
  }
112
100
 
113
 
  /** 
114
 
   * Returns the current path for the cached directory
115
 
   */
116
 
  inline const char *getPath() const
117
 
  {
118
 
    return path.c_str();
119
 
  }
120
 
 
121
101
  /**
122
102
   * Return the list of entries read from the directory
123
103
   *
128
108
  {
129
109
    return entries;
130
110
  }
131
 
private:
132
 
  std::string path; ///< Path to the directory
133
 
  int error; ///< Error code stored from various syscalls
134
 
  Entries entries; ///< Entries in the directory
135
 
 
136
 
  /**
137
 
   * Encapsulate the logic to open the directory.
138
 
   * @param[in] The path to the directory to open and read
139
 
   *
140
 
   * @retval true Success
141
 
   * @retval false Failure
142
 
   */
143
 
  bool open(const std::string &in_path);
144
 
 
145
 
  /**
146
 
   * Encapsulate the logic to open the directory with a set of allowed
147
 
   * file extensions to filter for.
148
 
   *
149
 
   * @param[in] The path to the directory to open and read
150
 
   * @param[in] File extensions to allow
151
 
   *
152
 
   * @retval true Success
153
 
   * @retval false Failure
154
 
   */
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);
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
111
};
175
112
 
176
 
} /* namespace drizzled */
177
 
 
178
 
#endif /* DRIZZLED_CACHED_DIRECTORY_H */
 
113
#endif  /* MYSYS_CACHED_DIRECTORY_H */