op-int-conv.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-int8.h"
00031 #include "ov-int16.h"
00032 #include "ov-int32.h"
00033 #include "ov-int64.h"
00034 #include "ov-uint8.h"
00035 #include "ov-uint16.h"
00036 #include "ov-uint32.h"
00037 #include "ov-uint64.h"
00038 #include "ov-range.h"
00039 #include "ov-bool.h"
00040 #include "ov-bool-mat.h"
00041 #include "ov-scalar.h"
00042 #include "ov-float.h"
00043 #include "ov-re-mat.h"
00044 #include "ov-flt-re-mat.h"
00045 #include "ov-str-mat.h"
00046 #include "ov-typeinfo.h"
00047 #include "ops.h"
00048 
00049 #define DEFINTCONVFN(name, tfrom, tto) \
00050   CONVDECL (name) \
00051   { \
00052     CAST_CONV_ARG (const octave_ ## tfrom&); \
00053  \
00054     octave_ ## tto ## _matrix v2 = v.tto ## _array_value (); \
00055     return new octave_ ## tto ## _matrix (v2); \
00056   }
00057 
00058 // conversion ops
00059 
00060 DEFINTCONVFN (scalar_to_int8, scalar, int8)
00061 DEFINTCONVFN (scalar_to_int16, scalar, int16)
00062 DEFINTCONVFN (scalar_to_int32, scalar, int32)
00063 DEFINTCONVFN (scalar_to_int64, scalar, int64)
00064 
00065 DEFINTCONVFN (scalar_to_uint8, scalar, uint8)
00066 DEFINTCONVFN (scalar_to_uint16, scalar, uint16)
00067 DEFINTCONVFN (scalar_to_uint32, scalar, uint32)
00068 DEFINTCONVFN (scalar_to_uint64, scalar, uint64)
00069 
00070 DEFINTCONVFN (matrix_to_int8, matrix, int8)
00071 DEFINTCONVFN (matrix_to_int16, matrix, int16)
00072 DEFINTCONVFN (matrix_to_int32, matrix, int32)
00073 DEFINTCONVFN (matrix_to_int64, matrix, int64)
00074 
00075 DEFINTCONVFN (matrix_to_uint8, matrix, uint8)
00076 DEFINTCONVFN (matrix_to_uint16, matrix, uint16)
00077 DEFINTCONVFN (matrix_to_uint32, matrix, uint32)
00078 DEFINTCONVFN (matrix_to_uint64, matrix, uint64)
00079 
00080 DEFINTCONVFN (float_scalar_to_int8, float_scalar, int8)
00081 DEFINTCONVFN (float_scalar_to_int16, float_scalar, int16)
00082 DEFINTCONVFN (float_scalar_to_int32, float_scalar, int32)
00083 DEFINTCONVFN (float_scalar_to_int64, float_scalar, int64)
00084 
00085 DEFINTCONVFN (float_scalar_to_uint8, float_scalar, uint8)
00086 DEFINTCONVFN (float_scalar_to_uint16, float_scalar, uint16)
00087 DEFINTCONVFN (float_scalar_to_uint32, float_scalar, uint32)
00088 DEFINTCONVFN (float_scalar_to_uint64, float_scalar, uint64)
00089 
00090 DEFINTCONVFN (float_matrix_to_int8, float_matrix, int8)
00091 DEFINTCONVFN (float_matrix_to_int16, float_matrix, int16)
00092 DEFINTCONVFN (float_matrix_to_int32, float_matrix, int32)
00093 DEFINTCONVFN (float_matrix_to_int64, float_matrix, int64)
00094 
00095 DEFINTCONVFN (float_matrix_to_uint8, float_matrix, uint8)
00096 DEFINTCONVFN (float_matrix_to_uint16, float_matrix, uint16)
00097 DEFINTCONVFN (float_matrix_to_uint32, float_matrix, uint32)
00098 DEFINTCONVFN (float_matrix_to_uint64, float_matrix, uint64)
00099 
00100 DEFCONVFN (bool_to_int8, bool, int8)
00101 DEFCONVFN (bool_to_int16, bool, int16)
00102 DEFCONVFN (bool_to_int32, bool, int32)
00103 DEFCONVFN (bool_to_int64, bool, int64)
00104 
00105 DEFCONVFN (bool_to_uint8, bool, uint8)
00106 DEFCONVFN (bool_to_uint16, bool, uint16)
00107 DEFCONVFN (bool_to_uint32, bool, uint32)
00108 DEFCONVFN (bool_to_uint64, bool, uint64)
00109 
00110 DEFCONVFN (bool_matrix_to_int8, bool_matrix, int8)
00111 DEFCONVFN (bool_matrix_to_int16, bool_matrix, int16)
00112 DEFCONVFN (bool_matrix_to_int32, bool_matrix, int32)
00113 DEFCONVFN (bool_matrix_to_int64, bool_matrix, int64)
00114 
00115 DEFCONVFN (bool_matrix_to_uint8, bool_matrix, uint8)
00116 DEFCONVFN (bool_matrix_to_uint16, bool_matrix, uint16)
00117 DEFCONVFN (bool_matrix_to_uint32, bool_matrix, uint32)
00118 DEFCONVFN (bool_matrix_to_uint64, bool_matrix, uint64)
00119 
00120 DEFSTRINTCONVFN (char_matrix_sq_str_to_int8, int8)
00121 DEFSTRINTCONVFN (char_matrix_sq_str_to_int16, int16)
00122 DEFSTRINTCONVFN (char_matrix_sq_str_to_int32, int32)
00123 DEFSTRINTCONVFN (char_matrix_sq_str_to_int64, int64)
00124 
00125 DEFSTRINTCONVFN (char_matrix_sq_str_to_uint8, uint8)
00126 DEFSTRINTCONVFN (char_matrix_sq_str_to_uint16, uint16)
00127 DEFSTRINTCONVFN (char_matrix_sq_str_to_uint32, uint32)
00128 DEFSTRINTCONVFN (char_matrix_sq_str_to_uint64, uint64)
00129 
00130 DEFSTRINTCONVFN (char_matrix_dq_str_to_int8, int8)
00131 DEFSTRINTCONVFN (char_matrix_dq_str_to_int16, int16)
00132 DEFSTRINTCONVFN (char_matrix_dq_str_to_int32, int32)
00133 DEFSTRINTCONVFN (char_matrix_dq_str_to_int64, int64)
00134 
00135 DEFSTRINTCONVFN (char_matrix_dq_str_to_uint8, uint8)
00136 DEFSTRINTCONVFN (char_matrix_dq_str_to_uint16, uint16)
00137 DEFSTRINTCONVFN (char_matrix_dq_str_to_uint32, uint32)
00138 DEFSTRINTCONVFN (char_matrix_dq_str_to_uint64, uint64)
00139 
00140 DEFINTCONVFN (range_to_int8, range, int8)
00141 DEFINTCONVFN (range_to_int16, range, int16)
00142 DEFINTCONVFN (range_to_int32, range, int32)
00143 DEFINTCONVFN (range_to_int64, range, int64)
00144 
00145 DEFINTCONVFN (range_to_uint8, range, uint8)
00146 DEFINTCONVFN (range_to_uint16, range, uint16)
00147 DEFINTCONVFN (range_to_uint32, range, uint32)
00148 DEFINTCONVFN (range_to_uint64, range, uint64)
00149 
00150 #define INT_CONV_FUNCTIONS(tfrom) \
00151   DEFCONVFN2 (tfrom ## _scalar_to_int8, tfrom, scalar, int8) \
00152   DEFCONVFN2 (tfrom ## _scalar_to_int16, tfrom, scalar, int16) \
00153   DEFCONVFN2 (tfrom ## _scalar_to_int32, tfrom, scalar, int32) \
00154   DEFCONVFN2 (tfrom ## _scalar_to_int64, tfrom, scalar, int64) \
00155  \
00156   DEFCONVFN2 (tfrom ## _scalar_to_uint8, tfrom, scalar, uint8) \
00157   DEFCONVFN2 (tfrom ## _scalar_to_uint16, tfrom, scalar, uint16) \
00158   DEFCONVFN2 (tfrom ## _scalar_to_uint32, tfrom, scalar, uint32) \
00159   DEFCONVFN2 (tfrom ## _scalar_to_uint64, tfrom, scalar, uint64) \
00160  \
00161   DEFCONVFN2 (tfrom ## _matrix_to_int8, tfrom, matrix, int8) \
00162   DEFCONVFN2 (tfrom ## _matrix_to_int16, tfrom, matrix, int16) \
00163   DEFCONVFN2 (tfrom ## _matrix_to_int32, tfrom, matrix, int32) \
00164   DEFCONVFN2 (tfrom ## _matrix_to_int64, tfrom, matrix, int64) \
00165  \
00166   DEFCONVFN2 (tfrom ## _matrix_to_uint8, tfrom, matrix, uint8) \
00167   DEFCONVFN2 (tfrom ## _matrix_to_uint16, tfrom, matrix, uint16) \
00168   DEFCONVFN2 (tfrom ## _matrix_to_uint32, tfrom, matrix, uint32) \
00169   DEFCONVFN2 (tfrom ## _matrix_to_uint64, tfrom, matrix, uint64)
00170 
00171 INT_CONV_FUNCTIONS (int8)
00172 INT_CONV_FUNCTIONS (int16)
00173 INT_CONV_FUNCTIONS (int32)
00174 INT_CONV_FUNCTIONS (int64)
00175 
00176 INT_CONV_FUNCTIONS (uint8)
00177 INT_CONV_FUNCTIONS (uint16)
00178 INT_CONV_FUNCTIONS (uint32)
00179 INT_CONV_FUNCTIONS (uint64)
00180 
00181 #define INSTALL_INT_CONV_FUNCTIONS(tfrom) \
00182   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_int8_matrix, tfrom ## _scalar_to_int8) \
00183   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_int16_matrix, tfrom ## _scalar_to_int16) \
00184   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_int32_matrix, tfrom ## _scalar_to_int32) \
00185   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_int64_matrix, tfrom ## _scalar_to_int64) \
00186  \
00187   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_uint8_matrix, tfrom ## _scalar_to_uint8) \
00188   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_uint16_matrix, tfrom ## _scalar_to_uint16) \
00189   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_uint32_matrix, tfrom ## _scalar_to_uint32) \
00190   INSTALL_CONVOP (octave_ ## tfrom ## _scalar, octave_uint64_matrix, tfrom ## _scalar_to_uint64) \
00191  \
00192   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_int8_matrix, tfrom ## _matrix_to_int8) \
00193   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_int16_matrix, tfrom ## _matrix_to_int16) \
00194   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_int32_matrix, tfrom ## _matrix_to_int32) \
00195   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_int64_matrix, tfrom ## _matrix_to_int64) \
00196  \
00197   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_uint8_matrix, tfrom ## _matrix_to_uint8) \
00198   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_uint16_matrix, tfrom ## _matrix_to_uint16) \
00199   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_uint32_matrix, tfrom ## _matrix_to_uint32) \
00200   INSTALL_CONVOP (octave_ ## tfrom ## _matrix, octave_uint64_matrix, tfrom ## _matrix_to_uint64)
00201 
00202 #define INSTALL_CONVOPS(tfrom) \
00203   INSTALL_CONVOP (octave_ ## tfrom, octave_int8_matrix, tfrom ## _to_int8) \
00204   INSTALL_CONVOP (octave_ ## tfrom, octave_int16_matrix, tfrom ## _to_int16) \
00205   INSTALL_CONVOP (octave_ ## tfrom, octave_int32_matrix, tfrom ## _to_int32) \
00206   INSTALL_CONVOP (octave_ ## tfrom, octave_int64_matrix, tfrom ## _to_int64) \
00207  \
00208   INSTALL_CONVOP (octave_ ## tfrom, octave_uint8_matrix, tfrom ## _to_uint8) \
00209   INSTALL_CONVOP (octave_ ## tfrom, octave_uint16_matrix, tfrom ## _to_uint16) \
00210   INSTALL_CONVOP (octave_ ## tfrom, octave_uint32_matrix, tfrom ## _to_uint32) \
00211   INSTALL_CONVOP (octave_ ## tfrom, octave_uint64_matrix, tfrom ## _to_uint64)
00212 
00213 void
00214 install_int_conv_ops (void)
00215 {
00216   INSTALL_CONVOPS (scalar)
00217   INSTALL_CONVOPS (matrix)
00218   INSTALL_CONVOPS (float_scalar)
00219   INSTALL_CONVOPS (float_matrix)
00220   INSTALL_CONVOPS (bool)
00221   INSTALL_CONVOPS (bool_matrix)
00222   INSTALL_CONVOPS (range)
00223   INSTALL_CONVOPS (char_matrix_sq_str)
00224   INSTALL_CONVOPS (char_matrix_dq_str)
00225 
00226   INSTALL_INT_CONV_FUNCTIONS (int8)
00227   INSTALL_INT_CONV_FUNCTIONS (int16)
00228   INSTALL_INT_CONV_FUNCTIONS (int32)
00229   INSTALL_INT_CONV_FUNCTIONS (int64)
00230 
00231   INSTALL_INT_CONV_FUNCTIONS (uint8)
00232   INSTALL_INT_CONV_FUNCTIONS (uint16)
00233   INSTALL_INT_CONV_FUNCTIONS (uint32)
00234   INSTALL_INT_CONV_FUNCTIONS (uint64)
00235 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines