~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Base/zipios/directory.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** \file
 
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.
 
4
*/
 
5
 
 
6
// -*-C++-*- directory.h
 
7
// <!!----------------------------------------------------------------------> 
 
8
// <!! Copyright (C) 1998 Dietmar Kuehl, Claas Solutions GmbH > 
 
9
// <!!> 
 
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
// <!!----------------------------------------------------------------------> 
 
18
 
 
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.2 2006/01/30 13:23:59 wmayer Exp $
 
22
 
 
23
// -------------------------------------------------------------------------- 
 
24
 
 
25
#if !defined(BOOST_DIRECTORY_H)
 
26
#define BOOST_DIRECTORY_H 1
 
27
 
 
28
// --------------------------------------------------------------------------
 
29
 
 
30
#include <iterator>
 
31
#include <string>
 
32
#include <ctime>
 
33
#include <stdexcept>
 
34
 
 
35
// #include <boost.h>  Contents of boost.h
 
36
 
 
37
// Allow control over DLL version being built
 
38
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
 
39
#  define BOOST_DECL
 
40
#elif defined(ZIPIOS_DLL)
 
41
#  ifdef ZIPIOS_EXPORTS
 
42
#    define BOOST_DECL __declspec(dllexport)
 
43
#  else
 
44
#    define BOOST_DECL __declspec(dllimport)
 
45
#  endif
 
46
#else
 
47
#  define BOOST_DECL
 
48
#endif
 
49
// end of contents of boost.h
 
50
 
 
51
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
 
52
#include <sys/types.h>
 
53
#endif
 
54
 
 
55
// --------------------------------------------------------------------------
 
56
 
 
57
namespace boost
 
58
{
 
59
        namespace filesystem
 
60
        {
 
61
                class dir_it;
 
62
 
 
63
#if defined(__GNUG__)
 
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);
 
68
#else
 
69
                template <class Property> class get;
 
70
                template <class Property> class set;
 
71
#endif
 
72
 
 
73
        class BOOST_DECL dir_it //: public std::iterator<std::input_iterator_tag, std::string>
 
74
                {
 
75
#if defined(__GNUG__)
 
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);
 
80
#endif
 
81
 
 
82
                        struct representation;
 
83
                        
 
84
                public:
 
85
                        typedef ptrdiff_t   difference_type;
 
86
                        typedef std::string value_type;
 
87
                        typedef std::string *pointer;
 
88
                        typedef std::string &reference;
 
89
                        
 
90
                        class proxy
 
91
                        {
 
92
                                friend class dir_it;
 
93
                                proxy(std::string const &ent): entry(ent) {}
 
94
                        public:
 
95
                                std::string operator*() const { return entry; }
 
96
                        private:
 
97
                                std::string entry;
 
98
                        };
 
99
                        
 
100
                        dir_it();
 
101
                        dir_it(std::string const &);
 
102
                        dir_it(dir_it const &);
 
103
                        ~dir_it();
 
104
                        dir_it &operator= (dir_it const &);
 
105
                        
 
106
                        std::string operator* () const;
 
107
                        dir_it      &operator++ ();
 
108
                        proxy       operator++ (int);
 
109
                        
 
110
                        bool operator== (dir_it const &) const;
 
111
                        bool operator!= (dir_it const &) const;
 
112
 
 
113
#if defined(__GNUG__)
 
114
                private:
 
115
#endif
 
116
                        representation *rep;
 
117
                };
 
118
                
 
119
                struct size { typedef size_t value_type; };
 
120
                struct mtime { typedef time_t const *value_type; };
 
121
 
 
122
                struct is_directory { typedef bool value_type; };
 
123
                struct is_regular { typedef bool value_type; };
 
124
                struct is_hidden { typedef bool value_type; };
 
125
 
 
126
                struct user_read { typedef bool value_type; };
 
127
                struct user_write { typedef bool value_type; };
 
128
                struct user_execute { typedef bool value_type; };
 
129
 
 
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);
 
142
#else
 
143
                template <> class BOOST_DECL get<size>
 
144
                {
 
145
                        typedef size::value_type value_type;
 
146
                public:
 
147
                        get(dir_it const &it): m_it(it) {}
 
148
                        operator value_type() const;
 
149
                private:
 
150
                        dir_it const &m_it;
 
151
                };
 
152
 
 
153
                template <> class BOOST_DECL get<mtime>
 
154
                {
 
155
                        typedef mtime::value_type value_type;
 
156
                public:
 
157
                        get(dir_it const &it): m_it(it) {}
 
158
                        operator value_type() const;
 
159
                private:
 
160
                        dir_it const &m_it;
 
161
                };
 
162
 
 
163
                template <> class BOOST_DECL get<is_directory>
 
164
                {
 
165
                        typedef is_directory::value_type value_type;
 
166
                public:
 
167
                        get(dir_it const &it): m_it(it) {}
 
168
                        operator value_type() const;
 
169
                private:
 
170
                        dir_it const &m_it;
 
171
                };
 
172
 
 
173
                template <> class BOOST_DECL get<is_regular>
 
174
                {
 
175
                        typedef is_regular::value_type value_type;
 
176
                public:
 
177
                        get(dir_it const &it): m_it(it) {}
 
178
                        operator value_type() const;
 
179
                private:
 
180
                        dir_it const &m_it;
 
181
                };
 
182
 
 
183
                template <> class BOOST_DECL get<is_hidden>
 
