]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dir.h
added support for POST method and alternate ports (part of patch 649438)
[wxWidgets.git] / include / wx / dir.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dir.h
3 // Purpose: wxDir is a class for enumerating the files in a directory
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 08.12.99
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DIR_H_
13 #define _WX_DIR_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "dir.h"
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/string.h"
21 #include "wx/arrstr.h"
22 #endif
23
24 // ----------------------------------------------------------------------------
25 // constants
26 // ----------------------------------------------------------------------------
27
28 // these flags define what kind of filenames is included in the list of files
29 // enumerated by GetFirst/GetNext
30 enum
31 {
32 wxDIR_FILES = 0x0001, // include files
33 wxDIR_DIRS = 0x0002, // include directories
34 wxDIR_HIDDEN = 0x0004, // include hidden files
35 wxDIR_DOTDOT = 0x0008, // include '.' and '..'
36
37 // by default, enumerate everything except '.' and '..'
38 wxDIR_DEFAULT = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
39 };
40
41 // these constants are possible return value of wxDirTraverser::OnDir()
42 enum wxDirTraverseResult
43 {
44 wxDIR_IGNORE = -1, // ignore this directory but continue with others
45 wxDIR_STOP, // stop traversing
46 wxDIR_CONTINUE // continue into this directory
47 };
48
49 // ----------------------------------------------------------------------------
50 // wxDirTraverser: helper class for wxDir::Traverse()
51 // ----------------------------------------------------------------------------
52
53 class WXDLLIMPEXP_BASE wxDirTraverser
54 {
55 public:
56 // called for each file found by wxDir::Traverse()
57 //
58 // return wxDIR_STOP or wxDIR_CONTINUE from here (wxDIR_IGNORE doesn't
59 // make sense)
60 virtual wxDirTraverseResult OnFile(const wxString& filename) = 0;
61
62 // called for each directory found by wxDir::Traverse()
63 //
64 // return one of the enum elements defined above
65 virtual wxDirTraverseResult OnDir(const wxString& dirname) = 0;
66
67 // called for each directory which we couldn't open during our traversal
68 // of the directory tyree
69 //
70 // this method can also return either wxDIR_STOP, wxDIR_IGNORE or
71 // wxDIR_CONTINUE but the latter is treated specially: it means to retry
72 // opening the directory and so may lead to infinite loop if it is
73 // returned unconditionally, be careful with this!
74 //
75 // the base class version always returns wxDIR_IGNORE
76 virtual wxDirTraverseResult OnOpenError(const wxString& dirname);
77 };
78
79 // ----------------------------------------------------------------------------
80 // wxDir: portable equivalent of {open/read/close}dir functions
81 // ----------------------------------------------------------------------------
82
83 class WXDLLIMPEXP_BASE wxDirData;
84
85 class WXDLLIMPEXP_BASE wxDir
86 {
87 public:
88 // test for existence of a directory with the given name
89 static bool Exists(const wxString& dir);
90
91 // ctors
92 // -----
93
94 // default, use Open()
95 wxDir() { m_data = NULL; }
96
97 // opens the directory for enumeration, use IsOpened() to test success
98 wxDir(const wxString& dir);
99
100 // dtor cleans up the associated ressources
101 ~wxDir();
102
103 // open the directory for enumerating
104 bool Open(const wxString& dir);
105
106 // returns TRUE if the directory was successfully opened
107 bool IsOpened() const;
108
109 // get the full name of the directory (without '/' at the end)
110 wxString GetName() const;
111
112 // file enumeration routines
113 // -------------------------
114
115 // start enumerating all files matching filespec (or all files if it is
116 // empty) and flags, return TRUE on success
117 bool GetFirst(wxString *filename,
118 const wxString& filespec = wxEmptyString,
119 int flags = wxDIR_DEFAULT) const;
120
121 // get next file in the enumeration started with GetFirst()
122 bool GetNext(wxString *filename) const;
123
124 // return true if this directory has any files in it
125 bool HasFiles(const wxString& spec = wxEmptyString);
126
127 // return true if this directory has any subdirectories
128 bool HasSubDirs(const wxString& spec = wxEmptyString);
129
130 // enumerate all files in this directory and its subdirectories
131 //
132 // return the number of files found
133 size_t Traverse(wxDirTraverser& sink,
134 const wxString& filespec = wxEmptyString,
135 int flags = wxDIR_DEFAULT) const;
136
137 // simplest version of Traverse(): get the names of all files under this
138 // directory into filenames array, return the number of files
139 static size_t GetAllFiles(const wxString& dirname,
140 wxArrayString *files,
141 const wxString& filespec = wxEmptyString,
142 int flags = wxDIR_DEFAULT);
143
144 private:
145 friend class wxDirData;
146
147 wxDirData *m_data;
148
149 DECLARE_NO_COPY_CLASS(wxDir)
150 };
151
152 #endif // _WX_DIR_H_
153