GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
dir-ops.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_dir_ops_h)
27#define octave_dir_ops_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "str-vec.h"
34
36
38
40{
41
42 // NOTE: This class cannot be used safely cross-platform (Windows) with
43 // non-ASCII characters in paths.
44 // Consider replacing the implementation using std::filesystem (C++ 17).
45 // In the meantime, consider using sys::get_dirlist instead.
46
47public:
48
49 dir_entry (const std::string& n = "")
50 : m_name (n), m_dir (nullptr), m_fail (false), m_errmsg ()
51 {
52 if (! m_name.empty ())
53 open ();
54 }
55
57 : m_name (d.m_name), m_dir (d.m_dir), m_fail (d.m_fail),
58 m_errmsg (d.m_errmsg)
59 { }
60
61 dir_entry& operator = (const dir_entry& d)
62 {
63 if (this != &d)
64 {
65 m_name = d.m_name;
66 m_dir = d.m_dir;
67 m_fail = d.m_fail;
68 m_errmsg = d.m_errmsg;
69 }
70
71 return *this;
72 }
73
74 ~dir_entry () { close (); }
75
76 bool open (const std::string& = "");
77
78 string_vector read ();
79
80 bool close ();
81
82 bool ok () const { return m_dir && ! m_fail; }
83
84 operator bool () const { return ok (); }
85
86 std::string error () const { return ok () ? "" : m_errmsg; }
87
88 static unsigned int max_name_length ();
89
90private:
91
92 // Name of the directory.
93 std::string m_name;
94
95 // A pointer to the contents of the directory. We use void here to
96 // avoid possible conflicts with the way some systems declare the
97 // type DIR.
98 void *m_dir;
99
100 // TRUE means the open for this directory failed.
101 bool m_fail;
102
103 // If a failure occurs, this contains the system error text.
104 std::string m_errmsg;
105};
106
107OCTAVE_END_NAMESPACE(sys)
108OCTAVE_END_NAMESPACE(octave)
109
110#endif
Definition dir-ops.h:40
~dir_entry()
Definition dir-ops.h:74
dir_entry(const std::string &n="")
Definition dir-ops.h:49
bool ok() const
Definition dir-ops.h:82
std::string error() const
Definition dir-ops.h:86
dir_entry(const dir_entry &d)
Definition dir-ops.h:56
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
#define OCTAVE_API
Definition main.in.cc:55