Mercurial > hg > octave-nkf
annotate libinterp/octave-value/ov-type-conv.h @ 18718:51a0d1c1023c stable
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Make parameter list case-insensitive.
Return empty matrix rather than empty cell list on failure.
* listdlg.m: Use for loop to index into java array to get octave value.
Use strcmpi to parse input options. Correctly return an empty matrix
rather than empty list if dialog fails.
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Sat, 22 Mar 2014 16:04:32 +0100 |
parents | 175b392e91fe |
children | 4197fc428c7d |
rev | line source |
---|---|
4901 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 2004-2013 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 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
28 octave_type_conv_body (const octave_value &arg, const std::string& name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
29 int t_result) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
30 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
31 int t_arg = arg.type_id (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
32 octave_value retval; |
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 if (t_arg == t_result || arg.class_name () == name) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
35 { |
10184
b39bd23019eb
partially revert a668fbd32e34
Jaroslav Hajek <highegg@gmail.com>
parents:
10181
diff
changeset
|
36 retval = arg; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
37 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
38 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
39 { |
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
|
40 octave_base_value::type_conv_fcn cf1 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
41 = 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
|
42 |
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
|
43 if (cf1) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
44 { |
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
|
45 octave_base_value *tmp (cf1 (*(arg.internal_rep ()))); |
8150
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 if (tmp) |
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 retval = octave_value (tmp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
50 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
51 retval.maybe_mutate (); |
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 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
54 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
55 { |
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
|
56 octave_base_value::type_conv_fcn cf2 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
57 = arg.numeric_conversion_function (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
58 |
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
|
59 if (cf2) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
60 { |
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
|
61 octave_base_value *tmp (cf2 (*(arg.internal_rep ()))); |
8150
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 if (tmp) |
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 octave_value xarg (tmp); |
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 retval = octave_type_conv_body (xarg, name, t_result); |
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 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
73 return retval; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
74 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
75 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
76 |
4901 | 77 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \ |
78 \ | |
79 octave_value retval; \ | |
80 \ | |
81 int nargin = args.length (); \ | |
82 \ | |
83 if (nargin == 1) \ | |
84 { \ | |
85 const octave_value arg = args(0); \ | |
86 \ | |
87 int t_result = MATRIX_RESULT_T::static_type_id (); \ | |
88 \ | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
89 retval = octave_type_conv_body (arg, #NAME, t_result); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
90 if (retval.is_undefined ()) \ |
4901 | 91 { \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
92 std::string arg_tname = arg.type_name (); \ |
4901 | 93 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
94 std::string result_tname = arg.numel () == 1 \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
95 ? SCALAR_RESULT_T::static_type_name () \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
96 : MATRIX_RESULT_T::static_type_name (); \ |
4901 | 97 \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
98 gripe_invalid_conversion (arg_tname, result_tname); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
99 } \ |
4901 | 100 } \ |
101 else \ | |
5823 | 102 print_usage (); \ |
4901 | 103 \ |
104 return retval | |
105 | |
106 #define OCTAVE_TYPE_CONV_BODY(NAME) \ | |
107 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \ | |
10313 | 108 octave_ ## NAME ## _scalar) |
4901 | 109 |
9340 | 110 #endif |