Mercurial > hg > octave-lyh
annotate src/ov-type-conv.h @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | bb3bdcdaa063 |
children | 49fe8721bae1 |
rev | line source |
---|---|
4901 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008 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 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
23 static |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
24 octave_value |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
25 octave_type_conv_body (const octave_value &arg, const std::string& name, int t_result) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
26 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
27 int t_arg = arg.type_id (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
28 octave_value retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
29 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
30 if (t_arg == t_result || arg.class_name () == name) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
31 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
32 retval = arg; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
33 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
34 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
35 { |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
36 octave_base_value::type_conv_fcn cf1 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
37 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
38 |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
39 if (cf1) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
40 { |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
41 octave_base_value *tmp (cf1 (*(arg.internal_rep ()))); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
42 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
43 if (tmp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
44 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
45 retval = octave_value (tmp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
46 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
47 retval.maybe_mutate (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
48 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
49 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
50 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
51 { |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
52 octave_base_value::type_conv_fcn cf2 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
53 = arg.numeric_conversion_function (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
54 |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
55 if (cf2) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
56 { |
8184
bb3bdcdaa063
oct-type-conv.h (octave_type_conv_body): avoid shadow warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8150
diff
changeset
|
57 octave_base_value *tmp (cf2 (*(arg.internal_rep ()))); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
58 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
59 if (tmp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
60 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
61 octave_value xarg (tmp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
62 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
63 retval = octave_type_conv_body (xarg, name, t_result); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
64 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
65 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
66 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
67 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
68 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
69 return retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
70 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
71 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
72 |
4901 | 73 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \ |
74 \ | |
75 octave_value retval; \ | |
76 \ | |
77 int nargin = args.length (); \ | |
78 \ | |
79 if (nargin == 1) \ | |
80 { \ | |
81 const octave_value arg = args(0); \ | |
82 \ | |
83 int t_result = MATRIX_RESULT_T::static_type_id (); \ | |
84 \ | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
85 retval = octave_type_conv_body (arg, #NAME, t_result); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
86 if (retval.is_undefined ()) \ |
4901 | 87 { \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
88 std::string arg_tname = arg.type_name (); \ |
4901 | 89 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
90 std::string result_tname = arg.numel () == 1 \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
91 ? SCALAR_RESULT_T::static_type_name () \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
92 : MATRIX_RESULT_T::static_type_name (); \ |
4901 | 93 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
94 gripe_invalid_conversion (arg_tname, result_tname); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
95 } \ |
4901 | 96 } \ |
97 else \ | |
5823 | 98 print_usage (); \ |
4901 | 99 \ |
100 return retval | |
101 | |
102 #define OCTAVE_TYPE_CONV_BODY(NAME) \ | |
103 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ | |
104 octave_ ## NAME ## _scalar) | |
105 | |
106 /* | |
107 ;;; Local Variables: *** | |
108 ;;; mode: C++ *** | |
109 ;;; End: *** | |
110 */ |