octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conversion of octave_int<short int> to int? moved from help-octave


From: John W. Eaton
Subject: Re: conversion of octave_int<short int> to int? moved from help-octave
Date: Mon, 26 Nov 2007 22:06:06 -0500

On 26-Nov-2007, Moritz Borgmann wrote:

| I propose that this patch be removed again, since it doesn't compile 
| on Solaris CC. Why it does in fact compile under gcc is beyond me. 
| See the thread "Solaris: Multiple declaration for 
| octave_int<char>::operator char() const" started on bug-octave on 
| Thu, 22 Nov 2007 02:54:23 +0100.
| 
| Reverting the patch may not be the best solution in the long run, but 
| it is certainly better than a solution that doesn't even compile. 
| IIRC, the patch was not necessary for any octave core functionality.
| 
| More discussion on the conversion operators is probably needed for a 
| permanent solution.

I checked in the following change instead of removing the new
conversion operator.  Does it work for you with the Solaris compiler?

jwe


liboctave/ChangeLog:

2007-11-26  John W. Eaton  <address@hidden>

        * idx-vector.h (idx_vector::idx_vector_rep (const intNDArray<U>&)):
        Eliminate unnecessary second arg from call to tree_to_mat_idx.

        * oct-inttypes.h (operator bool, operator char): Delete.
        (bool_value, char_value, double_value, float_value): New functions.


src/ChangeLog:

2007-11-26  John W. Eaton  <address@hidden>

        * oct-stream.cc (do_write): Call float_value and double_value on
        octave_int<T> objects instead of relying on conversion operators.

        * ls-mat5.cc (read_mat5_binary_element, OCTAVE_MAT5_INTEGER_READ): 
        Call double_value on octave_int<T> objects
        instead of relying on conversion operator.
        (read_mat5_binary_file_header): 
        Call char_value on octave_int<T> objects
        instead of relying on conversion operator.
        (read_mat5_binary_element): 
        Call bool_value on octave_int<T> objects
        instead of relying on conversion operator.

        * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::double_value, 
        OCTAVE_VALUE_INT_MATRIX_T::scalar_value,
        OCTAVE_VALUE_INT_MATRIX_T::matrix_value,
        OCTAVE_VALUE_INT_MATRIX_T::complex_matrix_value,
        OCTAVE_VALUE_INT_MATRIX_T::array_value,
        OCTAVE_VALUE_INT_MATRIX_T::complex_array_value,
        OCTAVE_VALUE_INT_SCALAR_T::double_value, 
        OCTAVE_VALUE_INT_SCALAR_T::scalar_value,
        OCTAVE_VALUE_INT_SCALAR_T::matrix_value,
        OCTAVE_VALUE_INT_SCALAR_T::complex_matrix_value,
        OCTAVE_VALUE_INT_SCALAR_T::array_value,
        OCTAVE_VALUE_INT_SCALAR_T::complex_array_value,
        Call double_value on octave_int<T> objects
        instead of relying on conversion operator.
        (OCTAVE_VALUE_INT_MATRIX_T::bool_array_value,
        OCTAVE_VALUE_INT_SCALAR_T::bool_array_value):
        Call bool_value on octave_int<T> objects
        instead of relying on conversion operator.
        (OCTAVE_VALUE_INT_MATRIX_T::char_array_value,
        OCTAVE_VALUE_INT_SCALAR_T::char_array_value):
        Call char_value on octave_int<T> objects
        instead of relying on conversion operator.


Index: liboctave/idx-vector.h
===================================================================
RCS file: /cvs/octave/liboctave/idx-vector.h,v
retrieving revision 1.53
diff -u -u -r1.53 idx-vector.h
--- liboctave/idx-vector.h      12 Oct 2007 21:27:16 -0000      1.53
+++ liboctave/idx-vector.h      27 Nov 2007 02:54:54 -0000
@@ -74,13 +74,8 @@
        {
          data = new octave_idx_type [len];
 
-         bool conversion_error = false;
-
          for (octave_idx_type i = 0; i < len; i++)
-           data[i] = tree_to_mat_idx (inda.elem (i), conversion_error);
-
-         if (conversion_error)
-           return;
+           data[i] = tree_to_mat_idx (inda.elem (i));
        }
 
       init_state ();
