Mercurial > octave-nkf
annotate liboctave/util/lo-array-gripes.h @ 20651:e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
* lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf
buffers from 100 to 64 characters (still well more than 19 required).
Use 'const' decorator on constant value for clarity. Remove extra space
between variable and array bracket.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 12 Oct 2015 21:13:47 -0700 |
parents | dd6345fd8a97 |
children |
rev | line source |
---|---|
11135 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19442
diff
changeset
|
3 Copyright (C) 2000-2015 John W. Eaton |
11135 | 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 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
23 #if !defined (octave_lo_array_gripes_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 #define octave_lo_array_gripes_h 1 |
11135 | 25 |
26 #include "dim-vector.h" | |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
27 #include "quit.h" |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
28 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
29 // Exception thrown by gripe_invalid_index |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
30 // This is thrown when the invalid index is detected, at which point nd and dim |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
31 // are usually not known. It is caught at the place they are known, where a |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
32 // new gripe_invalid_index is called. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
33 // |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
34 // Typically, this should be caught after any call to |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
35 // octave_value_list::index_vector() |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
36 class index_exception : public octave_execution_exception |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
37 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
38 public: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
39 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
40 index_exception (const char *index_in, octave_idx_type nd_in = 0, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
41 octave_idx_type dim_in = 0, const char *var_in = "") |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
42 : index (index_in), nd (nd_in), dim (dim_in), var (var_in) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
43 { } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
44 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
45 ~index_exception (void) throw () { } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
46 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
47 // Erroneous index value. Called in what, and by external code |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
48 // (e.g., nth_element) to make a custom error message. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
49 const char *idx (void) const { return index.c_str (); } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
50 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
51 // details set by subclass. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
52 virtual const char* explain (void) const = 0; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
53 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
54 // ID of error to throw. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
55 virtual const char* id (void) const = 0; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
56 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
57 virtual const char* err (void) throw (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
58 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
59 // Position of error: dimension in error, and number of dimensions. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
60 void set_pos (octave_idx_type nd_in, octave_idx_type dim_in) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
61 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
62 nd = nd_in; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
63 dim = dim_in; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
64 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
65 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
66 void set_pos_if_unset (octave_idx_type nd_in, octave_idx_type dim_in) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
67 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
68 if (nd == 0) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
69 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
70 nd = nd_in; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
71 dim = dim_in; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
72 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
73 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
74 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
75 // Name of variable being indexed. eye(2)(1,1) gives "<unknown>". |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
76 void set_var (std::string var_in) { var = var_in; } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
77 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
78 private: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
79 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
80 // Value of invalid index. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
81 std::string index; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
82 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
83 // Formatted message returned by what(), (not on stack). |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
84 std::string msg; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
85 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
86 protected: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
87 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
88 // Show what's wrong, e.g., A(-1,_), A(0+1i). |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
89 std::string access (void) const; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
90 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
91 // Number of dimensions of indexed object. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
92 octave_idx_type nd; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
93 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
94 // Dimension number in which invalid index occurred. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
95 octave_idx_type dim; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
96 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
97 // Name of variable being indexed. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
98 std::string var; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
99 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
100 }; |
11135 | 101 |
102 extern OCTAVE_API const char *error_id_nonconformant_args; | |
103 | |
104 extern OCTAVE_API const char *error_id_index_out_of_bounds; | |
105 | |
106 extern OCTAVE_API const char *error_id_invalid_index; | |
107 | |
19442
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
108 extern OCTAVE_API const char *warning_id_nearly_singular_matrix; |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
109 |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
110 extern OCTAVE_API const char *warning_id_singular_matrix; |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
111 |
11135 | 112 extern void OCTAVE_API |
113 gripe_nan_to_logical_conversion (void); | |
114 | |
115 extern void OCTAVE_API | |
116 gripe_nan_to_character_conversion (void); | |
117 | |
118 extern void OCTAVE_API | |
119 gripe_nonconformant (const char *op, | |
120 octave_idx_type op1_len, octave_idx_type op2_len); | |
121 | |
122 extern void OCTAVE_API | |
123 gripe_nonconformant (const char *op, | |
124 octave_idx_type op1_nr, octave_idx_type op1_nc, | |
125 octave_idx_type op2_nr, octave_idx_type op2_nc); | |
126 | |
127 | |
128 extern void OCTAVE_API | |
129 gripe_nonconformant (const char *op, const dim_vector& op1_dims, | |
130 const dim_vector& op2_dims); | |
131 | |
132 extern void OCTAVE_API | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
133 gripe_index_out_of_range (int nd, int dim, |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
134 octave_idx_type iext, octave_idx_type ext, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
135 const dim_vector& d); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
136 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
137 extern void OCTAVE_API |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
138 gripe_index_out_of_range (int nd, int dim, |
11135 | 139 octave_idx_type iext, octave_idx_type ext); |
140 | |
141 extern void OCTAVE_API | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
142 gripe_del_index_out_of_range (bool is1d, octave_idx_type iext, |
11135 | 143 octave_idx_type ext); |
144 | |
145 extern void OCTAVE_API | |
20574
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
146 gripe_invalid_index (double, octave_idx_type nd=0, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
147 octave_idx_type dim=0, const char *var = NULL); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
148 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
149 extern void OCTAVE_API |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
150 gripe_invalid_index (octave_idx_type n, octave_idx_type nd=0, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
151 octave_idx_type dim=0, const char *var = NULL); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
152 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
153 extern void OCTAVE_API |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
154 gripe_invalid_index (const char *idx, octave_idx_type nd=0, |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19731
diff
changeset
|
155 octave_idx_type dim=0, const char *var = NULL); |
11135 | 156 |
157 extern void OCTAVE_API | |
158 gripe_invalid_resize (void); | |
159 | |
160 extern void OCTAVE_API | |
19442
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
161 gripe_singular_matrix (double rcond = 0.0); |
a0c7001cf1a8
consistent messages and IDs for singular matrix warnings
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
162 |
11135 | 163 #endif |