184
                {
 
185
                        typedef is_hidden::value_type value_type;
 
186
                public:
 
187
                        get(dir_it const &it): m_it(it) {}
 
188
                        operator value_type() const;
 
189
                private:
 
190
                        dir_it const &m_it;
 
191
                };
 
192
                template <> class BOOST_DECL set<is_hidden>
 
193
                {
 
194
                public:
 
195
                        set(dir_it const &, is_hidden::value_type);
 
196
                };
 
197
 
 
198
                template <> class BOOST_DECL get<user_read>
 
199
                {
 
200
                        typedef user_read::value_type value_type;
 
201
                public:
 
202
                        get(dir_it const &it): m_it(it) {}
 
203
                        operator value_type() const;
 
204
                private:
 
205
                        dir_it const &m_it;
 
206
                };
 
207
 
 
208
                template <> class BOOST_DECL get<user_write>
 
209
                {
 
210
                        typedef user_write::value_type value_type;
 
211
                public:
 
212
                        get(dir_it const &it): m_it(it) {}
 
213
                        operator value_type() const;
 
214
                private:
 
215
                        dir_it const &m_it;
 
216
                };
 
217
                template <> class BOOST_DECL set<user_write>
 
218
                {
 
219
                public:
 
220
                        set(dir_it const &, user_write::value_type);
 
221
                };
 
222
 
 
223
                template <> class BOOST_DECL get<user_execute>
 
224
                {
 
225
                        typedef user_execute::value_type value_type;
 
226
                public:
 
227
                        get(dir_it const &it): m_it(it) {}
 
228
                        operator value_type() const;
 
229
                private:
 
230
                        dir_it const &m_it;
 
231
                };
 
232
 
 
233
#endif
 
234
 
 
235
#if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
 
236
 
 
237
                struct is_link { typedef bool value_type; };
 
238
                template <> bool get<is_link>(dir_it const &);
 
239
 
 
240
                struct is_char_device { typedef bool value_type; };
 
241
                template <> bool get<is_char_device>(dir_it const &);
 
242
 
 
243
                struct is_block_device { typedef bool value_type; };
 
244
                template <> bool get<is_block_device>(dir_it const &);
 
245
 
 
246
                struct is_fifo { typedef bool value_type; };
 
247
                template <> bool get<is_fifo>(dir_it const &);
 
248
 
 
249
                struct is_socket { typedef bool value_type; };
 
250
                template <> bool get<is_socket>(dir_it const &);
 
251
 
 
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 &);
 
256
 
 
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);
 
275
 
 
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);
 
285
 
 
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);
 
289
 
 
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 &);
 
296
 
 
297
                class unknown_uid: public std::invalid_argument
 
298
                {
 
299
                public:
 
300
                        unknown_uid(uid_t u): std::invalid_argument("unknown user ID"), m_uid(u) {}
 
301
                        virtual ~unknown_uid() throw() {}
 
302
                        uid_t uid() const { return m_uid; }
 
303
                private:
 
304
                        uid_t m_uid;
 
305
                };
 
306
                struct uid { typedef uid_t value_type; };
 
307
                template<> uid_t get<uid>(dir_it const &);
 
308
                template<> void set<uid>(dir_it const &, uid_t);
 
309
                class unknown_uname: public std::invalid_argument
 
310
                {
 
311
                public:
 
312
                        unknown_uname(std::string u): std::invalid_argument("unknown user name"), m_uname(u) {}
 
313
                        virtual ~unknown_uname() throw() {}
 
314
                        std::string uname() const { return m_uname; }
 
315
                private:
 
316
                        std::string m_uname;
 
317
                };
 
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 );
 
321
 
 
322
                class unknown_gid: public std::invalid_argument
 
323
                {
 
324
                public:
 
325
                        unknown_gid(gid_t g): std::invalid_argument("unknown group ID"), m_gid(g) {}
 
326
                        virtual ~unknown_gid() throw() {}
 
327
                        gid_t gid() const { return m_gid; }
 
328
                private:
 
329
                        gid_t m_gid;
 
330
                };
 
331
                struct gid { typedef gid_t value_type; };
 
332
                template<> gid_t get<gid>(dir_it const &);
 
333
                template<> void set<gid>(dir_it const &, gid_t);
 
334
                class unknown_gname: public std::invalid_argument
 
335
                {
 
336
                public:
 
337
                        unknown_gname(std::string g): std::invalid_argument("unknown group name"), m_gname(g) {}
 
338
                        virtual ~unknown_gname() throw() {}
 
339
                        std::string gname() const { return m_gname; }
 
340
                private:
 
341
                        std::string m_gname;
 
342
                };
 
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 );
 
346
 
 
347
#endif
 
348
 
 
349
        } // namespace filesystem
 
350
} // namespace boost
 
351
 
 
352
namespace std
 
353
{
 
354
        template<>
 
355
        struct iterator_traits<boost::filesystem::dir_it>
 
356
        {
 
357
        public:
 
358
                typedef ptrdiff_t          difference_type;
 
359
                typedef std::string             value_type;
 
360
                typedef std::string             *pointer;
 
361
                typedef std::string             &reference;
 
362
                typedef input_iterator_tag iterator_category;
 
363
        };
 
364
} // namespace std
 
365
 
 
366
// --------------------------------------------------------------------------
 
367
 
 
368
#endif /* BOOST_DIRECTORY_H */