op-str-str.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-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-str-mat.h"
00031 #include "ov-typeinfo.h"
00032 #include "ov-null-mat.h"
00033 #include "ops.h"
00034 
00035 // string unary ops.
00036 
00037 DEFUNOP (transpose, char_matrix_str)
00038 {
00039   CAST_UNOP_ARG (const octave_char_matrix_str&);
00040 
00041   if (v.ndims () > 2)
00042     {
00043       error ("transpose not defined for N-d objects");
00044       return octave_value ();
00045     }
00046   else
00047     return octave_value (v.char_matrix_value().transpose (),
00048                          a.is_sq_string () ? '\'' : '"');
00049 }
00050 
00051 // string by string ops.
00052 
00053 #define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f)  \
00054   BINOPDECL (name, a1, a2) \
00055   { \
00056     dim_vector a1_dims = a1.dims (); \
00057     dim_vector a2_dims = a2.dims (); \
00058  \
00059     bool a1_is_scalar = a1_dims.all_ones (); \
00060     bool a2_is_scalar = a2_dims.all_ones (); \
00061  \
00062     CAST_BINOP_ARGS (const octave_ ## t1&, const octave_ ## t2&); \
00063  \
00064     if (a1_is_scalar) \
00065       { \
00066         if (a2_is_scalar) \
00067           return octave_value ((v1.e1 ## _value ())(0) op (v2.e2 ## _value ())(0)); \
00068         else \
00069           return octave_value (f ((v1.e1 ## _value ())(0), v2.e2 ## _value ())); \
00070       } \
00071     else \
00072       { \
00073         if (a2_is_scalar) \
00074           return octave_value (f (v1.e1 ## _value (), (v2.e2 ## _value ())(0))); \
00075         else \
00076           return octave_value (f (v1.e1 ## _value (), v2.e2 ## _value ())); \
00077       } \
00078   }
00079 
00080 DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_lt)
00081 DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_le)
00082 DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_eq)
00083 DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_ge)
00084 DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_gt)
00085 DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array, char_array, mx_el_ne)
00086 
00087 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str)
00088 {
00089   CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&);
00090 
00091   v1.assign (idx, v2.char_array_value ());
00092   return octave_value ();
00093 }
00094 
00095 DEFNULLASSIGNOP_FN (null_assign, char_matrix_str, delete_elements)
00096 
00097 DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat)
00098 
00099 void
00100 install_str_str_ops (void)
00101 {
00102   INSTALL_UNOP (op_transpose, octave_char_matrix_str, transpose);
00103   INSTALL_UNOP (op_transpose, octave_char_matrix_sq_str, transpose);
00104 
00105   INSTALL_UNOP (op_hermitian, octave_char_matrix_str, transpose);
00106   INSTALL_UNOP (op_hermitian, octave_char_matrix_sq_str, transpose);
00107 
00108   INSTALL_BINOP (op_lt, octave_char_matrix_str, octave_char_matrix_str, lt);
00109   INSTALL_BINOP (op_lt, octave_char_matrix_str, octave_char_matrix_sq_str, lt);
00110   INSTALL_BINOP (op_lt, octave_char_matrix_sq_str, octave_char_matrix_str, lt);
00111   INSTALL_BINOP (op_lt, octave_char_matrix_sq_str, octave_char_matrix_sq_str, lt);
00112 
00113   INSTALL_BINOP (op_le, octave_char_matrix_str, octave_char_matrix_str, le);
00114   INSTALL_BINOP (op_le, octave_char_matrix_str, octave_char_matrix_sq_str, le);
00115   INSTALL_BINOP (op_le, octave_char_matrix_sq_str, octave_char_matrix_str, le);
00116   INSTALL_BINOP (op_le, octave_char_matrix_sq_str, octave_char_matrix_sq_str, le);
00117 
00118   INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_str, eq);
00119   INSTALL_BINOP (op_eq, octave_char_matrix_str, octave_char_matrix_sq_str, eq);
00120   INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_str, eq);
00121   INSTALL_BINOP (op_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, eq);
00122 
00123   INSTALL_BINOP (op_ge, octave_char_matrix_str, octave_char_matrix_str, ge);
00124   INSTALL_BINOP (op_ge, octave_char_matrix_str, octave_char_matrix_sq_str, ge);
00125   INSTALL_BINOP (op_ge, octave_char_matrix_sq_str, octave_char_matrix_str, ge);
00126   INSTALL_BINOP (op_ge, octave_char_matrix_sq_str, octave_char_matrix_sq_str, ge);
00127 
00128   INSTALL_BINOP (op_gt, octave_char_matrix_str, octave_char_matrix_str, gt);
00129   INSTALL_BINOP (op_gt, octave_char_matrix_str, octave_char_matrix_sq_str, gt);
00130   INSTALL_BINOP (op_gt, octave_char_matrix_sq_str, octave_char_matrix_str, gt);
00131   INSTALL_BINOP (op_gt, octave_char_matrix_sq_str, octave_char_matrix_sq_str, gt);
00132 
00133   INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_str, ne);
00134   INSTALL_BINOP (op_ne, octave_char_matrix_str, octave_char_matrix_sq_str, ne);
00135   INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_str, ne);
00136   INSTALL_BINOP (op_ne, octave_char_matrix_sq_str, octave_char_matrix_sq_str, ne);
00137 
00138   INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_str, str_str);
00139   INSTALL_CATOP (octave_char_matrix_str, octave_char_matrix_sq_str, str_str);
00140   INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_str, str_str);
00141   INSTALL_CATOP (octave_char_matrix_sq_str, octave_char_matrix_sq_str, str_str);
00142 
00143   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_str, assign);
00144   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_char_matrix_sq_str, assign);
00145   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_str, assign);
00146   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_char_matrix_sq_str, assign);
00147 
00148   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_null_matrix, null_assign);
00149   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_null_str, null_assign);
00150   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_str, octave_null_sq_str, null_assign);
00151   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_null_matrix, null_assign);
00152   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_null_str, null_assign);
00153   INSTALL_ASSIGNOP (op_asn_eq, octave_char_matrix_sq_str, octave_null_sq_str, null_assign);
00154 
00155 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines