1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
5 |
*
|
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.
|
|
9 |
*
|
|
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.
|
|
14 |
*
|
|
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
|
|
18 |
*/
|
|
19 |
||
20 |
/**
|
|
21 |
* @file
|
|
22 |
* cached_directory.h
|
|
23 |
*
|
|
24 |
* @brief
|
|
25 |
* Defines the interface to the CachedDirectory class.
|
|
26 |
*/
|
|
27 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
28 |
#pragma once
|
1241.9.44
by Monty Taylor
Made magic with cached_directory. |
29 |
|
2371.1.1
by Brian Aker
Fedora fix/use fwd header for iostream. |
30 |
#include <iosfwd> |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
31 |
#include <vector> |
1183.1.27
by Brian Aker
Fix issue where there are too many files in data directory. We now only |
32 |
#include <set> |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
33 |
#include <string> |
1241.9.44
by Monty Taylor
Made magic with cached_directory. |
34 |
#include <cstdlib> |
35 |
#include <cerrno> |
|
36 |
||
2240.2.1
by Olaf van der Spek
Refactor |
37 |
namespace drizzled { |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
38 |
|
39 |
/**
|
|
40 |
* A utility class to handle processing the entries/files within a directory.
|
|
41 |
*
|
|
42 |
* This class will allow the user to either get a list of the entry names
|
|
1108.4.1
by David Shrewsbury
Corrected comments |
43 |
* within a given directory.
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
44 |
*/
|
45 |
class CachedDirectory |
|
46 |
{
|
|
47 |
public: |
|
2240.2.1
by Olaf van der Spek
Refactor |
48 |
enum FILTER |
49 |
{
|
|
1273.13.9
by Brian Aker
Updating test cases + added Drizzle specific schema_names and schema_info. |
50 |
NONE, |
51 |
DIRECTORY, |
|
52 |
FILE, |
|
53 |
MAX
|
|
54 |
};
|
|
55 |
||
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
56 |
class Entry |
57 |
{
|
|
1259.3.4
by Monty Taylor
Just a little bit of a cleanup. |
58 |
Entry(); |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
59 |
public: |
60 |
std::string filename; |
|
1259.3.4
by Monty Taylor
Just a little bit of a cleanup. |
61 |
explicit Entry(std::string in_name) |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
62 |
: filename(in_name) |
63 |
{}
|
|
64 |
};
|
|
65 |
typedef std::vector<Entry *> Entries; |
|
66 |
/**
|
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
67 |
* Empty Constructor.
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
68 |
*/
|
1183.1.5
by Brian Aker
Reworked getTableNames() interface. Way simpler, less mallocs.... |
69 |
CachedDirectory(); |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
70 |
|
71 |
/**
|
|
72 |
* Constructor taking full directory path as sole parameter.
|
|
73 |
*
|
|
74 |
* @param[in] Path to the directory to open
|
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
75 |
* @param[in] File extensions to allow
|
76 |
*/
|
|
77 |
CachedDirectory(const std::string& in_path); |
|
78 |
||
79 |
/**
|
|
80 |
* Constructor taking full directory path as sole parameter.
|
|
81 |
*
|
|
82 |
* @param[in] Path to the directory to open
|
|
83 |
* @param[in] File extensions to allow
|
|
84 |
*/
|
|
85 |
CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts); |
|
2246.4.1
by Olaf van der Spek
Use BOOST_FOREACH |
86 |
CachedDirectory(const std::string& in_path, CachedDirectory::FILTER filter, bool use_full_path= false); |
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
87 |
|
88 |
/**
|
|
89 |
* Destructor. Cleans up any resources we've taken
|
|
90 |
*/
|
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
91 |
~CachedDirectory(); |
92 |
||
93 |
/**
|
|
94 |
* Returns whether the CachedDirectory object is in a failed state
|
|
95 |
*/
|
|
96 |
inline bool fail() const |
|
97 |
{
|
|
98 |
return error != 0; |
|
99 |
}
|
|
100 |
||
101 |
/**
|
|
102 |
* Returns the stored error code of the last action the directory
|
|
103 |
* object took (open, read, etc)
|
|
104 |
*/
|
|
105 |
inline int getError() const |
|
106 |
{
|
|
107 |
return error; |
|
108 |
}
|
|
109 |
||
1183.1.5
by Brian Aker
Reworked getTableNames() interface. Way simpler, less mallocs.... |
110 |
/**
|
111 |
* Returns the current path for the cached directory
|
|
112 |
*/
|
|
113 |
inline const char *getPath() const |
|
114 |
{
|
|
115 |
return path.c_str(); |
|
116 |
}
|
|
117 |
||
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
118 |
/**
|
1108.4.1
by David Shrewsbury
Corrected comments |
119 |
* Return the list of entries read from the directory
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
120 |
*
|
121 |
* @returns
|
|
122 |
* A vector of strings containing the directory entry names.
|
|
123 |
*/
|
|
2246.4.1
by Olaf van der Spek
Use BOOST_FOREACH |
124 |
const Entries &getEntries() const |
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
125 |
{
|
126 |
return entries; |
|
127 |
}
|
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
128 |
private: |
129 |
std::string path; ///< Path to the directory |
|
130 |
int error; ///< Error code stored from various syscalls |
|
1960.1.9
by Brian Aker
Merge in lock testing code/additional fix for tests. |
131 |
bool use_full_path; |
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
132 |
Entries entries; ///< Entries in the directory |
1183.1.5
by Brian Aker
Reworked getTableNames() interface. Way simpler, less mallocs.... |
133 |
|
134 |
/**
|
|
135 |
* Encapsulate the logic to open the directory.
|
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
136 |
* @param[in] The path to the directory to open and read
|
137 |
*
|
|
1183.1.5
by Brian Aker
Reworked getTableNames() interface. Way simpler, less mallocs.... |
138 |
* @retval true Success
|
139 |
* @retval false Failure
|
|
140 |
*/
|
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
141 |
bool open(const std::string &in_path); |
1183.1.5
by Brian Aker
Reworked getTableNames() interface. Way simpler, less mallocs.... |
142 |
|
1200.2.2
by Jay Pipes
Cleans up a few things in CachedDirectory class: |
143 |
/**
|
144 |
* Encapsulate the logic to open the directory with a set of allowed
|
|
145 |
* file extensions to filter for.
|
|
146 |
*
|
|
147 |
* @param[in] The path to the directory to open and read
|
|
148 |
* @param[in] File extensions to allow
|
|
149 |
*
|
|
150 |
* @retval true Success
|
|
151 |
* @retval false Failure
|
|
152 |
*/
|
|
153 |
bool open(const std::string &in_path, std::set<std::string> &allowable_exts); |
|
2246.4.1
by Olaf van der Spek
Use BOOST_FOREACH |
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&); |
|
1089.2.1
by David Shrewsbury
Add a new CachedDirectory class that handles opendir/readdir operations for all systems. |
157 |
};
|
158 |
||
1241.9.44
by Monty Taylor
Made magic with cached_directory. |
159 |
} /* namespace drizzled */ |
160 |