3
Copyright (C) 1996-2013 John W. Eaton
5
This file is part of Octave.
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.
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
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/>.
23
#if !defined (octave_pathsearch_h)
24
#define octave_pathsearch_h 1
36
dir_path (const std::string& s = std::string (),
37
const std::string& d = std::string ())
38
: p_orig (s), p_default (d), initialized (false), p (), pv ()
40
if (! p_orig.empty ())
44
dir_path (const dir_path& dp)
45
: p_orig (dp.p_orig), p_default (dp.p_default),
46
initialized (dp.initialized), p (dp.p), pv (dp.pv)
49
dir_path& operator = (const dir_path& dp)
52
p_default = dp.p_default;
53
initialized = dp.initialized;
61
void set (const std::string& s)
68
string_vector elements (void);
69
string_vector all_directories (void);
71
std::string find_first (const std::string&);
72
std::string find (const std::string& nm) { return find_first (nm); }
74
string_vector find_all (const std::string&);
76
std::string find_first_of (const string_vector& names);
77
string_vector find_all_first_of (const string_vector& names);
85
static char path_sep_char (void)
87
return static_members::path_sep_char ();
90
static void path_sep_char (char c)
92
static_members::path_sep_char (c);
95
static std::string path_sep_str (void)
97
return static_members::path_sep_str ();
100
static bool is_path_sep (char c) { return c == path_sep_char (); }
104
// The colon separated list that we were given.
107
// The default path. If specified, replaces leading, trailing, or
108
// doubled colons in p_orig.
109
std::string p_default;
111
// TRUE means we've unpacked p.
114
// A version of the colon separate list on which we have performed
115
// tilde, variable, and possibly default path expansion.
118
// The elements of the list.
123
// Use a singleton class for these data members instead of just
124
// making them static members of the dir_path class so that we can
125
// ensure proper initialization.
127
class OCTAVE_API static_members
131
static_members (void);
133
static char path_sep_char (void)
135
return instance_ok () ? instance->xpath_sep_char : 0;
138
static void path_sep_char (char c)
142
instance->xpath_sep_char = c;
143
instance->xpath_sep_str = std::string (1, c);
147
static std::string path_sep_str (void)
149
return instance_ok () ? instance->xpath_sep_str : std::string ();
154
static static_members *instance;
156
static void cleanup_instance (void) { delete instance; instance = 0; }
158
static bool instance_ok (void);
162
static_members (const static_members&);
164
static_members& operator = (const static_members&);
168
std::string xpath_sep_str;