lo-array-gripes.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2003-2012 John W. Eaton
00004 Copyright (C) 2009 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include "lo-array-gripes.h"
00029 #include "lo-error.h"
00030 
00031 const char *error_id_nonconformant_args = "Octave:nonconformant-args";
00032 
00033 const char *error_id_index_out_of_bounds = "Octave:index-out-of-bounds";
00034 
00035 const char *error_id_invalid_index = "Octave:invalid-index";
00036 
00037 void
00038 gripe_nan_to_logical_conversion (void)
00039 {
00040   (*current_liboctave_error_handler)
00041     ("invalid conversion from NaN to logical");
00042 }
00043 
00044 void
00045 gripe_nan_to_character_conversion (void)
00046 {
00047   (*current_liboctave_error_handler)
00048     ("invalid conversion from NaN to character");
00049 }
00050 
00051 void
00052 gripe_nonconformant (const char *op, octave_idx_type op1_len,
00053                      octave_idx_type op2_len)
00054 {
00055   const char *err_id = error_id_nonconformant_args;
00056 
00057   (*current_liboctave_error_with_id_handler)
00058     (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)",
00059      op, op1_len, op2_len);
00060 }
00061 
00062 void
00063 gripe_nonconformant (const char *op,
00064                      octave_idx_type op1_nr, octave_idx_type op1_nc,
00065                      octave_idx_type op2_nr, octave_idx_type op2_nc)
00066 {
00067   const char *err_id = error_id_nonconformant_args;
00068 
00069   (*current_liboctave_error_with_id_handler)
00070     (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)",
00071      op, op1_nr, op1_nc, op2_nr, op2_nc);
00072 }
00073 
00074 void
00075 gripe_nonconformant (const char *op, const dim_vector& op1_dims,
00076                      const dim_vector& op2_dims)
00077 {
00078   const char *err_id = error_id_nonconformant_args;
00079 
00080   std::string op1_dims_str = op1_dims.str ();
00081   std::string op2_dims_str = op2_dims.str ();
00082 
00083   (*current_liboctave_error_with_id_handler)
00084     (err_id, "%s: nonconformant arguments (op1 is %s, op2 is %s)",
00085      op, op1_dims_str.c_str (), op2_dims_str.c_str ());
00086 }
00087 
00088 void
00089 gripe_index_out_of_range (int nd, int dim, octave_idx_type idx,
00090                           octave_idx_type ext)
00091 {
00092   const char *err_id = error_id_index_out_of_bounds;
00093 
00094   switch (nd)
00095     {
00096     case 1:
00097       (*current_liboctave_error_with_id_handler)
00098         (err_id, "A(I): index out of bounds; value %d out of bound %d",
00099          idx, ext);
00100       break;
00101 
00102     case 2:
00103       (*current_liboctave_error_with_id_handler)
00104         (err_id, "A(I,J): %s index out of bounds; value %d out of bound %d",
00105          (dim == 1) ? "row" : "column", idx, ext);
00106       break;
00107 
00108     default:
00109       (*current_liboctave_error_with_id_handler)
00110         (err_id, "A(I,J,...): index to dimension %d out of bounds; value %d out of bound %d",
00111          dim, idx, ext);
00112       break;
00113     }
00114 }
00115 
00116 void
00117 gripe_del_index_out_of_range (bool is1d, octave_idx_type idx,
00118                               octave_idx_type ext)
00119 {
00120   const char *err_id = error_id_index_out_of_bounds;
00121 
00122   (*current_liboctave_error_with_id_handler)
00123     (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d",
00124      is1d ? "I" : "..,I,..", idx, ext);
00125 }
00126 
00127 void
00128 gripe_invalid_index (void)
00129 {
00130   const char *err_id = error_id_invalid_index;
00131 
00132   (*current_liboctave_error_with_id_handler)
00133     (err_id, "subscript indices must be either positive integers or logicals");
00134 }
00135 
00136 // FIXME -- the following is a common error message to resize,
00137 // regardless of whether it's called from assign or elsewhere.  It
00138 // seems OK to me, but eventually the gripe can be specialized.
00139 // Anyway, propagating various error messages into procedure is, IMHO,
00140 // a nonsense.  If anything, we should change error handling here (and
00141 // throughout liboctave) to allow custom handling of errors
00142 
00143 void
00144 gripe_invalid_resize (void)
00145 {
00146   (*current_liboctave_error_with_id_handler)
00147     ("Octave:invalid-resize",
00148      "Invalid resizing operation or ambiguous assignment to an out-of-bounds array element");
00149 }
00150 
00151 void
00152 gripe_invalid_assignment_size (void)
00153 {
00154   (*current_liboctave_error_handler)
00155     ("A(I) = X: X must have the same size as I");
00156 }
00157 
00158 void
00159 gripe_assignment_dimension_mismatch (void)
00160 {
00161   (*current_liboctave_error_handler)
00162     ("A(I,J,...) = X: dimensions mismatch");
00163 }
00164 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines