Mercurial > octave
changeset 21745:bf1121302404
use namespace for dir_path class
* pathsearch.h, pathsearch.cc: Put dir_path class in octave namespace
and rename to directory_path. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 May 2016 13:59:28 -0400 |
parents | e1be0b36fbed |
children | ac8b8bdae98f |
files | libinterp/corefcn/defaults.cc libinterp/corefcn/dirfns.cc libinterp/corefcn/load-path.cc libinterp/corefcn/load-path.h libinterp/corefcn/ls-mat5.cc libinterp/corefcn/utils.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-java.cc liboctave/system/file-ops.h liboctave/util/pathsearch.cc liboctave/util/pathsearch.h |
diffstat | 11 files changed, 251 insertions(+), 239 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/defaults.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/defaults.cc Thu May 19 13:59:28 2016 -0400 @@ -258,10 +258,10 @@ tpath = octave::sys::env::getenv ("OCTAVE_EXEC_PATH"); if (tpath.empty ()) - tpath = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str () - + Vlocal_api_arch_lib_dir + dir_path::path_sep_str () - + Vlocal_arch_lib_dir + dir_path::path_sep_str () - + Varch_lib_dir + dir_path::path_sep_str () + tpath = Vlocal_ver_arch_lib_dir + octave::directory_path::path_sep_str () + + Vlocal_api_arch_lib_dir + octave::directory_path::path_sep_str () + + Vlocal_arch_lib_dir + octave::directory_path::path_sep_str () + + Varch_lib_dir + octave::directory_path::path_sep_str () + Vbin_dir; VEXEC_PATH = tpath; @@ -283,7 +283,7 @@ static std::string shell_path = octave::sys::env::getenv ("PATH"); if (! shell_path.empty ()) - tpath = shell_path + dir_path::path_sep_str () + tpath; + tpath = shell_path + octave::directory_path::path_sep_str () + tpath; octave::sys::env::putenv ("PATH", tpath); } @@ -299,12 +299,12 @@ tpath = octave::sys::env::getenv ("OCTAVE_IMAGE_PATH"); if (! tpath.empty ()) - VIMAGE_PATH += dir_path::path_sep_str () + tpath; + VIMAGE_PATH += octave::directory_path::path_sep_str () + tpath; tpath = genpath (Vimage_dir, ""); if (! tpath.empty ()) - VIMAGE_PATH += dir_path::path_sep_str () + tpath; + VIMAGE_PATH += octave::directory_path::path_sep_str () + tpath; } static void
--- a/libinterp/corefcn/dirfns.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/dirfns.cc Thu May 19 13:59:28 2016 -0400 @@ -584,7 +584,7 @@ octave_value retval; if (nargout > 0 || nargin == 0) - retval = dir_path::path_sep_str (); + retval = octave::directory_path::path_sep_str (); if (nargin == 1) { @@ -593,11 +593,11 @@ switch (sval.length ()) { case 1: - dir_path::path_sep_char (sval[0]); + octave::directory_path::path_sep_char (sval[0]); break; case 0: - dir_path::path_sep_char ('\0'); + octave::directory_path::path_sep_char ('\0'); break; default:
--- a/libinterp/corefcn/load-path.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/load-path.cc Thu May 19 13:59:28 2016 -0400 @@ -568,7 +568,7 @@ if (path.empty ()) path = tpath; else - path += dir_path::path_sep_str () + tpath; + path += octave::directory_path::path_sep_str () + tpath; } } @@ -602,7 +602,7 @@ xpath = tpath; if (! sys_path.empty ()) - xpath += dir_path::path_sep_str () + sys_path; + xpath += octave::directory_path::path_sep_str () + sys_path; } else xpath = sys_path; @@ -626,7 +626,7 @@ std::list<std::string> retval; size_t beg = 0; - size_t end = p.find (dir_path::path_sep_char ()); + size_t end = p.find (octave::directory_path::path_sep_char ()); size_t len = p.length (); @@ -642,7 +642,7 @@ if (beg == len) break; - end = p.find (dir_path::path_sep_char (), beg); + end = p.find (octave::directory_path::path_sep_char (), beg); } std::string elt = p.substr (beg); @@ -1716,7 +1716,7 @@ xpath = xdirs[0]; for (octave_idx_type i = 1; i < len; i++) - xpath += dir_path::path_sep_str () + xdirs[i]; + xpath += octave::directory_path::path_sep_str () + xdirs[i]; return xpath; } @@ -1845,7 +1845,7 @@ size_t ps = path.size (); size_t pls = path_list.size (); size_t pos = path_list.find (path); - char psc = dir_path::path_sep_char (); + char psc = octave::directory_path::path_sep_char (); while (pos != std::string::npos) { if ((pos == 0 || path_list[pos-1] == psc) @@ -2176,7 +2176,7 @@ octave::sys::file_stat fs (nm); if (fs && fs.is_dir ()) - retval += dir_path::path_sep_str () + genpath (nm, skip); + retval += octave::directory_path::path_sep_str () + genpath (nm, skip); } } } @@ -2358,7 +2358,7 @@ std::string path = argv[1]; for (int i = 2; i <= nargin; i++) - path += dir_path::path_sep_str () + argv[i]; + path += octave::directory_path::path_sep_str () + argv[i]; load_path::set (path, true);
--- a/libinterp/corefcn/load-path.h Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/load-path.h Thu May 19 13:59:28 2016 -0400 @@ -273,7 +273,7 @@ if (command_line_path.empty ()) command_line_path = p; else - command_line_path += dir_path::path_sep_str () + p; + command_line_path += octave::directory_path::path_sep_str () + p; } static std::string get_command_line_path (void)
--- a/libinterp/corefcn/ls-mat5.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/ls-mat5.cc Thu May 19 13:59:28 2016 -0400 @@ -904,7 +904,7 @@ names(1) = fname + ".mex"; names(2) = fname + ".m"; - dir_path p (load_path::system_path ()); + octave::directory_path p (load_path::system_path ()); str = octave::sys::env::make_absolute (p.find_first_of (names));
--- a/libinterp/corefcn/utils.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/corefcn/utils.cc Thu May 19 13:59:28 2016 -0400 @@ -253,7 +253,7 @@ std::string search_path_for_file (const std::string& path, const string_vector& names) { - dir_path p (path); + octave::directory_path p (path); return octave::sys::env::make_absolute (p.find_first_of (names)); } @@ -263,7 +263,7 @@ string_vector search_path_for_all_files (const std::string& path, const string_vector& names) { - dir_path p (path); + octave::directory_path p (path); string_vector sv = p.find_all_first_of (names);
--- a/libinterp/octave-value/ov-fcn-handle.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/octave-value/ov-fcn-handle.cc Thu May 19 13:59:28 2016 -0400 @@ -292,7 +292,7 @@ names(1) = nm + ".mex"; names(2) = nm + ".m"; - dir_path p (load_path::system_path ()); + octave::directory_path p (load_path::system_path ()); str = octave::sys::env::make_absolute (p.find_first_of (names));
--- a/libinterp/octave-value/ov-java.cc Thu May 19 13:01:29 2016 -0400 +++ b/libinterp/octave-value/ov-java.cc Thu May 19 13:59:28 2016 -0400 @@ -405,7 +405,7 @@ else { // prepend separator character - classpath.append (dir_path::path_sep_str ()); + classpath.append (octave::directory_path::path_sep_str ()); // append content of line without whitespace int last = line.find_last_not_of (" \t\f\v\r\n");
--- a/liboctave/system/file-ops.h Thu May 19 13:01:29 2016 -0400 +++ b/liboctave/system/file-ops.h Thu May 19 13:59:28 2016 -0400 @@ -42,8 +42,8 @@ public: // Use a singleton class for dir_sep data members instead of just - // making them static members of the dir_path class so that we can - // ensure proper initialization. + // making them static members of the file_ops class so that we + // can ensure proper initialization. file_ops (char dir_sep_char_arg = 0, const std::string& dir_sep_str_arg = std::string ("/"),
--- a/liboctave/util/pathsearch.cc Thu May 19 13:01:29 2016 -0400 +++ b/liboctave/util/pathsearch.cc Thu May 19 13:59:28 2016 -0400 @@ -36,136 +36,139 @@ #include "kpse.cc" -dir_path::static_members *dir_path::static_members::instance = 0; +namespace octave +{ + directory_path::static_members *directory_path::static_members::instance = 0; -dir_path::static_members::static_members (void) - : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { } + directory_path::static_members::static_members (void) + : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { } -bool -dir_path::static_members::instance_ok (void) -{ - bool retval = true; + bool + directory_path::static_members::instance_ok (void) + { + bool retval = true; - if (! instance) - { - instance = new static_members (); + if (! instance) + { + instance = new static_members (); - if (instance) - singleton_cleanup_list::add (cleanup_instance); - } + if (instance) + singleton_cleanup_list::add (cleanup_instance); + } - if (! instance) - (*current_liboctave_error_handler) - ("unable to create dir_path::static_members object!"); + if (! instance) + (*current_liboctave_error_handler) + ("unable to create directory_path::static_members object!"); - return retval; -} + return retval; + } -string_vector -dir_path::elements (void) -{ - return initialized ? pv : string_vector (); -} + string_vector + directory_path::elements (void) + { + return initialized ? pv : string_vector (); + } -string_vector -dir_path::all_directories (void) -{ - int count = 0; - string_vector retval; + string_vector + directory_path::all_directories (void) + { + int count = 0; + string_vector retval; - if (initialized) - { - int len = pv.numel (); + if (initialized) + { + int len = pv.numel (); - int nmax = len > 32 ? len : 32; + int nmax = len > 32 ? len : 32; - retval.resize (len); + retval.resize (len); - for (int i = 0; i < len; i++) - { - str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); + for (int i = 0; i < len; i++) + { + str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); - if (elt_dirs) - { - str_llist_elt_type *dir; + if (elt_dirs) + { + str_llist_elt_type *dir; - for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) - { - const std::string elt_dir = STR_LLIST (*dir); + for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) + { + const std::string elt_dir = STR_LLIST (*dir); - if (! elt_dir.empty ()) - { - if (count == nmax) - nmax *= 2; + if (! elt_dir.empty ()) + { + if (count == nmax) + nmax *= 2; - retval.resize (nmax); + retval.resize (nmax); - retval[count++] = elt_dir; - } - } - } - } + retval[count++] = elt_dir; + } + } + } + } - retval.resize (count); - } + retval.resize (count); + } - return retval; -} + return retval; + } -std::string -dir_path::find_first (const std::string& nm) -{ - return initialized ? kpse_path_search (p, nm, true) : ""; -} + std::string + directory_path::find_first (const std::string& nm) + { + return initialized ? kpse_path_search (p, nm, true) : ""; + } -string_vector -dir_path::find_all (const std::string& nm) -{ - return initialized ? kpse_all_path_search (p, nm) : string_vector (); -} + string_vector + directory_path::find_all (const std::string& nm) + { + return initialized ? kpse_all_path_search (p, nm) : string_vector (); + } -std::string -dir_path::find_first_of (const string_vector& names) -{ - return initialized - ? kpse_path_find_first_of (p, names, true) : ""; -} + std::string + directory_path::find_first_of (const string_vector& names) + { + return initialized + ? kpse_path_find_first_of (p, names, true) : ""; + } -string_vector -dir_path::find_all_first_of (const string_vector& names) -{ - return initialized - ? kpse_all_path_find_first_of (p, names) : string_vector (); -} + string_vector + directory_path::find_all_first_of (const string_vector& names) + { + return initialized + ? kpse_all_path_find_first_of (p, names) : string_vector (); + } -void -dir_path::init (void) -{ - static bool octave_kpathsea_initialized = false; + void + directory_path::init (void) + { + static bool octave_kpathsea_initialized = false; - if (! octave_kpathsea_initialized) - { - std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); + if (! octave_kpathsea_initialized) + { + std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); - if (! val.empty ()) - kpathsea_debug |= atoi (val.c_str ()); + if (! val.empty ()) + kpathsea_debug |= atoi (val.c_str ()); - octave_kpathsea_initialized = true; - } + octave_kpathsea_initialized = true; + } - p = kpse_path_expand (p_default.empty () - ? p_orig : kpse_expand_default (p_orig, p_default)); + p = kpse_path_expand (p_default.empty () + ? p_orig : kpse_expand_default (p_orig, p_default)); - int count = 0; - for (kpse_path_iterator pi (p); pi != std::string::npos; pi++) - count++; + int count = 0; + for (kpse_path_iterator pi (p); pi != std::string::npos; pi++) + count++; - pv.resize (count); + pv.resize (count); - kpse_path_iterator pi (p); + kpse_path_iterator pi (p); - for (int i = 0; i < count; i++) - pv[i] = *pi++; + for (int i = 0; i < count; i++) + pv[i] = *pi++; - initialized = true; + initialized = true; + } }
--- a/liboctave/util/pathsearch.h Thu May 19 13:01:29 2016 -0400 +++ b/liboctave/util/pathsearch.h Thu May 19 13:59:28 2016 -0400 @@ -29,146 +29,155 @@ #include "str-vec.h" -class -OCTAVE_API -dir_path +namespace octave { -public: - - dir_path (const std::string& s = "", - const std::string& d = "") - : p_orig (s), p_default (d), initialized (false), p (), pv () - { - if (! p_orig.empty ()) - init (); - } - - dir_path (const dir_path& dp) - : p_orig (dp.p_orig), p_default (dp.p_default), - initialized (dp.initialized), p (dp.p), pv (dp.pv) - { } - - dir_path& operator = (const dir_path& dp) - { - p_orig = dp.p_orig; - p_default = dp.p_default; - initialized = dp.initialized; - p = dp.p; - pv = dp.pv; - return *this; - } - - ~dir_path (void) { } - - void set (const std::string& s) - { - initialized = false; - p_orig = s; - init (); - } - - string_vector elements (void); - string_vector all_directories (void); - - std::string find_first (const std::string&); - std::string find (const std::string& nm) { return find_first (nm); } - - string_vector find_all (const std::string&); - - std::string find_first_of (const string_vector& names); - string_vector find_all_first_of (const string_vector& names); - - void rehash (void) - { - initialized = false; - init (); - } - - static char path_sep_char (void) - { - return static_members::path_sep_char (); - } - - static void path_sep_char (char c) - { - static_members::path_sep_char (c); - } - - static std::string path_sep_str (void) - { - return static_members::path_sep_str (); - } - - static bool is_path_sep (char c) { return c == path_sep_char (); } - -private: - - // The colon separated list that we were given. - std::string p_orig; - - // The default path. If specified, replaces leading, trailing, or - // doubled colons in p_orig. - std::string p_default; - - // TRUE means we've unpacked p. - bool initialized; - - // A version of the colon separate list on which we have performed - // tilde, variable, and possibly default path expansion. - std::string p; - - // The elements of the list. - string_vector pv; - - void init (void); - - // Use a singleton class for these data members instead of just - // making them static members of the dir_path class so that we can - // ensure proper initialization. - - class OCTAVE_API static_members + class + OCTAVE_API + directory_path { public: - static_members (void); + directory_path (const std::string& s = "", const std::string& d = "") + : p_orig (s), p_default (d), initialized (false), p (), pv () + { + if (! p_orig.empty ()) + init (); + } + + directory_path (const directory_path& dp) + : p_orig (dp.p_orig), p_default (dp.p_default), + initialized (dp.initialized), p (dp.p), pv (dp.pv) + { } + + directory_path& operator = (const directory_path& dp) + { + p_orig = dp.p_orig; + p_default = dp.p_default; + initialized = dp.initialized; + p = dp.p; + pv = dp.pv; + return *this; + } + + ~directory_path (void) { } + + void set (const std::string& s) + { + initialized = false; + p_orig = s; + init (); + } + + string_vector elements (void); + string_vector all_directories (void); + + std::string find_first (const std::string&); + std::string find (const std::string& nm) { return find_first (nm); } + + string_vector find_all (const std::string&); + + std::string find_first_of (const string_vector& names); + string_vector find_all_first_of (const string_vector& names); + + void rehash (void) + { + initialized = false; + init (); + } static char path_sep_char (void) { - return instance_ok () ? instance->xpath_sep_char : 0; + return static_members::path_sep_char (); } static void path_sep_char (char c) { - if (instance_ok ()) - { - instance->xpath_sep_char = c; - instance->xpath_sep_str = std::string (1, c); - } + static_members::path_sep_char (c); } static std::string path_sep_str (void) { - return instance_ok () ? instance->xpath_sep_str : ""; + return static_members::path_sep_str (); } + static bool is_path_sep (char c) { return c == path_sep_char (); } + private: - static static_members *instance; + // The colon separated list that we were given. + std::string p_orig; + + // The default path. If specified, replaces leading, trailing, or + // doubled colons in p_orig. + std::string p_default; - static void cleanup_instance (void) { delete instance; instance = 0; } + // TRUE means we've unpacked p. + bool initialized; + + // A version of the colon separate list on which we have performed + // tilde, variable, and possibly default path expansion. + std::string p; + + // The elements of the list. + string_vector pv; - static bool instance_ok (void); + void init (void); + + // Use a singleton class for these data members instead of just + // making them static members of the directory_path class so that + // we can ensure proper initialization. - // No copying! + class OCTAVE_API static_members + { + public: + + static_members (void); + + static char path_sep_char (void) + { + return instance_ok () ? instance->xpath_sep_char : 0; + } - static_members (const static_members&); + static void path_sep_char (char c) + { + if (instance_ok ()) + { + instance->xpath_sep_char = c; + instance->xpath_sep_str = std::string (1, c); + } + } - static_members& operator = (const static_members&); + static std::string path_sep_str (void) + { + return instance_ok () ? instance->xpath_sep_str : ""; + } + + private: + + static static_members *instance; + + static void cleanup_instance (void) { delete instance; instance = 0; } - char xpath_sep_char; + static bool instance_ok (void); + + // No copying! + + static_members (const static_members&); + + static_members& operator = (const static_members&); + + char xpath_sep_char; - std::string xpath_sep_str; + std::string xpath_sep_str; + }; }; -}; +} + +#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) + +OCTAVE_DEPRECATED ("use octave::directory_path instead") +typedef octave::directory_path dir_path; #endif + +#endif