1 | /** |
---|
2 | * Copyright (C) 2002 Bart Vanhauwaert |
---|
3 | * |
---|
4 | * Permission to use, copy, modify, distribute and sell this software |
---|
5 | * for any purpose is hereby granted without fee. This license |
---|
6 | * includes (but is not limited to) standalone compilation or as part |
---|
7 | * of a larger project. |
---|
8 | * |
---|
9 | * This software is provided "as is" without express or implied warranty. |
---|
10 | * |
---|
11 | * For a full statement on warranty and terms and conditions for |
---|
12 | * copying, distribution and modification, please see the comment block |
---|
13 | * at the end of this file. |
---|
14 | * |
---|
15 | * Version 1 |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef __DIRECTORY_H_ |
---|
20 | #define __DIRECTORY_H_ |
---|
21 | |
---|
22 | #if defined(unix) || defined(__unix) || defined(__unix__) |
---|
23 | #define OSLINK_OSDIR_POSIX |
---|
24 | #elif defined(_WIN32) |
---|
25 | #define OSLINK_OSDIR_WINDOWS |
---|
26 | #else |
---|
27 | #define OSLINK_OSDIR_NOTSUPPORTED |
---|
28 | #endif |
---|
29 | |
---|
30 | #include <string> |
---|
31 | |
---|
32 | #if defined(OSLINK_OSDIR_NOTSUPPORTED) |
---|
33 | #warning DIRECTORY NOT SUPPORTET |
---|
34 | |
---|
35 | #elif defined(OSLINK_OSDIR_POSIX) |
---|
36 | #include <sys/types.h> |
---|
37 | #include <dirent.h> |
---|
38 | |
---|
39 | #elif defined(OSLINK_OSDIR_WINDOWS) |
---|
40 | |
---|
41 | /// HACK |
---|
42 | #ifdef DATADIR |
---|
43 | #undef DATADIR |
---|
44 | #endif |
---|
45 | |
---|
46 | #include <windows.h> |
---|
47 | #include <winbase.h> |
---|
48 | |
---|
49 | #endif |
---|
50 | |
---|
51 | class Directory |
---|
52 | { |
---|
53 | public: |
---|
54 | Directory(const std::string& directoryName = ""); |
---|
55 | ~Directory(); |
---|
56 | |
---|
57 | bool open(const std::string& directoryName); |
---|
58 | void close(); |
---|
59 | operator void*() const { return willfail ? (void*)0:(void*)(-1); } |
---|
60 | |
---|
61 | std::string next(); |
---|
62 | |
---|
63 | private: |
---|
64 | #if defined(OSLINK_OSDIR_POSIX) |
---|
65 | DIR* handle; |
---|
66 | #elif defined(OSLINK_OSDIR_WINDOWS) |
---|
67 | HANDLE handle; |
---|
68 | #endif |
---|
69 | bool willfail; |
---|
70 | std::string current; |
---|
71 | }; |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | #endif /* __DIRECTORY_H_ */ |
---|
76 | |
---|
77 | /** |
---|
78 | * |
---|
79 | * The "library", above, refers to the collection of software functions |
---|
80 | * and/or data contained in this file, prepared so as to be conveniently |
---|
81 | * compiled and linked with application programs (which use some of those |
---|
82 | * functions and data) to form executables. |
---|
83 | * |
---|
84 | * NO WARRANTY |
---|
85 | * |
---|
86 | * 1. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
---|
87 | * WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
---|
88 | * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
---|
89 | * OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
---|
90 | * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
---|
91 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
---|
92 | * PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
---|
93 | * LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
---|
94 | * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
---|
95 | * |
---|
96 | * 2. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
---|
97 | * WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
---|
98 | * AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
---|
99 | * FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
---|
100 | * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
---|
101 | * LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
---|
102 | * RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
---|
103 | * FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
---|
104 | * SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
---|
105 | * DAMAGES. |
---|
106 | * |
---|
107 | * END OF TERMS AND CONDITIONS |
---|
108 | * |
---|
109 | */ |
---|
110 | |
---|