GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dir-ops.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_dir_ops_h)
24 #define octave_dir_ops_h 1
25 
26 #include <string>
27 
28 #include "str-vec.h"
29 
30 class
31 OCTAVE_API
33 {
34 public:
35 
36  dir_entry (const std::string& n = std::string ())
37  : name (n), dir (0), fail (false), errmsg ()
38  {
39  if (! name.empty ())
40  open ();
41  }
42 
44  : name (d.name), dir (d.dir), fail (d.fail), errmsg (d.errmsg) { }
45 
46  dir_entry& operator = (const dir_entry& d)
47  {
48  if (this != &d)
49  {
50  name = d.name;
51  dir = d.dir;
52  fail = d.fail;
53  errmsg = d.errmsg;
54  }
55 
56  return *this;
57  }
58 
59  ~dir_entry (void) { close (); }
60 
61  bool open (const std::string& = std::string ());
62 
63  string_vector read (void);
64 
65  void close (void);
66 
67  bool ok (void) const { return dir && ! fail; }
68 
69  operator bool () const { return ok (); }
70 
71  std::string error (void) const { return ok () ? std::string () : errmsg; }
72 
73 private:
74 
75  // Name of the directory.
76  std::string name;
77 
78  // A pointer to the contents of the directory. We use void here to
79  // avoid possible conflicts with the way some systems declare the
80  // type DIR.
81  void *dir;
82 
83  // TRUE means the open for this directory failed.
84  bool fail;
85 
86  // If a failure occurs, this contains the system error text.
87  std::string errmsg;
88 };
89 
90 #endif
int bool
Definition: mex.h:56
std::string errmsg
Definition: dir-ops.h:87
bool ok(void) const
Definition: dir-ops.h:67
std::string name
Definition: dir-ops.h:76
F77_RET_T const double const double double * d
bool fail
Definition: dir-ops.h:84
void * dir
Definition: dir-ops.h:81
~dir_entry(void)
Definition: dir-ops.h:59
std::string error(void) const
Definition: dir-ops.h:71
Definition: dir-ops.h:30
dir_entry(const dir_entry &d)
Definition: dir-ops.h:43
dir_entry(const std::string &n=std::string())
Definition: dir-ops.h:36