directory.h
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #if !defined(BOOST_DIRECTORY_H)
00026 #define BOOST_DIRECTORY_H 1
00027
00028
00029
00030 #include <iterator>
00031 #include <string>
00032 #include <cstddef>
00033 #include <ctime>
00034 #include <stdexcept>
00035
00036
00037
00038
00039 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
00040 # define BOOST_DECL
00041 #elif defined(ZIPIOS_DLL)
00042 # ifdef ZIPIOS_EXPORTS
00043 # define BOOST_DECL __declspec(dllexport)
00044 # else
00045 # define BOOST_DECL __declspec(dllimport)
00046 # endif
00047 #else
00048 # define BOOST_DECL
00049 #endif
00050
00051
00052 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
00053 #include <sys/types.h>
00054 #endif
00055
00056
00057
00058 namespace boost
00059 {
00060 namespace filesystem
00061 {
00062 class dir_it;
00063
00064 #if defined(__GNUG__)
00065 template <class Property>
00066 typename Property::value_type get(dir_it const &);
00067 template <class Property>
00068 void set(dir_it const &, typename Property::value_type);
00069 #else
00070 template <class Property> class get;
00071 template <class Property> class set;
00072 #endif
00073
00074 class BOOST_DECL dir_it
00075 {
00076 #if defined(__GNUG__)
00077 template <class Property>
00078 friend typename Property::value_type get(dir_it const &);
00079 template <class Property>
00080 friend void set(dir_it const &, typename Property::value_type);
00081 #endif
00082
00083 struct representation;
00084
00085 public:
00086 typedef ptrdiff_t difference_type;
00087 typedef std::string value_type;
00088 typedef std::string *pointer;
00089 typedef std::string &reference;
00090
00091 class proxy
00092 {
00093 friend class dir_it;
00094 proxy(std::string const &ent): entry(ent) {}
00095 public:
00096 std::string operator*() const { return entry; }
00097 private:
00098 std::string entry;
00099 };
00100
00101 dir_it();
00102 dir_it(std::string const &);
00103 dir_it(dir_it const &);
00104 ~dir_it();
00105 dir_it &operator= (dir_it const &);
00106
00107 std::string operator* () const;
00108 dir_it &operator++ ();
00109 proxy operator++ (int);
00110
00111 bool operator== (dir_it const &) const;
00112 bool operator!= (dir_it const &) const;
00113
00114 #if defined(__GNUG__)
00115 private:
00116 #endif
00117 representation *rep;
00118 };
00119
00120 struct size { typedef size_t value_type; };
00121 struct mtime { typedef time_t const *value_type; };
00122
00123 struct is_directory { typedef bool value_type; };
00124 struct is_regular { typedef bool value_type; };
00125 struct is_hidden { typedef bool value_type; };
00126
00127 struct user_read { typedef bool value_type; };
00128 struct user_write { typedef bool value_type; };
00129 struct user_execute { typedef bool value_type; };
00130
00131 #if defined(__GNUG__)
00132 template <> size::value_type get<size>(dir_it const &);
00133 template <> mtime::value_type get<mtime>(dir_it const &);
00134 template <> bool get<is_directory>(dir_it const &);
00135 template <> bool get<is_regular>(dir_it const &);
00136 template <> bool get<is_hidden>(dir_it const &);
00137 template <> bool get<user_read>(dir_it const &);
00138 template <> void set<user_read>(dir_it const &, bool);
00139 template <> bool get<user_write>(dir_it const &);
00140 template <> void set<user_write>(dir_it const &, bool);
00141 template <> bool get<user_execute>(dir_it const &);
00142 template <> void set<user_execute>(dir_it const &, bool);
00143 #else
00144 template <> class BOOST_DECL get<size>
00145 {
00146 typedef size::value_type value_type;
00147 public:
00148 get(dir_it const &it): m_it(it) {}
00149 operator value_type() const;
00150 private:
00151 dir_it const &m_it;
00152 };
00153
00154 template <> class BOOST_DECL get<mtime>
00155 {
00156 typedef mtime::value_type value_type;
00157 public:
00158 get(dir_it const &it): m_it(it) {}
00159 operator value_type() const;
00160 private:
00161 dir_it const &m_it;
00162 };
00163
00164 template <> class BOOST_DECL get<is_directory>
00165 {
00166 typedef is_directory::value_type value_type;
00167 public:
00168 get(dir_it const &it): m_it(it) {}
00169 operator value_type() const;
00170 private:
00171 dir_it const &m_it;
00172 };
00173
00174 template <> class BOOST_DECL get<is_regular>
00175 {
00176 typedef is_regular::value_type value_type;
00177 public:
00178 get(dir_it const &it): m_it(it) {}
00179 operator value_type() const;
00180 private:
00181 dir_it const &m_it;
00182 };
00183
00184 template <> class BOOST_DECL get<is_hidden>
00185 {
00186 typedef is_hidden::value_type value_type;
00187 public:
00188 get(dir_it const &it): m_it(it) {}
00189 operator value_type() const;
00190 private:
00191 dir_it const &m_it;
00192 };
00193 template <> class BOOST_DECL set<is_hidden>
00194 {
00195 public:
00196 set(dir_it const &, is_hidden::value_type);
00197 };
00198
00199 template <> class BOOST_DECL get<user_read>
00200 {
00201 typedef user_read::value_type value_type;
00202 public:
00203 get(dir_it const &it): m_it(it) {}
00204 operator value_type() const;
00205 private:
00206 dir_it const &m_it;
00207 };
00208
00209 template <> class BOOST_DECL get<user_write>
00210 {
00211 typedef user_write::value_type value_type;
00212 public:
00213 get(dir_it const &it): m_it(it) {}
00214 operator value_type() const;
00215 private:
00216 dir_it const &m_it;
00217 };
00218 template <> class BOOST_DECL set<user_write>
00219 {
00220 public:
00221 set(dir_it const &, user_write::value_type);
00222 };
00223
00224 template <> class BOOST_DECL get<user_execute>
00225 {
00226 typedef user_execute::value_type value_type;
00227 public:
00228 get(dir_it const &it): m_it(it) {}
00229 operator value_type() const;
00230 private:
00231 dir_it const &m_it;
00232 };
00233
00234 #endif
00235
00236 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
00237
00238 struct is_link { typedef bool value_type; };
00239 template <> bool get<is_link>(dir_it const &);
00240
00241 struct is_char_device { typedef bool value_type; };
00242 template <> bool get<is_char_device>(dir_it const &);
00243
00244 struct is_block_device { typedef bool value_type; };
00245 template <> bool get<is_block_device>(dir_it const &);
00246
00247 struct is_fifo { typedef bool value_type; };
00248 template <> bool get<is_fifo>(dir_it const &);
00249
00250 struct is_socket { typedef bool value_type; };
00251 template <> bool get<is_socket>(dir_it const &);
00252
00253 struct atime { typedef time_t *value_type; };
00254 template <> atime::value_type get<atime>(dir_it const &);
00255 struct ctime { typedef time_t *value_type; };
00256 template <> ctime::value_type get<ctime>(dir_it const &);
00257
00258 struct group_read { typedef bool value_type; };
00259 template <> bool get<group_read>(dir_it const &);
00260 template <> void set<group_read>(dir_it const &, bool);
00261 struct group_write { typedef bool value_type; };
00262 template <> bool get<group_write>(dir_it const &);
00263 template <> void set<group_write>(dir_it const &, bool);
00264 struct group_execute { typedef bool value_type; };
00265 template <> bool get<group_execute>(dir_it const &);
00266 template <> void set<group_execute>(dir_it const &, bool);
00267 struct other_read { typedef bool value_type; };
00268 template <> bool get<other_read>(dir_it const &);
00269 template <> void set<other_read>(dir_it const &, bool);
00270 struct other_write { typedef bool value_type; };
00271 template <> bool get<other_write>(dir_it const &);
00272 template <> void set<other_write>(dir_it const &, bool);
00273 struct other_execute { typedef bool value_type; };
00274 template <> bool get<other_execute>(dir_it const &);
00275 template <> void set<other_execute>(dir_it const &, bool);
00276
00277 struct set_uid { typedef bool value_type; };
00278 template <> bool get<set_uid>(dir_it const &);
00279 template <> void set<set_uid>(dir_it const &, bool);
00280 struct set_gid { typedef bool value_type; };
00281 template <> bool get<set_gid>(dir_it const &);
00282 template <> void set<set_gid>(dir_it const &, bool);
00283 struct sticky { typedef bool value_type; };
00284 template <> bool get<sticky>(dir_it const &);
00285 template <> void set<sticky>(dir_it const &, bool);
00286
00287 struct mode { typedef mode_t value_type; };
00288 template <> mode_t get<mode>(dir_it const &);
00289 template <> void set<mode>(dir_it const &, mode_t);
00290
00291 struct links { typedef nlink_t value_type; };
00292 template<> nlink_t get<links>(dir_it const &);
00293 struct blocks { typedef unsigned long value_type; };
00294 template<> unsigned long get<blocks>(dir_it const &);
00295 struct blksize { typedef unsigned long value_type; };
00296 template<> unsigned long get<blksize>(dir_it const &);
00297
00298 class unknown_uid: public std::invalid_argument
00299 {
00300 public:
00301 unknown_uid(uid_t u): std::invalid_argument("unknown user ID"), m_uid(u) {}
00302 virtual ~unknown_uid() throw() {}
00303 uid_t uid() const { return m_uid; }
00304 private:
00305 uid_t m_uid;
00306 };
00307 struct uid { typedef uid_t value_type; };
00308 template<> uid_t get<uid>(dir_it const &);
00309 template<> void set<uid>(dir_it const &, uid_t);
00310 class unknown_uname: public std::invalid_argument
00311 {
00312 public:
00313 unknown_uname(std::string u): std::invalid_argument("unknown user name"), m_uname(u) {}
00314 virtual ~unknown_uname() throw() {}
00315 std::string uname() const { return m_uname; }
00316 private:
00317 std::string m_uname;
00318 };
00319 struct uname { typedef std::string value_type; };
00320 template<> std::string get<uname>(dir_it const &);
00321 template<> void set<uname>(dir_it const &, std::string );
00322
00323 class unknown_gid: public std::invalid_argument
00324 {
00325 public:
00326 unknown_gid(gid_t g): std::invalid_argument("unknown group ID"), m_gid(g) {}
00327 virtual ~unknown_gid() throw() {}
00328 gid_t gid() const { return m_gid; }
00329 private:
00330 gid_t m_gid;
00331 };
00332 struct gid { typedef gid_t value_type; };
00333 template<> gid_t get<gid>(dir_it const &);
00334 template<> void set<gid>(dir_it const &, gid_t);
00335 class unknown_gname: public std::invalid_argument
00336 {
00337 public:
00338 unknown_gname(std::string g): std::invalid_argument("unknown group name"), m_gname(g) {}
00339 virtual ~unknown_gname() throw() {}
00340 std::string gname() const { return m_gname; }
00341 private:
00342 std::string m_gname;
00343 };
00344 struct gname { typedef std::string value_type; };
00345 template<> std::string get<gname>(dir_it const &);
00346 template<> void set<gname>(dir_it const &, std::string );
00347
00348 #endif
00349
00350 }
00351 }
00352
00353 namespace std
00354 {
00355 template<>
00356 struct iterator_traits<boost::filesystem::dir_it>
00357 {
00358 public:
00359 typedef ptrdiff_t difference_type;
00360 typedef std::string value_type;
00361 typedef std::string *pointer;
00362 typedef std::string &reference;
00363 typedef input_iterator_tag iterator_category;
00364 };
00365 }
00366
00367
00368
00369 #endif