changeset 10380:60acc47c203f

configure checks for complex element setter/reference accessor methods
author John W. Eaton <jwe@octave.org>
date Mon, 01 Mar 2010 15:02:25 -0500
parents f578e6468d0c
children 1aa8b9b8f921
files ChangeLog acinclude.m4 configure.ac src/ChangeLog src/DLD-FUNCTIONS/str2double.cc
diffstat 5 files changed, 57 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 01 15:24:05 2010 +0100
+++ b/ChangeLog	Mon Mar 01 15:02:25 2010 -0500
@@ -1,3 +1,9 @@
+2010-03-01  John W. Eaton  <jwe@octave.org>
+
+	* acinclude.m4 (OCTAVE_CXX_COMPLEX_REFERENCE_ACCESSORS,
+	OCTAVE_CXX_COMPLEX_SETTERS): New macros.
+	* configure.ac: Use them.
+
 2010-02-25  John W. Eaton  <jwe@octave.org>
 
 	* gdbinit: New file.
--- a/acinclude.m4	Mon Mar 01 15:24:05 2010 +0100
+++ b/acinclude.m4	Mon Mar 01 15:02:25 2010 -0500
@@ -106,6 +106,38 @@
 AC_LANG_POP(C++)
 ])
 dnl
+dnl See if the C++ library has functions to set real and imaginary
+dnl parts of complex numbers independently.
+dnl
+AC_DEFUN([OCTAVE_CXX_COMPLEX_SETTERS],
+[AC_CACHE_CHECK([whether complex class can set components independently],
+octave_cv_cxx_complex_setters,
+[AC_LANG_PUSH(C++)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <complex>]],
+[[std::complex<double> x; x.real (1.0); x.imag (2.0);]])],
+octave_cv_cxx_complex_setters=yes, octave_cv_cxx_complex_setters=no)])
+if test $octave_cv_cxx_complex_setters = yes; then
+AC_DEFINE(HAVE_CXX_COMPLEX_SETTERS,1,[Define if C++ complex class has void real (T) and void imag (T) methods])
+fi
+AC_LANG_POP(C++)
+])
+dnl
+dnl See if the C++ library has functions to access real and imaginary
+dnl parts of complex numbers independently via references.
+dnl
+AC_DEFUN([OCTAVE_CXX_COMPLEX_REFERENCE_ACCESSORS],
+[AC_CACHE_CHECK([whether complex class can reference components independently],
+octave_cv_cxx_complex_reference_accessors,
+[AC_LANG_PUSH(C++)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <complex>]],
+[[std::complex<double> x; x.real () = 1.0; x.imag () = 1.0;]])],
+octave_cv_cxx_complex_reference_accessors=yes, octave_cv_cxx_complex_reference_accessors=no)])
+if test $octave_cv_cxx_complex_reference_accessors = yes; then
+AC_DEFINE(HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS,1,[Define if C++ complex class has T& real (void) and T& imag (void) methods])
+fi
+AC_LANG_POP(C++)
+])
+dnl
 dnl The following test is from Karl Berry's Kpathseach library.  I'm
 dnl including it here in case we someday want to make the use of
 dnl kpathsea optional.
--- a/configure.ac	Mon Mar 01 15:24:05 2010 +0100
+++ b/configure.ac	Mon Mar 01 15:02:25 2010 -0500
@@ -607,6 +607,9 @@
 
 OCTAVE_IEEE754_DATA_FORMAT
 
+OCTAVE_CXX_COMPLEX_SETTERS
+OCTAVE_CXX_COMPLEX_REFERENCE_ACCESSORS
+
 ### Check for the QHull library
 
 OCTAVE_CHECK_LIBRARY(qhull, QHull,
--- a/src/ChangeLog	Mon Mar 01 15:24:05 2010 +0100
+++ b/src/ChangeLog	Mon Mar 01 15:02:25 2010 -0500
@@ -1,3 +1,9 @@
+2010-03-01  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/str2double.cc (set_component): Use autoconf
+	macros instead of checking predefined compiler macros.
+	(str2double1): Pass val to set_component, not c.
+
 2010-03-01  Jaroslav Hajek  <highegg@gmail.com>
 
 	* DLD-FUNCTIONS/str2double.cc (set_component): New helper func.
--- a/src/DLD-FUNCTIONS/str2double.cc	Mon Mar 01 15:24:05 2010 +0100
+++ b/src/DLD-FUNCTIONS/str2double.cc	Mon Mar 01 15:02:25 2010 -0500
@@ -139,12 +139,16 @@
 static inline void
 set_component (Complex& c, double num, bool imag)
 {
-  // FIXME: this is C++-0x.
-#if defined (__GNUC__) || defined (__MSVC__)
+#if defined (HAVE_CXX_COMPLEX_SETTERS)
   if (imag)
-    c.imag (r);
+    c.imag (num);
   else
-    c.real (r);
+    c.real (num);
+#elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS)
+  if (imag)
+    c.imag () = num;
+  else
+    c.real () = num;
 #else
   if (imag)
     c = Complex (c.real (), num);
@@ -173,14 +177,14 @@
     val = octave_NaN;
   else
     {
-      set_component (c, num, i1);
+      set_component (val, num, i1);
 
       if (! is.eof ())
         {
           if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2)
             val = octave_NaN;
           else
-            set_component (c, num, i2);
+            set_component (val, num, i2);
         }
     }