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
lo-array-errwarn.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2016-2017 Rik Wehbring
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_lo_array_errwarn_h)
24 #define octave_lo_array_errwarn_h 1
25 
26 #include "octave-config.h"
27 
28 #include "dim-vector.h"
29 #include "quit.h"
30 
31 namespace octave
32 {
33  // Exception thrown by err_invalid_index
34  // This is thrown when the invalid index is detected, at which point nd and dim
35  // are usually not known. It is caught at the place they are known, where a
36  // new err_invalid_index is called.
37  //
38  // Typically, this should be caught after any call to
39  // octave_value_list::index_vector()
40 
42  {
43  public:
44 
45  index_exception (const std::string& index_arg, octave_idx_type nd_arg = 0,
46  octave_idx_type dim_arg = -1, const char *var_arg = "")
47  : index (index_arg), nd (nd_arg), dim (dim_arg), var (var_arg)
48  { }
49 
50  ~index_exception (void) { }
51 
52  // Erroneous index value. Called in what, and by external code
53  // (e.g., nth_element) to make a custom error message.
54  std::string idx (void) const { return index; }
55 
56  // details set by subclass.
57  virtual std::string details (void) const = 0;
58 
59  // ID of error to throw.
60  virtual const char *err_id (void) const = 0;
61 
62  virtual std::string message (void) const;
63 
64  // Position of error: dimension in error, and number of dimensions.
65  void set_pos (octave_idx_type nd_arg, octave_idx_type dim_arg)
66  {
67  nd = nd_arg;
68  dim = dim_arg;
69  }
70 
72  {
73  if (nd == 0)
74  {
75  nd = nd_arg;
76  dim = dim_arg;
77  }
78  }
79 
80  // Name of variable being indexed. eye(2)(1,1) gives "<unknown>".
81  void set_var (const std::string& var_arg = "")
82  {
83  var = var_arg;
84  }
85 
86  private:
87 
88  // Value of invalid index.
90 
91  protected:
92 
93  // Show what's wrong, e.g., A(-1,_), A(0+1i).
94  std::string expression (void) const;
95 
96  // Number of dimensions of indexed object.
98 
99  // Dimension number in which invalid index occurred.
101 
102  // Name of variable being indexed.
104 
105  };
106 
107  OCTAVE_NORETURN OCTAVE_API extern void
109 
110  OCTAVE_NORETURN OCTAVE_API extern void
112 
113  OCTAVE_NORETURN OCTAVE_API extern void
114  err_nonconformant (const char *op, octave_idx_type op1_len,
115  octave_idx_type op2_len);
116 
117  OCTAVE_NORETURN OCTAVE_API extern void
118  err_nonconformant (const char *op,
119  octave_idx_type op1_nr, octave_idx_type op1_nc,
120  octave_idx_type op2_nr, octave_idx_type op2_nc);
121 
122  OCTAVE_NORETURN OCTAVE_API extern void
123  err_nonconformant (const char *op,
124  const dim_vector& op1_dims, const dim_vector& op2_dims);
125 
126  OCTAVE_NORETURN OCTAVE_API extern void
127  err_index_out_of_range (int nd, int dim, octave_idx_type iext,
128  octave_idx_type ext, const dim_vector& d);
129 
130  OCTAVE_NORETURN OCTAVE_API extern void
131  err_index_out_of_range (int nd, int dim, octave_idx_type iext,
132  octave_idx_type ext);
133 
134  OCTAVE_NORETURN OCTAVE_API extern void
136  octave_idx_type ext);
137 
138  OCTAVE_NORETURN OCTAVE_API extern void
139  err_invalid_index (double n, octave_idx_type nd = 0,
140  octave_idx_type dim = 0,
141  const std::string& var = "");
142 
143  OCTAVE_NORETURN OCTAVE_API extern void
145  octave_idx_type dim = 0,
146  const std::string& var = "");
147 
148  OCTAVE_NORETURN OCTAVE_API extern void
149  err_invalid_index (const std::string& idx, octave_idx_type nd = 0,
150  octave_idx_type dim = 0,
151  const std::string& var = "");
152 
153  OCTAVE_NORETURN OCTAVE_API extern void
154  err_invalid_resize (void);
155 
156  OCTAVE_API extern void
157  warn_singular_matrix (double rcond = 0.0);
158 }
159 
160 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
161 
162 OCTAVE_DEPRECATED ("use 'octave::err_nan_to_logical_conversion' instead")
163 OCTAVE_NORETURN inline void
165 {
167 }
168 
169 OCTAVE_DEPRECATED ("use 'octave::err_nan_to_character_conversion' instead")
170 OCTAVE_NORETURN inline void
172 {
174 }
175 
176 OCTAVE_DEPRECATED ("use 'octave::err_nonconformant' instead")
177 OCTAVE_NORETURN inline void
178 err_nonconformant (const char *op, octave_idx_type op1_len,
179  octave_idx_type op2_len)
180 {
181  octave::err_nonconformant (op, op1_len, op2_len);
182 }
183 
184 OCTAVE_DEPRECATED ("use 'octave::err_nonconformant' instead")
185 OCTAVE_NORETURN inline void
186 err_nonconformant (const char *op,
187  octave_idx_type op1_nr, octave_idx_type op1_nc,
188  octave_idx_type op2_nr, octave_idx_type op2_nc)
189 {
190  octave::err_nonconformant (op, op1_nr, op1_nc, op2_nr, op2_nc);
191 }
192 
193 OCTAVE_DEPRECATED ("use 'octave::err_nonconformant' instead")
194 OCTAVE_NORETURN inline void
195 err_nonconformant (const char *op,
196  const dim_vector& op1_dims, const dim_vector& op2_dims)
197 {
198  octave::err_nonconformant (op, op1_dims, op2_dims);
199 }
200 
201 OCTAVE_DEPRECATED ("use 'octave::err_index_out_of_range' instead")
202 OCTAVE_NORETURN inline void
203 err_index_out_of_range (int nd, int dim, octave_idx_type iext,
204  octave_idx_type ext, const dim_vector& d)
205 {
206  octave::err_index_out_of_range (nd, dim, iext, ext, d);
207 }
208 
209 OCTAVE_DEPRECATED ("use 'octave::err_index_out_of_range' instead")
210 OCTAVE_NORETURN inline void
211 err_index_out_of_range (int nd, int dim, octave_idx_type iext,
212  octave_idx_type ext)
213 {
214  octave::err_index_out_of_range (nd, dim, iext, ext);
215 }
216 
217 OCTAVE_DEPRECATED ("use 'octave::err_del_index_out_of_range' instead")
218 OCTAVE_NORETURN inline void
220  octave_idx_type ext)
221 {
222  octave::err_del_index_out_of_range (is1d, iext, ext);
223 }
224 
225 OCTAVE_NORETURN inline void
226 err_invalid_index (double n, octave_idx_type nd = 0,
227  octave_idx_type dim = 0,
228  const std::string& var = "")
229 {
230  octave::err_invalid_index (n, nd, dim, var);
231 }
232 
233 OCTAVE_DEPRECATED ("use 'octave::err_invalid_index' instead")
234 OCTAVE_NORETURN inline void
236  octave_idx_type dim = 0,
237  const std::string& var = "")
238 {
239  octave::err_invalid_index (n, nd, dim, var);
240 }
241 
242 OCTAVE_DEPRECATED ("use 'octave::err_invalid_index' instead")
243 OCTAVE_NORETURN inline void
244 err_invalid_index (const std::string& idx, octave_idx_type nd = 0,
245  octave_idx_type dim = 0,
246  const std::string& var = "")
247 {
248  octave::err_invalid_index (idx, nd, dim, var);
249 }
250 
251 OCTAVE_DEPRECATED ("use 'octave::err_invalid_resize' instead")
252 OCTAVE_NORETURN inline void
253 err_invalid_resize (void)
254 {
256 }
257 
258 OCTAVE_DEPRECATED ("use 'octave::warn_singular_matrix' instead")
259 inline void
260 warn_singular_matrix (double rcond = 0.0)
261 {
262  return octave::warn_singular_matrix (rcond);
263 }
264 
265 #endif
266 
267 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
static void err_index_out_of_range(void)
Definition: idx-vector.cc:51
in that an updated permutation matrix is returned Note that if var
Definition: lu.cc:606
void set_pos_if_unset(octave_idx_type nd_arg, octave_idx_type dim_arg)
void err_index_out_of_range(int nd, int dim, octave_idx_type idx, octave_idx_type ext)
void err_invalid_index(const std::string &idx, octave_idx_type nd, octave_idx_type dim, const std::string &)
STL namespace.
std::string idx(void) const
void err_nan_to_logical_conversion(void)
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
virtual std::string message(void) const
void set_var(const std::string &var_arg="")
void err_del_index_out_of_range(bool is1d, octave_idx_type idx, octave_idx_type ext)
virtual const char * err_id(void) const =0
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
void err_invalid_resize(void)
index_exception(const std::string &index_arg, octave_idx_type nd_arg=0, octave_idx_type dim_arg=-1, const char *var_arg="")
void set_pos(octave_idx_type nd_arg, octave_idx_type dim_arg)
virtual std::string details(void) const =0
void err_nan_to_character_conversion(void)
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
void warn_singular_matrix(double rcond)
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
std::string expression(void) const