00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_pathsearch_h)
00025 #define octave_pathsearch_h 1
00026
00027 #include <string>
00028
00029 #include "str-vec.h"
00030
00031 class
00032 OCTAVE_API
00033 dir_path
00034 {
00035 public:
00036
00037 dir_path (const std::string& s = std::string (),
00038 const std::string& d = std::string ())
00039 : p_orig (s), p_default (d), initialized (false)
00040 {
00041 if (! p_orig.empty ())
00042 init ();
00043 }
00044
00045 dir_path (const dir_path& dp)
00046 : p_orig (dp.p_orig), p_default (dp.p_default),
00047 initialized (dp.initialized), p (dp.p), pv (dp.pv)
00048 { }
00049
00050 dir_path& operator = (const dir_path& dp)
00051 {
00052 p_orig = dp.p_orig;
00053 p_default = dp.p_default;
00054 initialized = dp.initialized;
00055 p = dp.p;
00056 pv = dp.pv;
00057 return *this;
00058 }
00059
00060 ~dir_path (void) { }
00061
00062 void set (const std::string& s)
00063 {
00064 initialized = false;
00065 p_orig = s;
00066 init ();
00067 }
00068
00069 string_vector elements (void);
00070 string_vector all_directories (void);
00071
00072 std::string find_first (const std::string&);
00073 std::string find (const std::string& nm) { return find_first (nm); }
00074
00075 string_vector find_all (const std::string&);
00076
00077 std::string find_first_of (const string_vector& names);
00078 string_vector find_all_first_of (const string_vector& names);
00079
00080 void rehash (void)
00081 {
00082 initialized = false;
00083 init ();
00084 }
00085
00086 static char path_sep_char (void)
00087 {
00088 return static_members::path_sep_char ();
00089 }
00090
00091 static void path_sep_char (char c)
00092 {
00093 static_members::path_sep_char (c);
00094 }
00095
00096 static std::string path_sep_str (void)
00097 {
00098 return static_members::path_sep_str ();
00099 }
00100
00101 static bool is_path_sep (char c) { return c == path_sep_char (); }
00102
00103 private:
00104
00105
00106 std::string p_orig;
00107
00108
00109
00110 std::string p_default;
00111
00112
00113 bool initialized;
00114
00115
00116
00117 std::string p;
00118
00119
00120 string_vector pv;
00121
00122 void init (void);
00123
00124
00125
00126
00127
00128 class OCTAVE_API static_members
00129 {
00130 public:
00131
00132 static_members (void);
00133
00134 static char path_sep_char (void)
00135 {
00136 return instance_ok () ? instance->xpath_sep_char : 0;
00137 }
00138
00139 static void path_sep_char (char c)
00140 {
00141 if (instance_ok ())
00142 {
00143 instance->xpath_sep_char = c;
00144 instance->xpath_sep_str = std::string (1, c);
00145 }
00146 }
00147
00148 static std::string path_sep_str (void)
00149 {
00150 return instance_ok () ? instance->xpath_sep_str : std::string ();
00151 }
00152
00153 private:
00154
00155 static static_members *instance;
00156
00157 static bool instance_ok (void);
00158
00159
00160
00161 static_members (const static_members&);
00162
00163 static_members& operator = (const static_members&);
00164
00165 char xpath_sep_char;
00166
00167 std::string xpath_sep_str;
00168 };
00169 };
00170
00171 #endif
00172
00173
00174
00175
00176
00177