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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4901
|
21 |
|
22 */ |
|
23 |
|
24 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \ |
|
25 \ |
|
26 octave_value retval; \ |
|
27 \ |
|
28 int nargin = args.length (); \ |
|
29 \ |
|
30 if (nargin == 1) \ |
|
31 { \ |
|
32 const octave_value arg = args(0); \ |
|
33 \ |
|
34 int t_arg = arg.type_id (); \ |
|
35 \ |
|
36 int t_result = MATRIX_RESULT_T::static_type_id (); \ |
|
37 \ |
5476
|
38 if (t_arg == t_result || arg.class_name () == #NAME) \ |
|
39 { \ |
|
40 retval = arg; \ |
|
41 } \ |
|
42 else \ |
4901
|
43 { \ |
5759
|
44 octave_base_value::type_conv_fcn cf \ |
4901
|
45 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); \ |
|
46 \ |
|
47 if (cf) \ |
|
48 { \ |
5759
|
49 octave_base_value *tmp (cf (*(arg.internal_rep ()))); \ |
4901
|
50 \ |
|
51 if (tmp) \ |
|
52 { \ |
|
53 retval = octave_value (tmp); \ |
|
54 \ |
|
55 retval.maybe_mutate (); \ |
|
56 } \ |
|
57 } \ |
|
58 else \ |
|
59 { \ |
|
60 std::string arg_tname = arg.type_name (); \ |
|
61 \ |
|
62 std::string result_tname = arg.numel () == 1 \ |
|
63 ? SCALAR_RESULT_T::static_type_name () \ |
|
64 : MATRIX_RESULT_T::static_type_name (); \ |
|
65 \ |
|
66 gripe_invalid_conversion (arg_tname, result_tname); \ |
|
67 } \ |
|
68 } \ |
|
69 } \ |
|
70 else \ |
5823
|
71 print_usage (); \ |
4901
|
72 \ |
|
73 return retval |
|
74 |
|
75 #define OCTAVE_TYPE_CONV_BODY(NAME) \ |
|
76 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ |
|
77 octave_ ## NAME ## _scalar) |
|
78 |
|
79 /* |
|
80 ;;; Local Variables: *** |
|
81 ;;; mode: C++ *** |
|
82 ;;; End: *** |
|
83 */ |