4901
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2004, 2005, 2006, 2007 John W. Eaton |
4901
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
4901
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
4901
|
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 \ |
5476
|
37 if (t_arg == t_result || arg.class_name () == #NAME) \ |
|
38 { \ |
|
39 retval = arg; \ |
|
40 } \ |
|
41 else \ |
4901
|
42 { \ |
5759
|
43 octave_base_value::type_conv_fcn cf \ |
4901
|
44 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); \ |
|
45 \ |
|
46 if (cf) \ |
|
47 { \ |
5759
|
48 octave_base_value *tmp (cf (*(arg.internal_rep ()))); \ |
4901
|
49 \ |
|
50 if (tmp) \ |
|
51 { \ |
|
52 retval = octave_value (tmp); \ |
|
53 \ |
|
54 retval.maybe_mutate (); \ |
|
55 } \ |
|
56 } \ |
|
57 else \ |
|
58 { \ |
|
59 std::string arg_tname = arg.type_name (); \ |
|
60 \ |
|
61 std::string result_tname = arg.numel () == 1 \ |
|
62 ? SCALAR_RESULT_T::static_type_name () \ |
|
63 : MATRIX_RESULT_T::static_type_name (); \ |
|
64 \ |
|
65 gripe_invalid_conversion (arg_tname, result_tname); \ |
|
66 } \ |
|
67 } \ |
|
68 } \ |
|
69 else \ |
5823
|
70 print_usage (); \ |
4901
|
71 \ |
|
72 return retval |
|
73 |
|
74 #define OCTAVE_TYPE_CONV_BODY(NAME) \ |
|
75 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ |
|
76 octave_ ## NAME ## _scalar) |
|
77 |
|
78 /* |
|
79 ;;; Local Variables: *** |
|
80 ;;; mode: C++ *** |
|
81 ;;; End: *** |
|
82 */ |