4901
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \ |
|
24 \ |
|
25 octave_value retval; \ |
|
26 \ |
|
27 int nargin = args.length (); \ |
|
28 \ |
|
29 if (nargin == 1) \ |
|
30 { \ |
|
31 const octave_value arg = args(0); \ |
|
32 \ |
|
33 int t_arg = arg.type_id (); \ |
|
34 \ |
|
35 int t_result = MATRIX_RESULT_T::static_type_id (); \ |
|
36 \ |
|
37 if (t_arg != t_result) \ |
|
38 { \ |
|
39 type_conv_fcn cf \ |
|
40 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); \ |
|
41 \ |
|
42 if (cf) \ |
|
43 { \ |
|
44 octave_value *tmp (cf (*(arg.internal_rep ()))); \ |
|
45 \ |
|
46 if (tmp) \ |
|
47 { \ |
|
48 retval = octave_value (tmp); \ |
|
49 \ |
|
50 retval.maybe_mutate (); \ |
|
51 } \ |
|
52 } \ |
|
53 else \ |
|
54 { \ |
|
55 std::string arg_tname = arg.type_name (); \ |
|
56 \ |
|
57 std::string result_tname = arg.numel () == 1 \ |
|
58 ? SCALAR_RESULT_T::static_type_name () \ |
|
59 : MATRIX_RESULT_T::static_type_name (); \ |
|
60 \ |
|
61 gripe_invalid_conversion (arg_tname, result_tname); \ |
|
62 } \ |
|
63 } \ |
4952
|
64 else \ |
|
65 retval = arg; \ |
4901
|
66 } \ |
|
67 else \ |
|
68 print_usage (#NAME); \ |
|
69 \ |
|
70 return retval |
|
71 |
|
72 #define OCTAVE_TYPE_CONV_BODY(NAME) \ |
|
73 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ |
|
74 octave_ ## NAME ## _scalar) |
|
75 |
|
76 /* |
|
77 ;;; Local Variables: *** |
|
78 ;;; mode: C++ *** |
|
79 ;;; End: *** |
|
80 */ |