GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-type-conv.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2013 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_ov_type_conv_h)
24 #define octave_ov_type_conv_h 1
25 
26 static
28 octave_type_conv_body (const octave_value &arg, const std::string& name,
29  int t_result)
30 {
31  int t_arg = arg.type_id ();
32  octave_value retval;
33 
34  if (t_arg == t_result || arg.class_name () == name)
35  {
36  retval = arg;
37  }
38  else
39  {
42 
43  if (cf1)
44  {
45  octave_base_value *tmp (cf1 (*(arg.internal_rep ())));
46 
47  if (tmp)
48  {
49  retval = octave_value (tmp);
50 
51  retval.maybe_mutate ();
52  }
53  }
54  else
55  {
58 
59  if (cf2)
60  {
61  octave_base_value *tmp (cf2 (*(arg.internal_rep ())));
62 
63  if (tmp)
64  {
65  octave_value xarg (tmp);
66 
67  retval = octave_type_conv_body (xarg, name, t_result);
68  }
69  }
70  }
71  }
72 
73  return retval;
74 }
75 
76 
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  \
89  retval = octave_type_conv_body (arg, #NAME, t_result); \
90  if (retval.is_undefined ()) \
91  { \
92  std::string arg_tname = arg.type_name (); \
93  \
94  std::string result_tname = arg.numel () == 1 \
95  ? SCALAR_RESULT_T::static_type_name () \
96  : MATRIX_RESULT_T::static_type_name (); \
97  \
98  gripe_invalid_conversion (arg_tname, result_tname); \
99  } \
100  } \
101  else \
102  print_usage (); \
103  \
104  return retval
105 
106 #define OCTAVE_TYPE_CONV_BODY(NAME) \
107  OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \
108  octave_ ## NAME ## _scalar)
109 
110 #endif