00001 #ifndef FILENAME_CLASS
00002 #define FILENAME_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "opsysdll.h"
00019
00020 #include <basis/packable.h>
00021
00022
00023 class string_array;
00024
00026
00027 class OPSYSTEM_CLASS_STYLE filename : public packable
00028 {
00029 public:
00030 filename();
00031 filename(const istring &name);
00033
00034 filename(const istring &directory, const istring &name_of_file);
00036
00037 filename(const filename &to_copy);
00038
00039 virtual ~filename();
00040
00041 bool good() const;
00043
00046 operator const istring &() const;
00048 const istring &raw() const;
00050 istring &raw();
00052
00055 filename &operator = (const filename &to_copy);
00057 filename &operator = (const istring &to_copy);
00059
00061
00062 bool operator == (const filename &that) const;
00063 inline bool operator != (const filename &that) const
00064 { return !(*this == that); }
00065
00066 void canonicalize();
00068
00071 bool exists() const;
00073
00074 bool unlink() const;
00076
00078 filename parent() const;
00080
00081 istring pop();
00083
00088 void push(const istring &to_push);
00090
00095 filename basename() const;
00097 filename dirname() const;
00099
00101 istring dirname(bool add_slash) const;
00103
00105 bool had_directory() const { return _had_directory; }
00107
00110 char drive(bool interact_with_fs = false) const;
00112
00117 istring extension() const;
00119
00120 istring rootname() const;
00122
00123
00124
00125
00126 bool is_directory() const;
00127 bool is_writable() const;
00128 bool is_readable() const;
00129 bool is_executable() const;
00130
00131 enum write_modes {
00132 ALLOW_NEITHER = 0x0,
00133 ALLOW_READ = 0x1, ALLOW_WRITE = 0x2,
00134 ALLOW_BOTH = ALLOW_READ | ALLOW_WRITE
00135 };
00136
00137 enum ownership_modes {
00138 NO_RIGHTS = 0x0,
00139 USER_RIGHTS = 0x1, GROUP_RIGHTS = 0x2, OTHER_RIGHTS = 0x4,
00140 ALL_RIGHTS = USER_RIGHTS | GROUP_RIGHTS | OTHER_RIGHTS
00141 };
00142
00143 bool chmod(int write_mode, int owner_mode) const;
00145
00147
00149 enum directory_separator { pc_separator = '\\', unix_separator = '/' };
00150
00151 static bool separator(char is_it);
00153
00154 static istring default_separator();
00156
00157 static bool legal_character(char to_check);
00159
00163 static void detooth_filename(istring &to_clean, char replacement = '_');
00165
00171 void separate(string_array &pieces) const;
00173
00178 void join(const string_array &pieces);
00180
00184
00185 virtual void pack(byte_array &packed_form) const;
00186 virtual bool unpack(byte_array &packed_form);
00187
00188 bool compare_prefix(const filename &to_compare, istring &sequel);
00190
00197 bool compare_prefix(const filename &to_compare);
00199
00200 bool compare_suffix(const filename &to_compare, istring &prequel);
00202
00207 bool compare_suffix(const filename &to_compare);
00208
00209 private:
00210 bool _had_directory;
00211 istring *_contents;
00212
00213 int find_last_separator(const istring &look_at) const;
00215
00216 typedef struct stat status_info;
00217 bool get_info(status_info &to_fill) const;
00219
00220
00221 bool base_compare_prefix(const filename &to_compare, string_array &first,
00222 string_array &second);
00223 bool base_compare_suffix(const filename &to_compare, string_array &first,
00224 string_array &second);
00225 };
00226
00227 #endif
00228