Index: liboctave/oct-inttypes.h
===================================================================
RCS file: /cvs/octave/liboctave/oct-inttypes.h,v
retrieving revision 1.33
diff -u -u -r1.33 oct-inttypes.h
--- liboctave/oct-inttypes.h    14 Nov 2007 22:21:35 -0000      1.33
+++ liboctave/oct-inttypes.h    27 Nov 2007 02:54:54 -0000
@@ -250,15 +250,21 @@
       OCTAVE_INT_FIT_TO_RANGE (- static_cast<double> (ival), T) : 0;
   }
 
-  operator T (void) const { return value (); }
+  bool bool_value (void) const { return static_cast<bool> (value ()); }
+
+  char char_value (void) const { return static_cast<char> (value ()); }
+
+  double double_value (void) const { return static_cast<double> (value ()); }
 
-  operator bool (void) const { return static_cast<bool> (value ()); }
+  float float_value (void) const { return static_cast<float> (value ()); }
+
+  operator T (void) const { return value (); }
 
-  operator char (void) const { return static_cast<char> (value ()); }
+  // char and bool operators intentionally omitted.
 
-  operator double (void) const { return static_cast<double> (value ()); }
+  operator double (void) const { return double_value (); }
 
-  operator float (void) const { return static_cast<float> (value ()); }
+  operator float (void) const { return float_value (); }
 
   octave_int<T>& operator += (const octave_int<T>& x)
   {
Index: src/ls-mat5.cc
===================================================================
RCS file: /cvs/octave/src/ls-mat5.cc,v
retrieving revision 1.46
diff -u -u -r1.46 ls-mat5.cc
--- src/ls-mat5.cc      12 Oct 2007 21:27:30 -0000      1.46
+++ src/ls-mat5.cc      27 Nov 2007 02:54:57 -0000
@@ -334,7 +334,7 @@
            ComplexNDArray ctmp (dims); \
   \
            for (int i = 0; i < n; i++) \
-             ctmp(i) = Complex (double (re(i)), im(i)); \
+             ctmp(i) = Complex (re(i).double_value (), im(i)); \
   \
             tc = ctmp;  \
          } \
@@ -863,7 +863,7 @@
          {
            Octave_map m2 = m1.contents("workspace")(0).map_value();
            uint32NDArray MCOS = m2.contents("MCOS")(0).uint32_array_value();
-           octave_idx_type off = static_cast<octave_idx_type>(double (MCOS 
(4)));
+           octave_idx_type off = 
static_cast<octave_idx_type>(MCOS(4).double_value ());
            m2 = subsys_ov.map_value();
            m2 = m2.contents("MCOS")(0).map_value();
            tc2 = m2.contents("MCOS")(0).cell_value()(1 + off).cell_value()(1);
@@ -1140,7 +1140,7 @@
            boolNDArray out (dims);
            
            for (int i = 0; i < nel; i++)
-             out (i) = static_cast<bool> (double (in (i)));
+             out (i) = in(i).bool_value ();
 
            tc = out;
          }
@@ -1377,7 +1377,7 @@
          // FIXME -- find a way to avoid casting away const here
          char *ctmp = const_cast<char *> (outbuf.c_str ());
          for (octave_idx_type j = 8; j < ilen; j++)
-           ctmp [j - 8] = itmp (j);
+           ctmp[j-8] = itmp(j).char_value ();
 
          std::istringstream fh_ws (outbuf);
 
Index: src/ov-intx.h
===================================================================
RCS file: /cvs/octave/src/ov-intx.h,v
retrieving revision 1.31
diff -u -u -r1.31 ov-intx.h
--- src/ov-intx.h       24 Oct 2007 21:09:44 -0000      1.31
+++ src/ov-intx.h       27 Nov 2007 02:54:57 -0000
@@ -99,7 +99,7 @@
          gripe_implicit_conversion ("Octave:array-as-scalar",
                                     type_name (), "real scalar");
 
