GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
utils.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2021 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_utils_h)
27 #define octave_utils_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdarg>
32 
33 #include <iosfwd>
34 #include <string>
35 #include <list>
36 
37 #include "dMatrix.h"
38 #include "lo-utils.h"
39 
40 class octave_value;
41 class octave_value_list;
42 class string_vector;
43 
44 namespace octave
45 {
46  extern OCTINTERP_API bool valid_identifier (const char *s);
47  extern OCTINTERP_API bool valid_identifier (const std::string& s);
48 
49  extern OCTINTERP_API bool
50  same_file (const std::string& f, const std::string& g);
51 
52  extern OCTINTERP_API int almost_match (const std::string& std,
53  const std::string& s,
54  int min_match_len = 1,
55  int case_sens = 1);
56 
57  extern OCTINTERP_API int
58  keyword_almost_match (const char * const *std, int *min_len,
59  const std::string& s, int min_toks_to_match,
60  int max_toks);
61 
62  extern OCTINTERP_API std::string
63  search_path_for_file (const std::string&, const string_vector&);
64 
65  extern OCTINTERP_API string_vector
66  search_path_for_all_files (const std::string&, const string_vector&);
67 
68  extern OCTINTERP_API std::string
69  file_in_path (const std::string&, const std::string&);
70 
71  extern OCTINTERP_API std::string
72  find_data_file_in_load_path (const std::string& fcn,
73  const std::string& file,
74  bool require_regular_file = false);
75 
76  extern OCTINTERP_API std::string contents_file_in_path (const std::string&);
77 
78  extern OCTINTERP_API std::string fcn_file_in_path (const std::string&);
79 
80  extern OCTINTERP_API std::string do_string_escapes (const std::string& s);
81 
82  extern OCTINTERP_API const char * undo_string_escape (char c);
83 
84  extern OCTINTERP_API std::string undo_string_escapes (const std::string& s);
85 
86  extern OCTINTERP_API void
87  check_dimensions (dim_vector& dim, const char *warnfor);
88 
89  extern OCTINTERP_API void
90  get_dimensions (const octave_value& a, const char *warn_for,
91  dim_vector& dim);
92 
93  extern OCTINTERP_API void
94  get_dimensions (const octave_value& a, const octave_value& b,
95  const char *warn_for, octave_idx_type& nr,
96  octave_idx_type& nc);
97 
98  extern OCTINTERP_API void
99  get_dimensions (const octave_value& a, const char *warn_for,
101 
102  extern OCTINTERP_API octave_idx_type
103  dims_to_numel (const dim_vector& dims, const octave_value_list& idx);
104 
105  extern OCTINTERP_API Matrix
107 
108  extern OCTINTERP_API FloatMatrix
110 
111  extern OCTINTERP_API size_t
112  format (std::ostream& os, const char *fmt, ...);
113 
114  extern OCTINTERP_API size_t
115  format (std::ostream& os, const std::string& enc, const char *fmt, ...);
116 
117  extern OCTINTERP_API size_t
118  vformat (std::ostream& os, const char *fmt, va_list args);
119 
120  extern OCTINTERP_API size_t
121  vformat (std::ostream& os, const std::string& enc,
122  const char *fmt, va_list args);
123 
124  extern OCTINTERP_API std::string
125  vasprintf (const char *fmt, va_list args);
126 
127  extern OCTINTERP_API std::string asprintf (const char *fmt, ...);
128 
129  extern OCTINTERP_API void sleep (double seconds,
130  bool do_graphics_events = false);
131 
132  extern OCTINTERP_API
135  const char *fun_name, const octave_value_list& args,
136  int nargout);
137 
138  extern OCTINTERP_API
141  const char *fun_name, const octave_value_list& args);
142 }
143 
144 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
145 
146 OCTAVE_DEPRECATED (5, "use 'octave::valid_identifier' instead")
147 extern OCTINTERP_API bool
148 valid_identifier (const char *s);
149 
150 OCTAVE_DEPRECATED (5, "use 'octave::valid_identifier' instead")
151 extern OCTINTERP_API bool
152 valid_identifier (const std::string& s);
153 
154 OCTAVE_DEPRECATED (5, "use 'octave::same_file' instead")
155 extern OCTINTERP_API bool
156 same_file (const std::string& f, const std::string& g);
157 
158 OCTAVE_DEPRECATED (5, "use 'octave::almost_match' instead")
159 extern OCTINTERP_API int
160 almost_match (const std::string& std, const std::string& s,
161  int min_match_len = 1, int case_sens = 1);
162 
163 OCTAVE_DEPRECATED (5, "use 'octave::keyword_almost_match' instead")
164 extern OCTINTERP_API int
165 keyword_almost_match (const char * const *std, int *min_len,
166  const std::string& s, int min_toks_to_match,
167  int max_toks);
168 
169 OCTAVE_DEPRECATED (5, "use 'octave::search_path_for_file' instead")
170 extern OCTINTERP_API std::string
171 search_path_for_file (const std::string& path, const string_vector& names);
172 
173 OCTAVE_DEPRECATED (5, "use 'octave::search_path_for_all_files' instead")
174 extern OCTINTERP_API string_vector
175 search_path_for_all_files (const std::string& path, const string_vector& names);
176 
177 OCTAVE_DEPRECATED (5, "use 'octave::file_in_path' instead")
178 extern OCTINTERP_API std::string
179 file_in_path (const std::string& name, const std::string& suffix);
180 
181 OCTAVE_DEPRECATED (5, "use 'octave::find_data_file_in_load_path ' instead")
182 extern OCTINTERP_API std::string
183 find_data_file_in_load_path (const std::string& fcn, const std::string& file,
184  bool require_regular_file = false);
185 
186 OCTAVE_DEPRECATED (5, "use 'octave::contents_file_in_path' instead")
187 extern OCTINTERP_API std::string
188 contents_file_in_path (const std::string& s);
189 
190 OCTAVE_DEPRECATED (5, "use 'octave::fcn_file_in_path' instead")
191 extern OCTINTERP_API std::string
192 fcn_file_in_path (const std::string& s);
193 
194 OCTAVE_DEPRECATED (5, "use 'octave::do_string_escapes' instead")
195 extern OCTINTERP_API std::string
196 do_string_escapes (const std::string& s);
197 
198 OCTAVE_DEPRECATED (5, "use 'octave::undo_string_escape' instead")
199 extern OCTINTERP_API const char *
200 undo_string_escape (char c);
201 
202 OCTAVE_DEPRECATED (5, "use 'octave::undo_string_escapes' instead")
203 extern OCTINTERP_API std::string
204 undo_string_escapes (const std::string& s);
205 
206 OCTAVE_DEPRECATED (5, "use 'octave::check_dimensions' instead")
207 extern OCTINTERP_API void
208 check_dimensions (dim_vector& dim, const char *warnfor);
209 
210 OCTAVE_DEPRECATED (5, "use 'octave::get_dimensions' instead")
211 extern OCTINTERP_API void
212 get_dimensions (const octave_value& a, const char *warn_for,
213  dim_vector& dim);
214 
215 OCTAVE_DEPRECATED (5, "use 'octave::get_dimensions' instead")
216 extern OCTINTERP_API void
217 get_dimensions (const octave_value& a, const octave_value& b,
218  const char *warn_for, octave_idx_type& nr,
219  octave_idx_type& nc);
220 
221 OCTAVE_DEPRECATED (5, "use 'octave::get_dimensions' instead")
222 extern OCTINTERP_API void
223 get_dimensions (const octave_value& a, const char *warn_for,
225 
226 OCTAVE_DEPRECATED (5, "use 'octave::dims_to_numel' instead")
227 extern OCTINTERP_API octave_idx_type
228 dims_to_numel (const dim_vector& dims, const octave_value_list& idx);
229 
230 OCTAVE_DEPRECATED (5, "use 'octave::identity_matrix' instead")
231 extern OCTINTERP_API Matrix
233 
234 OCTAVE_DEPRECATED (5, "use 'octave::float_identity_matrix' instead")
235 extern OCTINTERP_API FloatMatrix
237 
238 template <typename ... Args>
239 OCTAVE_DEPRECATED (5, "use 'octave::format' instead")
240 size_t
241 octave_format (std::ostream& os, const char *fmt, Args&& ... args)
242 {
243  return octave::format (os, fmt, std::forward<Args> (args) ...);
244 }
245 
246 OCTAVE_DEPRECATED (5, "use 'octave::vformat' instead")
247 extern OCTINTERP_API size_t
248 octave_vformat (std::ostream& os, const char *fmt, va_list args);
249 
250 OCTAVE_DEPRECATED (5, "use 'octave::vasprintf' instead")
251 extern OCTINTERP_API std::string
252 octave_vasprintf (const char *fmt, va_list args);
253 
254 template <typename ... Args>
255 OCTAVE_DEPRECATED (5, "use 'octave::asprintf' instead")
256 std::string
257 octave_asprintf (const char *fmt, Args&& ... args)
258 {
259  return octave::asprintf (fmt, std::forward<Args> (args) ...);
260 }
261 
262 OCTAVE_DEPRECATED (5, "use 'octave::sleep' instead")
263 extern OCTINTERP_API void
264 octave_sleep (double seconds);
265 
266 OCTAVE_DEPRECATED (5, "use 'octave::do_simple_cellfun' instead")
267 extern OCTINTERP_API octave_value_list
269  const char *fun_name, const octave_value_list& args,
270  int nargout);
271 
272 OCTAVE_DEPRECATED (5, "use 'octave::do_simple_cellfun' instead")
273 extern OCTINTERP_API octave_value
275  const char *fun_name, const octave_value_list& args);
276 
277 #endif
278 
279 #endif
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
octave_value identity_matrix(int nr, int nc)
Definition: data.cc:4931
QString path
QString name
F77_RET_T const F77_DBLE const F77_DBLE * f
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
Definition: utils.cc:1197
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
Definition: utils.cc:257
std::string vasprintf(const char *fmt, va_list args)
Definition: utils.cc:1379
std::string contents_file_in_path(const std::string &dir)
Definition: utils.cc:632
bool valid_identifier(const char *s)
Definition: utils.cc:77
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
Definition: utils.cc:1166
static double f(double k, double l_nu, double c_pm)
Definition: randpoisson.cc:118
std::string do_string_escapes(const std::string &s)
Definition: utils.cc:654
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
Definition: utils.cc:370
const char * undo_string_escape(char c)
Definition: utils.cc:838
std::string asprintf(const char *fmt,...)
Definition: utils.cc:1396
void sleep(double seconds, bool do_graphics_events)
Definition: utils.cc:1415
octave_value_list do_simple_cellfun(octave_value_list(*fun)(const octave_value_list &, int), const char *fun_name, const octave_value_list &args, int nargout)
Definition: utils.cc:1549
Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:1299
std::string fcn_file_in_path(const std::string &name)
Definition: utils.cc:592
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition: utils.cc:272
size_t vformat(std::ostream &os, const char *fmt, va_list args)
Definition: utils.cc:1343
std::string file_in_path(const std::string &name, const std::string &suffix)
Definition: utils.cc:541
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
Definition: utils.cc:553
size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1329
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:1314
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:138
std::string search_path_for_file(const std::string &path, const string_vector &names)
Definition: utils.cc:360
std::string undo_string_escapes(const std::string &s)
Definition: utils.cc:885
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx_arg)
Definition: utils.cc:1260
std::string do_string_escapes(const std::string &s)
Definition: utils.cc:1734
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
Definition: utils.cc:1715
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
Definition: utils.cc:1780
std::string undo_string_escapes(const std::string &s)
Definition: utils.cc:1746
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
Definition: utils.cc:1681
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition: utils.cc:1688
std::string file_in_path(const std::string &name, const std::string &suffix)
Definition: utils.cc:1709
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:1792
void octave_sleep(double seconds)
Definition: utils.cc:1810
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
Definition: utils.cc:1703
std::string contents_file_in_path(const std::string &s)
Definition: utils.cc:1722
size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
Definition: utils.cc:1798
std::string fcn_file_in_path(const std::string &s)
Definition: utils.cc:1728
const char * undo_string_escape(char c)
Definition: utils.cc:1740
std::string search_path_for_file(const std::string &path, const string_vector &names)
Definition: utils.cc:1697
void check_dimensions(dim_vector &dim, const char *warnfor)
Definition: utils.cc:1752
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:1675
std::string octave_vasprintf(const char *fmt, va_list args)
Definition: utils.cc:1804