00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_ov_type_conv_h)
00024 #define octave_ov_type_conv_h 1
00025
00026 static
00027 octave_value
00028 octave_type_conv_body (const octave_value &arg, const std::string& name, int t_result)
00029 {
00030 int t_arg = arg.type_id ();
00031 octave_value retval;
00032
00033 if (t_arg == t_result || arg.class_name () == name)
00034 {
00035 retval = arg;
00036 }
00037 else
00038 {
00039 octave_base_value::type_conv_fcn cf1
00040 = octave_value_typeinfo::lookup_type_conv_op (t_arg, t_result);
00041
00042 if (cf1)
00043 {
00044 octave_base_value *tmp (cf1 (*(arg.internal_rep ())));
00045
00046 if (tmp)
00047 {
00048 retval = octave_value (tmp);
00049
00050 retval.maybe_mutate ();
00051 }
00052 }
00053 else
00054 {
00055 octave_base_value::type_conv_fcn cf2
00056 = arg.numeric_conversion_function ();
00057
00058 if (cf2)
00059 {
00060 octave_base_value *tmp (cf2 (*(arg.internal_rep ())));
00061
00062 if (tmp)
00063 {
00064 octave_value xarg (tmp);
00065
00066 retval = octave_type_conv_body (xarg, name, t_result);
00067 }
00068 }
00069 }
00070 }
00071
00072 return retval;
00073 }
00074
00075
00076 #define OCTAVE_TYPE_CONV_BODY3(NAME, MATRIX_RESULT_T, SCALAR_RESULT_T) \
00077 \
00078 octave_value retval; \
00079 \
00080 int nargin = args.length (); \
00081 \
00082 if (nargin == 1) \
00083 { \
00084 const octave_value arg = args(0); \
00085 \
00086 int t_result = MATRIX_RESULT_T::static_type_id (); \
00087 \
00088 retval = octave_type_conv_body (arg, #NAME, t_result); \
00089 if (retval.is_undefined ()) \
00090 { \
00091 std::string arg_tname = arg.type_name (); \
00092 \
00093 std::string result_tname = arg.numel () == 1 \
00094 ? SCALAR_RESULT_T::static_type_name () \
00095 : MATRIX_RESULT_T::static_type_name (); \
00096 \
00097 gripe_invalid_conversion (arg_tname, result_tname); \
00098 } \
00099 } \
00100 else \
00101 print_usage (); \
00102 \
00103 return retval
00104
00105 #define OCTAVE_TYPE_CONV_BODY(NAME) \
00106 OCTAVE_TYPE_CONV_BODY3 (NAME, octave_ ## NAME ## _matrix, \
00107 octave_ ## NAME ## _scalar)
00108
00109 #endif
00110
00111
00112
00113
00114
00115