00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef FILENAME_H
00020 #define FILENAME_H
00021
00022 #include "dtoolbase.h"
00023
00024 #include "vector_string.h"
00025
00026 #include <assert.h>
00027
00028 class DSearchPath;
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class EXPCL_DTOOL Filename {
00046 PUBLISHED:
00047 enum Type {
00048
00049
00050 T_general = 0x00,
00051 T_dso = 0x01,
00052 T_executable = 0x02,
00053
00054 };
00055
00056 public:
00057 enum Flags {
00058 F_type = 0x0f,
00059 F_binary = 0x10,
00060 F_text = 0x20,
00061 };
00062
00063 PUBLISHED:
00064 INLINE Filename(const string &filename = "");
00065 INLINE Filename(const char *filename);
00066 INLINE Filename(const Filename ©);
00067 Filename(const Filename &dirname, const Filename &basename);
00068 INLINE ~Filename();
00069
00070
00071
00072
00073 INLINE static Filename text_filename(const string &filename);
00074 INLINE static Filename binary_filename(const string &filename);
00075 INLINE static Filename dso_filename(const string &filename);
00076 INLINE static Filename executable_filename(const string &filename);
00077
00078 static Filename from_os_specific(const string &os_specific,
00079 Type type = T_general);
00080 static Filename expand_from(const string &user_string,
00081 Type type = T_general);
00082 static Filename temporary(const string &dirname, const string &prefix,
00083 Type type = T_general);
00084
00085
00086 INLINE Filename &operator = (const string &filename);
00087 INLINE Filename &operator = (const char *filename);
00088 INLINE Filename &operator = (const Filename ©);
00089
00090
00091 INLINE operator const string & () const;
00092 INLINE const char *c_str() const;
00093 INLINE bool empty() const;
00094 INLINE size_t length() const;
00095 INLINE char operator [] (int n) const;
00096
00097
00098 INLINE string get_fullpath() const;
00099 INLINE string get_dirname() const;
00100 INLINE string get_basename() const;
00101 INLINE string get_fullpath_wo_extension() const;
00102 INLINE string get_basename_wo_extension() const;
00103 INLINE string get_extension() const;
00104
00105
00106 void set_fullpath(const string &s);
00107 void set_dirname(const string &s);
00108 void set_basename(const string &s);
00109 void set_fullpath_wo_extension(const string &s);
00110 void set_basename_wo_extension(const string &s);
00111 void set_extension(const string &s);
00112
00113
00114
00115
00116
00117 INLINE void set_binary();
00118 INLINE void set_text();
00119 INLINE bool is_binary() const;
00120 INLINE bool is_text() const;
00121
00122 INLINE void set_type(Type type);
00123 INLINE Type get_type() const;
00124
00125 void extract_components(vector_string &components) const;
00126 void standardize();
00127
00128
00129
00130 INLINE bool is_local() const;
00131 INLINE bool is_fully_qualified() const;
00132 void make_absolute();
00133 void make_absolute(const Filename &start_directory);
00134
00135 bool make_canonical();
00136
00137 string to_os_specific() const;
00138 string to_os_generic() const;
00139
00140 bool exists() const;
00141 bool is_regular_file() const;
00142 bool is_directory() const;
00143 bool is_executable() const;
00144 int compare_timestamps(const Filename &other,
00145 bool this_missing_is_old = true,
00146 bool other_missing_is_old = true) const;
00147 bool resolve_filename(const DSearchPath &searchpath,
00148 const string &default_extension = string());
00149 bool make_relative_to(Filename directory, bool allow_backups = true);
00150 int find_on_searchpath(const DSearchPath &searchpath);
00151
00152 bool scan_directory(vector_string &contents) const;
00153
00154 bool open_read(ifstream &stream) const;
00155 bool open_write(ofstream &stream, bool truncate = true) const;
00156 bool open_append(ofstream &stream) const;
00157 bool open_read_write(fstream &stream) const;
00158
00159 bool touch() const;
00160
00161 bool unlink() const;
00162 bool rename_to(const Filename &other) const;
00163
00164 bool make_dir() const;
00165
00166
00167 INLINE bool operator == (const string &other) const;
00168 INLINE bool operator != (const string &other) const;
00169 INLINE bool operator < (const string &other) const;
00170
00171 INLINE void output(ostream &out) const;
00172
00173 private:
00174 void locate_basename();
00175 void locate_extension();
00176 size_t get_common_prefix(const string &other) const;
00177 static int count_slashes(const string &str);
00178
00179 string _filename;
00180
00181
00182 size_t _dirname_end;
00183 size_t _basename_start;
00184 size_t _basename_end;
00185 size_t _extension_start;
00186
00187 int _flags;
00188 };
00189
00190 INLINE ostream &operator << (ostream &out, const Filename &n) {
00191 n.output(out);
00192 return out;
00193 }
00194
00195 #include "filename.I"
00196
00197 #endif
00198
00199
00200