-         retval = double (matrix(0));
+         retval = matrix(0).double_value ();
        }
       else
        gripe_invalid_conversion (type_name (), "real scalar");
@@ -123,7 +123,7 @@
          double *vec = retval.fortran_vec ();
          octave_idx_type nel = matrix.numel ();
          for (octave_idx_type i = 0; i < nel; i++)
-           vec[i] = double (matrix(i));
+           vec[i] = matrix(i).double_value ();
        }
       return retval;
     }
@@ -141,7 +141,7 @@
          Complex *vec = retval.fortran_vec ();
          octave_idx_type nel = matrix.numel ();
          for (octave_idx_type i = 0; i < nel; i++)
-           vec[i] = Complex (double (matrix(i)));
+           vec[i] = Complex (matrix(i).double_value ());
        }
       return retval;
     }
@@ -153,7 +153,7 @@
       double *vec = retval.fortran_vec ();
       octave_idx_type nel = matrix.numel ();
       for (octave_idx_type i = 0; i < nel; i++)
-        vec[i] = double (matrix(i));
+        vec[i] = matrix(i).double_value ();
       return retval;
     }
 
@@ -164,7 +164,7 @@
       Complex *vec = retval.fortran_vec ();
       octave_idx_type nel = matrix.numel ();
       for (octave_idx_type i = 0; i < nel; i++)
-        vec[i] = Complex (double (matrix(i)));
+        vec[i] = Complex (matrix(i).double_value ());
       return retval;
     }
 
@@ -180,7 +180,7 @@
 
     bool *vec = retval.fortran_vec ();
     for (octave_idx_type i = 0; i < nel; i++)
-      vec[i] = static_cast<bool> (matrix(i));
+      vec[i] = matrix(i).bool_value ();
 
     return retval;
   }
@@ -194,7 +194,7 @@
   
     char *vec = retval.fortran_vec ();
     for (octave_idx_type i = 0; i < nel; i++)
-      vec[i] = static_cast<char> (matrix(i));
+      vec[i] = matrix(i).char_value ();
 
     return retval;
   }
@@ -361,16 +361,16 @@
        }
     }
 
-  double double_value (bool = false) const { return double (scalar); }
+  double double_value (bool = false) const { return scalar.double_value (); }
 
-  double scalar_value (bool = false) const { return double (scalar); }
+  double scalar_value (bool = false) const { return scalar.double_value (); }
 
 
   Matrix
   matrix_value (bool = false) const
     {
       Matrix retval (1, 1);
-      retval(0,0) = double (scalar);
+      retval(0,0) = scalar.double_value ();
       return retval;
     }
 
@@ -378,7 +378,7 @@
   complex_matrix_value (bool = false) const
     {
       ComplexMatrix retval (1, 1);
-      retval(0,0) = Complex (double (scalar));
+      retval(0,0) = Complex (scalar.double_value ());
       return retval;
     }
 
@@ -387,7 +387,7 @@
   array_value (bool = false) const
     { 
       NDArray retval (dim_vector (1, 1)); 
-      retval(0) = double (scalar);
+      retval(0) = scalar.double_value ();
       return retval;
     }
 
@@ -395,7 +395,7 @@
   complex_array_value (bool = false) const
     { 
       ComplexNDArray retval (dim_vector (1, 1));
-      retval(0) = Complex (double (scalar));
+      retval(0) = Complex (scalar.double_value ());
       return retval;
     }
 
@@ -407,7 +407,7 @@
     if (warn && scalar != 0.0 && scalar != 1.0)
       gripe_logical_conversion ();
 
-    retval(0) = static_cast<bool> (scalar);
+    retval(0) = scalar.bool_value ();
 
     return retval;
   }
@@ -416,7 +416,7 @@
   char_array_value (bool = false) const
   {
     charNDArray retval (dim_vector (1, 1));
-    retval(0) = static_cast<char> (scalar);
+    retval(0) = scalar.char_value ();
     return retval;
   }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]