2
This file and directory.cpp are borrowed from the dir_it library
3
available at http://www.boost.org. dir_it is a directory iterator.
6
// -*-C++-*- directory.h
7
// <!!---------------------------------------------------------------------->
8
// <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH >
10
// <!! Permission to use, copy, modify, distribute and sell this >
11
// <!! software for any purpose is hereby granted without fee, provided >
12
// <!! that the above copyright notice appears in all copies and that >
13
// <!! both that copyright notice and this permission notice appear in >
14
// <!! supporting documentation. Dietmar Kuehl and Claas Solutions make no >
15
// <!! representations about the suitability of this software for any >
16
// <!! purpose. It is provided "as is" without express or implied warranty. >
17
// <!!---------------------------------------------------------------------->
19
// Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de
20
// Title: An input iterator used to list the entries in a directory
21
// Version: $Name: $ $Id: directory.h,v 1.6 2004/05/01 17:33:10 dheck Exp $
23
// --------------------------------------------------------------------------
25
#if !defined(BOOST_DIRECTORY_H)
26
#define BOOST_DIRECTORY_H 1
28
// --------------------------------------------------------------------------
35
// #include <boost.h> Contents of boost.h
37
// Allow control over DLL version being built
38
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(MACOSX) || defined(__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__)
40
#elif defined(ZIPIOS_DLL)
41
# ifdef ZIPIOS_EXPORTS
42
# define BOOST_DECL __declspec(dllexport)
44
# define BOOST_DECL __declspec(dllimport)
49
// end of contents of boost.h
51
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(MACOSX) || defined(__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__)
52
#include <sys/types.h>
55
// --------------------------------------------------------------------------
64
template <class Property>
65
typename Property::value_type get(dir_it const &);
66
template <class Property>
67
void set(dir_it const &, typename Property::value_type);
69
template <class Property> class get;
70
template <class Property> class set;
73
class BOOST_DECL dir_it //: public std::iterator<std::input_iterator_tag, std::string>
76
template <class Property>
77
friend typename Property::value_type get(dir_it const &);
78
template <class Property>
79
friend void set(dir_it const &, typename Property::value_type);
82
struct representation;
85
typedef ptrdiff_t difference_type;
86
typedef std::string value_type;
87
typedef std::string *pointer;
88
typedef std::string &reference;
93
proxy(std::string const &ent): entry(ent) {}
95
std::string operator*() const { return entry; }
101
dir_it(std::string const &);
102
dir_it(dir_it const &);
104
dir_it &operator= (dir_it const &);
106
std::string operator* () const;
107
dir_it &operator++ ();
108
proxy operator++ (int);
110
bool operator== (dir_it const &) const;
111
bool operator!= (dir_it const &) const;
113
#if defined(__GNUG__)
119
struct size { typedef size_t value_type; };
120
struct mtime { typedef time_t const *value_type; };
122
struct is_directory { typedef bool value_type; };
123
struct is_regular { typedef bool value_type; };
124
struct is_hidden { typedef bool value_type; };
126
struct user_read { typedef bool value_type; };
127
struct user_write { typedef bool value_type; };
128
struct user_execute { typedef bool value_type; };
130
#if defined(__GNUG__)
131
template <> size::value_type get<size>(dir_it const &);
132
template <> mtime::value_type get<mtime>(dir_it const &);
133
template <> bool get<is_directory>(dir_it const &);
134
template <> bool get<is_regular>(dir_it const &);
135
template <> bool get<is_hidden>(dir_it const &);
136
template <> bool get<user_read>(dir_it const &);
137
template <> void set<user_read>(dir_it const &, bool);
138
template <> bool get<user_write>(dir_it const &);
139
template <> void set<user_write>(dir_it const &, bool);
140
template <> bool get<user_execute>(dir_it const &);
141
template <> void set<user_execute>(dir_it const &, bool);
143
template <> class BOOST_DECL get<size>
145
typedef size::value_type value_type;
147
get(dir_it const &it): m_it(it) {}
148
operator value_type() const;
153
template <> class BOOST_DECL get<mtime>
155
typedef mtime::value_type value_type;
157
get(dir_it const &it): m_it(it) {}
158
operator value_type() const;
163
template <> class BOOST_DECL get<is_directory>
165
typedef is_directory::value_type value_type;
167
get(dir_it const &it): m_it(it) {}
168
operator value_type() const;
173
template <> class BOOST_DECL get<is_regular>
175
typedef is_regular::value_type value_type;
177
get(dir_it const &it): m_it(it) {}
178
operator value_type() const;
183
template <> class BOOST_DECL get<is_hidden>
185
typedef is_hidden::value_type value_type;
187
get(dir_it const &it): m_it(it) {}
188
operator value_type() const;
192
template <> class BOOST_DECL set<is_hidden>
195
set(dir_it const &, is_hidden::value_type);
198
template <> class BOOST_DECL get<user_read>
200
typedef user_read::value_type value_type;
202
get(dir_it const &it): m_it(it) {}
203
operator value_type() const;
208
template <> class BOOST_DECL get<user_write>
210
typedef user_write::value_type value_type;
212
get(dir_it const &it): m_it(it) {}
213
operator value_type() const;
217
template <> class BOOST_DECL set<user_write>
220
set(dir_it const &, user_write::value_type);
223
template <> class BOOST_DECL get<user_execute>
225
typedef user_execute::value_type value_type;
227
get(dir_it const &it): m_it(it) {}
228
operator value_type() const;
235
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(MACOSX) || defined(__NetBSD__) || defined (__FreeBSD__) || defined (__OpenBSD__)
237
struct is_link { typedef bool value_type; };
238
template <> bool get<is_link>(dir_it const &);
240
struct is_char_device { typedef bool value_type; };
241
template <> bool get<is_char_device>(dir_it const &);
243
struct is_block_device { typedef bool value_type; };
244
template <> bool get<is_block_device>(dir_it const &);
246
struct is_fifo { typedef bool value_type; };
247
template <> bool get<is_fifo>(dir_it const &);
249
struct is_socket { typedef bool value_type; };
250
template <> bool get<is_socket>(dir_it const &);
252
struct atime { typedef time_t *value_type; };
253
template <> atime::value_type get<atime>(dir_it const &);
254
struct ctime { typedef time_t *value_type; };
255
template <> ctime::value_type get<ctime>(dir_it const &);
257
struct group_read { typedef bool value_type; };
258
template <> bool get<group_read>(dir_it const &);
259
template <> void set<group_read>(dir_it const &, bool);
260
struct group_write { typedef bool value_type; };
261
template <> bool get<group_write>(dir_it const &);
262
template <> void set<group_write>(dir_it const &, bool);
263
struct group_execute { typedef bool value_type; };
264
template <> bool get<group_execute>(dir_it const &);
265
template <> void set<group_execute>(dir_it const &, bool);
266
struct other_read { typedef bool value_type; };
267
template <> bool get<other_read>(dir_it const &);
268
template <> void set<other_read>(dir_it const &, bool);
269
struct other_write { typedef bool value_type; };
270
template <> bool get<other_write>(dir_it const &);
271
template <> void set<other_write>(dir_it const &, bool);
272
struct other_execute { typedef bool value_type; };
273
template <> bool get<other_execute>(dir_it const &);
274
template <> void set<other_execute>(dir_it const &, bool);
276
struct set_uid { typedef bool value_type; };
277
template <> bool get<set_uid>(dir_it const &);
278
template <> void set<set_uid>(dir_it const &, bool);
279
struct set_gid { typedef bool value_type; };
280
template <> bool get<set_gid>(dir_it const &);
281
template <> void set<set_gid>(dir_it const &, bool);
282
struct sticky { typedef bool value_type; };
283
template <> bool get<sticky>(dir_it const &);
284
template <> void set<sticky>(dir_it const &, bool);
286
struct mode { typedef mode_t value_type; };
287
template <> mode_t get<mode>(dir_it const &);
288
template <> void set<mode>(dir_it const &, mode_t);
290
struct links { typedef nlink_t value_type; };
291
template<> nlink_t get<links>(dir_it const &);
292
struct blocks { typedef unsigned long value_type; };
293
template<> unsigned long get<blocks>(dir_it const &);
294
struct blksize { typedef unsigned long value_type; };
295
template<> unsigned long get<blksize>(dir_it const &);
297
class unknown_uid: public std::invalid_argument
300
unknown_uid(uid_t u): std::invalid_argument("unknown user ID"), m_uid(u) {}
301
uid_t uid() const { return m_uid; }
305
struct uid { typedef uid_t value_type; };
306
template<> uid_t get<uid>(dir_it const &);
307
template<> void set<uid>(dir_it const &, uid_t);
308
class unknown_uname: public std::invalid_argument
311
unknown_uname(std::string u): std::invalid_argument("unknown user name"), m_uname(u) {}
312
// TODO: Why does this destructor have to be redefined so as to avoid the "looser throw specifier" error.
313
~unknown_uname() throw() { }
314
std::string uname() const { return m_uname; }
318
struct uname { typedef std::string value_type; };
319
template<> std::string get<uname>(dir_it const &);
320
template<> void set<uname>(dir_it const &, std::string );
322
class unknown_gid: public std::invalid_argument
325
unknown_gid(gid_t g): std::invalid_argument("unknown group ID"), m_gid(g) {}
326
gid_t gid() const { return m_gid; }
330
struct gid { typedef gid_t value_type; };
331
template<> gid_t get<gid>(dir_it const &);
332
template<> void set<gid>(dir_it const &, gid_t);
333
class unknown_gname: public std::invalid_argument
336
unknown_gname(std::string g): std::invalid_argument("unknown group name"), m_gname(g) {}
337
// TODO: Why does this destructor have to be redefined so as to avoid the "looser throw specifier" error.
338
~unknown_gname() throw() { }
339
std::string gname() const { return m_gname; }
343
struct gname { typedef std::string value_type; };
344
template<> std::string get<gname>(dir_it const &);
345
template<> void set<gname>(dir_it const &, std::string );
349
} // namespace filesystem
355
struct iterator_traits<boost::filesystem::dir_it> {
357
typedef ptrdiff_t difference_type;
358
typedef std::string value_type;
359
typedef std::string *pointer;
360
typedef std::string &reference;
361
typedef input_iterator_tag iterator_category;
365
// --------------------------------------------------------------------------
367
#endif /* BOOST_DIRECTORY_H */