Mercurial > hg > octave-lyh
annotate libinterp/octave-value/ov-type-conv.h @ 17526:05bed3576091
Fix int16 type comments
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 04:18:59 +0800 |
parents | 2fc554ffbc28 |
children |
rev | line source |
---|---|
4901 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2004-2012 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 | |
9340 | 23 #if !defined (octave_ov_type_conv_h) |
24 #define octave_ov_type_conv_h 1 | |
25 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
26 static |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
27 octave_value |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
28 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
|
29 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
30 int t_arg = arg.type_id (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
31 octave_value retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
32 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
33 if (t_arg == t_result || arg.class_name () == name) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
34 { |
10184
b39bd23019eb
partially revert a668fbd32e34
Jaroslav Hajek <highegg@gmail.com>
parents:
10181
diff
changeset
|
35 retval = arg; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
36 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
37 else |
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 octave_base_value::type_conv_fcn cf1 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
40 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
41 |
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
|
42 if (cf1) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
43 { |
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
|
44 octave_base_value *tmp (cf1 (*(arg.internal_rep ()))); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
45 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
46 if (tmp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
47 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
48 retval = octave_value (tmp); |
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 retval.maybe_mutate (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
51 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
52 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
53 else |
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 octave_base_value::type_conv_fcn cf2 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
56 = arg.numeric_conversion_function (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
57 |
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
|
58 if (cf2) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
59 { |
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
|
60 octave_base_value *tmp (cf2 (*(arg.internal_rep ()))); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
61 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
62 if (tmp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
63 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
64 octave_value xarg (tmp); |
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 retval = octave_type_conv_body (xarg, name, t_result); |
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 } |
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 return retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
73 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
75 |
4901 | 76 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \ |
77 \ | |
78 octave_value retval; \ | |
79 \ | |
80 int nargin = args.length (); \ | |
81 \ | |
82 if (nargin == 1) \ | |
83 { \ | |
84 const octave_value arg = args(0); \ | |
85 \ | |
86 int t_result = MATRIX_RESULT_T::static_type_id (); \ | |
87 \ | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
88 retval = octave_type_conv_body (arg, #NAME, t_result); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
89 if (retval.is_undefined ()) \ |
4901 | 90 { \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
91 std::string arg_tname = arg.type_name (); \ |
4901 | 92 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
93 std::string result_tname = arg.numel () == 1 \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
94 ? SCALAR_RESULT_T::static_type_name () \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
95 : MATRIX_RESULT_T::static_type_name (); \ |
4901 | 96 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
97 gripe_invalid_conversion (arg_tname, result_tname); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
98 } \ |
4901 | 99 } \ |
100 else \ | |
5823 | 101 print_usage (); \ |
4901 | 102 \ |
103 return retval | |
104 | |
105 #define OCTAVE_TYPE_CONV_BODY(NAME) \ | |
106 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ | |
10313 | 107 octave_ ## NAME ## _scalar) |
4901 | 108 |
9340 | 109 #endif |