comparison src/ov-type-conv.h @ 4901:35bfb4e0b96b

[project @ 2004-06-14 18:33:02 by jwe]
author jwe
date Mon, 14 Jun 2004 18:33:02 +0000
parents
children bfd57b466752
comparison
equal deleted inserted replaced
4900:cf470c996819 4901:35bfb4e0b96b
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
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 \
37 if (t_arg != t_result) \
38 { \
39 type_conv_fcn cf \
40 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result); \
41 \
42 if (cf) \
43 { \
44 octave_value *tmp (cf (*(arg.internal_rep ()))); \
45 \
46 if (tmp) \
47 { \
48 retval = octave_value (tmp); \
49 \
50 retval.maybe_mutate (); \
51 } \
52 } \
53 else \
54 { \
55 std::string arg_tname = arg.type_name (); \
56 \
57 std::string result_tname = arg.numel () == 1 \
58 ? SCALAR_RESULT_T::static_type_name () \
59 : MATRIX_RESULT_T::static_type_name (); \
60 \
61 gripe_invalid_conversion (arg_tname, result_tname); \
62 } \
63 } \
64 } \
65 else \
66 print_usage (#NAME); \
67 \
68 return retval
69
70 #define OCTAVE_TYPE_CONV_BODY(NAME) \
71 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \
72 octave_ ## NAME ## _scalar)
73
74 /*
75 ;;; Local Variables: ***
76 ;;; mode: C++ ***
77 ;;; End: ***
78 */