Mercurial > octave
changeset 21735:60212efcd9cb
use namespace for dir_entry class
* dir-ops.h, dir-ops.cc: Put dir_entry class in octave::sys
namespace. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 May 2016 01:05:45 -0400 |
parents | 11af9c03400c |
children | 0504351a45e6 |
files | libinterp/corefcn/dirfns.cc libinterp/corefcn/load-path.cc liboctave/system/dir-ops.cc liboctave/system/dir-ops.h liboctave/system/file-ops.cc liboctave/util/url-transfer.cc |
diffstat | 6 files changed, 110 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/dirfns.cc Thu May 19 01:00:37 2016 -0400 +++ b/libinterp/corefcn/dirfns.cc Thu May 19 01:05:45 2016 -0400 @@ -182,7 +182,7 @@ octave_value_list retval = ovl (Cell (), -1.0, ""); - dir_entry dir (dirname); + octave::sys::dir_entry dir (dirname); if (dir) {
--- a/libinterp/corefcn/load-path.cc Thu May 19 01:00:37 2016 -0400 +++ b/libinterp/corefcn/load-path.cc Thu May 19 01:05:45 2016 -0400 @@ -177,7 +177,7 @@ void load_path::dir_info::get_file_list (const std::string& d) { - dir_entry dir (d); + octave::sys::dir_entry dir (d); if (dir) { @@ -247,7 +247,7 @@ { load_path::dir_info::fcn_file_map_type retval; - dir_entry dir (d); + octave::sys::dir_entry dir (d); if (dir) { @@ -2143,7 +2143,7 @@ { std::string retval; - dir_entry dir (dirname); + octave::sys::dir_entry dir (dirname); if (dir) {
--- a/liboctave/system/dir-ops.cc Thu May 19 01:00:37 2016 -0400 +++ b/liboctave/system/dir-ops.cc Thu May 19 01:05:45 2016 -0400 @@ -39,63 +39,69 @@ #include "lo-sysdep.h" #include "str-vec.h" -bool -dir_entry::open (const std::string& n) +namespace octave { - fail = true; - - if (! n.empty ()) - name = n; - - if (! name.empty ()) + namespace sys + { + bool + dir_entry::open (const std::string& n) { - close (); + fail = true; + + if (! n.empty ()) + name = n; - std::string fullname = octave::sys::file_ops::tilde_expand (name); + if (! name.empty ()) + { + close (); + + std::string fullname = octave::sys::file_ops::tilde_expand (name); - dir = static_cast<void *> (gnulib::opendir (fullname.c_str ())); + dir = static_cast<void *> (gnulib::opendir (fullname.c_str ())); - if (dir) - fail = false; + if (dir) + fail = false; + else + errmsg = gnulib::strerror (errno); + } else - errmsg = gnulib::strerror (errno); + errmsg = "dir_entry::open: empty filename"; + + return ! fail; } - else - errmsg = "dir_entry::open: empty filename"; - return ! fail; -} + string_vector + dir_entry::read (void) + { + string_vector retval; -string_vector -dir_entry::read (void) -{ - string_vector retval; + if (ok ()) + { + std::list<std::string> dirlist; - if (ok ()) - { - std::list<std::string> dirlist; - - struct dirent *dir_ent; + struct dirent *dir_ent; - while ((dir_ent = gnulib::readdir (static_cast<DIR *> (dir)))) - { - if (dir_ent) - dirlist.push_back (dir_ent->d_name); - else - break; + while ((dir_ent = gnulib::readdir (static_cast<DIR *> (dir)))) + { + if (dir_ent) + dirlist.push_back (dir_ent->d_name); + else + break; + } + + retval = string_vector (dirlist); } - retval = string_vector (dirlist); + return retval; } - return retval; -} + void + dir_entry::close (void) + { + if (dir) + gnulib::closedir (static_cast<DIR *> (dir)); -void -dir_entry::close (void) -{ - if (dir) - gnulib::closedir (static_cast<DIR *> (dir)); - - dir = 0; + dir = 0; + } + } }
--- a/liboctave/system/dir-ops.h Thu May 19 01:00:37 2016 -0400 +++ b/liboctave/system/dir-ops.h Thu May 19 01:05:45 2016 -0400 @@ -29,64 +29,77 @@ #include "str-vec.h" -class -OCTAVE_API -dir_entry +namespace octave { -public: + namespace sys + { + class + OCTAVE_API + dir_entry + { + public: - dir_entry (const std::string& n = "") - : name (n), dir (0), fail (false), errmsg () - { - if (! name.empty ()) - open (); - } + dir_entry (const std::string& n = "") + : name (n), dir (0), fail (false), errmsg () + { + if (! name.empty ()) + open (); + } - dir_entry (const dir_entry& d) - : name (d.name), dir (d.dir), fail (d.fail), errmsg (d.errmsg) { } + dir_entry (const dir_entry& d) + : name (d.name), dir (d.dir), fail (d.fail), errmsg (d.errmsg) { } - dir_entry& operator = (const dir_entry& d) - { - if (this != &d) - { - name = d.name; - dir = d.dir; - fail = d.fail; - errmsg = d.errmsg; - } + dir_entry& operator = (const dir_entry& d) + { + if (this != &d) + { + name = d.name; + dir = d.dir; + fail = d.fail; + errmsg = d.errmsg; + } - return *this; - } + return *this; + } + + ~dir_entry (void) { close (); } - ~dir_entry (void) { close (); } + bool open (const std::string& = ""); + + string_vector read (void); - bool open (const std::string& = ""); + void close (void); - string_vector read (void); + bool ok (void) const { return dir && ! fail; } - void close (void); + operator bool () const { return ok (); } - bool ok (void) const { return dir && ! fail; } + std::string error (void) const { return ok () ? "" : errmsg; } - operator bool () const { return ok (); } + private: - std::string error (void) const { return ok () ? "" : errmsg; } + // Name of the directory. + std::string name; -private: + // A pointer to the contents of the directory. We use void here to + // avoid possible conflicts with the way some systems declare the + // type DIR. + void *dir; - // Name of the directory. - std::string name; + // TRUE means the open for this directory failed. + bool fail; - // A pointer to the contents of the directory. We use void here to - // avoid possible conflicts with the way some systems declare the - // type DIR. - void *dir; + // If a failure occurs, this contains the system error text. + std::string errmsg; + }; + } +} - // TRUE means the open for this directory failed. - bool fail; +#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) - // If a failure occurs, this contains the system error text. - std::string errmsg; -}; +OCTAVE_DEPRECATED ("use octave::sys::dir_entry instead") +typedef octave::sys::dir_entry dir_entry; #endif + +#endif