GNU Octave  4.2.1
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
pathsearch.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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_pathsearch_h)
24 #define octave_pathsearch_h 1
25 
26 #include "octave-config.h"
27 
28 #include <list>
29 #include <string>
30 
31 namespace octave
32 {
33  class
34  OCTAVE_API
36  {
37  public:
38 
39  directory_path (const std::string& s = "", const std::string& d = "")
40  : m_orig_path (s), m_default_path (d), m_initialized (false),
41  m_expanded_path (), m_path_elements ()
42  {
43  if (! m_orig_path.empty ())
44  init ();
45  }
46 
48  : m_orig_path (dp.m_orig_path),
49  m_default_path (dp.m_default_path),
50  m_initialized (dp.m_initialized),
51  m_expanded_path (dp.m_expanded_path),
52  m_path_elements (dp.m_path_elements)
53  { }
54 
55  directory_path& operator = (const directory_path& dp)
56  {
57  if (this != &dp)
58  {
59  m_orig_path = dp.m_orig_path;
60  m_default_path = dp.m_default_path;
61  m_initialized = dp.m_initialized;
62  m_expanded_path = dp.m_expanded_path;
63  m_path_elements = dp.m_path_elements;
64  }
65 
66  return *this;
67  }
68 
69  ~directory_path (void) { }
70 
71  void set (const std::string& s)
72  {
73  m_initialized = false;
74  m_orig_path = s;
75  init ();
76  }
77 
78  std::list<std::string> elements (void);
79 
80  std::list<std::string> all_directories (void);
81 
82  std::string find_first (const std::string&);
83 
84  std::string find (const std::string& nm) { return find_first (nm); }
85 
86  std::list<std::string> find_all (const std::string&);
87 
88  std::string find_first_of (const std::list<std::string>& names);
89 
90  std::list<std::string>
91  find_all_first_of (const std::list<std::string>& names);
92 
93  void rehash (void)
94  {
95  m_initialized = false;
96  init ();
97  }
98 
99  static char path_sep_char (void)
100  {
101  return static_members::path_sep_char ();
102  }
103 
104  static void path_sep_char (char c)
105  {
106  static_members::path_sep_char (c);
107  }
108 
109  static std::string path_sep_str (void)
110  {
111  return static_members::path_sep_str ();
112  }
113 
114  static bool is_path_sep (char c) { return c == path_sep_char (); }
115 
116  private:
117 
118  // The colon separated list that we were given.
120 
121  // The default path. If specified, replaces leading, trailing, or
122  // doubled colons in p_orig.
124 
125  // TRUE means we've unpacked the path p.
127 
128  // A version of the colon separate list on which we have performed
129  // tilde, variable, and possibly default path expansion.
131 
132  // The elements of the list.
133  std::list<std::string> m_path_elements;
134 
135  void init (void);
136 
137  // Use a singleton class for these data members instead of just
138  // making them static members of the directory_path class so that
139  // we can ensure proper initialization.
140 
141  class OCTAVE_API static_members
142  {
143  public:
144 
145  static_members (void);
146 
147  static char path_sep_char (void)
148  {
149  return instance_ok () ? instance->xpath_sep_char : 0;
150  }
151 
152  static void path_sep_char (char c)
153  {
154  if (instance_ok ())
155  {
156  instance->xpath_sep_char = c;
157  instance->xpath_sep_str = std::string (1, c);
158  }
159  }
160 
161  static std::string path_sep_str (void)
162  {
163  return instance_ok () ? instance->xpath_sep_str : "";
164  }
165 
166  private:
167 
169 
170  static void cleanup_instance (void) { delete instance; instance = 0; }
171 
172  static bool instance_ok (void);
173 
174  // No copying!
175 
177 
178  static_members& operator = (const static_members&);
179 
181 
183  };
184  };
185 }
186 
187 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
188 
189 OCTAVE_DEPRECATED ("use 'octave::directory_path' instead")
190 typedef octave::directory_path dir_path;
191 
192 #endif
193 
194 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
static bool is_path_sep(char c)
Definition: pathsearch.h:114
static std::string path_sep_str(void)
Definition: pathsearch.h:161
std::string m_expanded_path
Definition: pathsearch.h:130
static static_members * instance
Definition: pathsearch.h:168
std::string m_orig_path
Definition: pathsearch.h:119
s
Definition: file-io.cc:2682
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
void set(const std::string &s)
Definition: pathsearch.h:71
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
std::string find(const std::string &nm)
Definition: pathsearch.h:84
static char path_sep_char(void)
Definition: pathsearch.h:99
std::string m_default_path
Definition: pathsearch.h:123
is false
Definition: cellfun.cc:398
static std::list< std::string > find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
Definition: kpse.cc:548
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
directory_path(const std::string &s="", const std::string &d="")
Definition: pathsearch.h:39
static std::string path_sep_str(void)
Definition: pathsearch.h:109
std::list< std::string > m_path_elements
Definition: pathsearch.h:133
directory_path(const directory_path &dp)
Definition: pathsearch.h:47
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static void path_sep_char(char c)
Definition: pathsearch.h:104