changeset 21355:28d9bce20aa7

eliminate HAVE_HDF5 macros from public header files * ls-hdf5.h, ls-hdf5.cc: Always define hdf5_fstreambase and related functions. Check HAVE_HDF5 macros in individual functions. * libinterp/corefcn/module.mk (NOINSTALL_COREFCN_SRC): Move oct-hdf5.h here from COREFCN_INC.
author John W. Eaton <jwe@octave.org>
date Thu, 25 Feb 2016 18:43:08 -0500
parents 06d15e4e611a
children 12d5c0538730
files libinterp/corefcn/ls-hdf5.cc libinterp/corefcn/ls-hdf5.h libinterp/corefcn/module.mk
diffstat 3 files changed, 108 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/ls-hdf5.cc	Thu Feb 25 17:34:14 2016 -0500
+++ b/libinterp/corefcn/ls-hdf5.cc	Thu Feb 25 18:43:08 2016 -0500
@@ -75,6 +75,8 @@
 hdf5_fstreambase::hdf5_fstreambase (const char *name, int mode, int /* prot */)
   : file_id (-1), current_item (-1)
 {
+#if defined (HAVE_HDF5)
+
   if (mode & std::ios::in)
     file_id = H5Fopen (name, H5F_ACC_RDONLY, octave_H5P_DEFAULT);
   else if (mode & std::ios::out)
@@ -89,22 +91,37 @@
     std::ios::setstate (std::ios::badbit);
 
   current_item = 0;
+
+#else
+  err_disabled_feature ("hdf5_fstreambase", "HDF5");
+#endif
 }
 
 void
 hdf5_fstreambase::close (void)
 {
+#if defined (HAVE_HDF5)
+
   if (file_id >= 0)
     {
       if (H5Fclose (file_id) < 0)
         std::ios::setstate (std::ios::badbit);
       file_id = -1;
     }
+
+#else
+  // This shouldn't happen because construction of hdf5_fstreambase
+  // objects is supposed to be impossible if HDF5 is not available.
+
+  panic_impossible ();
+#endif
 }
 
 void
 hdf5_fstreambase::open (const char *name, int mode, int)
 {
+#if defined (HAVE_HDF5)
+
   clear ();
 
   if (mode & std::ios::in)
@@ -121,6 +138,13 @@
     std::ios::setstate (std::ios::badbit);
 
   current_item = 0;
+
+#else
+  // This shouldn't happen because construction of hdf5_fstreambase
+  // objects is supposed to be impossible if HDF5 is not available.
+
+  panic_impossible ();
+#endif
 }
 
 static std::string
@@ -153,6 +177,8 @@
 bool
 hdf5_types_compatible (octave_hdf5_id t1, octave_hdf5_id t2)
 {
+#if defined (HAVE_HDF5)
+
   int n;
   if ((n = H5Tget_nmembers (t1)) != H5Tget_nmembers (t2))
     return false;
@@ -170,6 +196,10 @@
     }
 
   return true;
+
+#else
+  err_disabled_feature ("hdf5_types_compatible", "HDF5");
+#endif
 }
 
 // Return true if loc_id has the attribute named attr_name, and false
@@ -178,6 +208,8 @@
 bool
 hdf5_check_attr (octave_hdf5_id loc_id, const char *attr_name)
 {
+#if defined (HAVE_HDF5)
+
   bool retval = false;
 
   // we have to pull some shenanigans here to make sure
@@ -214,12 +246,18 @@
   H5Eset_auto (err_func, err_func_data);
 #endif
   return retval;
+
+#else
+  err_disabled_feature ("hdf5_check_attr", "HDF5");
+#endif
 }
 
 bool
 hdf5_get_scalar_attr (octave_hdf5_id loc_id, octave_hdf5_id type_id,
                       const char *attr_name, void *buf)
 {
+#if defined (HAVE_HDF5)
+
   bool retval = false;
 
   // we have to pull some shenanigans here to make sure
@@ -260,11 +298,12 @@
   H5Eset_auto (err_func, err_func_data);
 #endif
   return retval;
+
+#else
+  err_disabled_feature ("hdf5_get_scalar_attr", "HDF5");
+#endif
 }
 
-
-
-
 // The following subroutines creates an HDF5 representations of the way
 // we will store Octave complex types (pairs of floating-point numbers).
 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g.
@@ -274,12 +313,18 @@
 octave_hdf5_id
 hdf5_make_complex_type (octave_hdf5_id num_type)
 {
+#if defined (HAVE_HDF5)
+
   hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 2);
 
   H5Tinsert (type_id, "real", 0 * sizeof (double), num_type);
   H5Tinsert (type_id, "imag", 1 * sizeof (double), num_type);
 
   return type_id;
+
+#else
+  err_disabled_feature ("hdf5_make_complex_type", "HDF5");
+#endif
 }
 
 // This function is designed to be passed to H5Giterate, which calls it
@@ -295,6 +340,8 @@
 octave_hdf5_err
 hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv)
 {
+#if defined (HAVE_HDF5)
+
   hdf5_callback_data *d = static_cast<hdf5_callback_data *> (dv);
   hid_t type_id = -1;
   hid_t type_class_id = -1;
@@ -623,6 +670,10 @@
     }
 
   return retval;
+
+#else
+  err_disabled_feature ("hdf5_read_next_data", "HDF5");
+#endif
 }
 
 // Read the next Octave variable from the stream IS, which must really be
@@ -635,6 +686,8 @@
                 bool& global, octave_value& tc, std::string& doc,
                 const string_vector& argv, int argv_idx, int argc)
 {
+#if defined (HAVE_HDF5)
+
   check_hdf5_types ();
 
   std::string retval;
@@ -706,6 +759,10 @@
     retval = d.name;
 
   return retval;
+
+#else
+  err_disabled_feature ("read_hdf5_data", "HDF5");
+#endif
 }
 
 // Add an attribute named attr_name to loc_id (a simple scalar
@@ -713,6 +770,8 @@
 octave_hdf5_err
 hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name)
 {
+#if defined (HAVE_HDF5)
+
   herr_t retval = 0;
 
   hid_t as_id = H5Screate (H5S_SCALAR);
@@ -743,12 +802,18 @@
     retval = as_id;
 
   return retval;
+
+#else
+  err_disabled_feature ("hdf5_add_attr", "HDF5");
+#endif
 }
 
 octave_hdf5_err
 hdf5_add_scalar_attr (octave_hdf5_id loc_id, octave_hdf5_id type_id,
                       const char *attr_name, void *buf)
 {
+#if defined (HAVE_HDF5)
+
   herr_t retval = 0;
 
   hid_t as_id = H5Screate (H5S_SCALAR);
@@ -777,6 +842,10 @@
     retval = as_id;
 
   return retval;
+
+#else
+  err_disabled_feature ("hdf5_add_scalar_attr", "HDF5");
+#endif
 }
 
 // Save an empty matrix, if needed. Returns
@@ -786,6 +855,8 @@
 int
 save_hdf5_empty (octave_hdf5_id loc_id, const char *name, const dim_vector d)
 {
+#if defined (HAVE_HDF5)
+
   hsize_t sz = d.length ();
   OCTAVE_LOCAL_BUFFER (octave_idx_type, dims, sz);
   bool empty = false;
@@ -827,6 +898,10 @@
     retval = hdf5_add_attr (loc_id, "OCTAVE_EMPTY_MATRIX");
 
   return (retval == 0 ? 1 : retval);
+
+#else
+  err_disabled_feature ("save_hdf5_empty", "HDF5");
+#endif
 }
 
 // Load an empty matrix, if needed. Returns
@@ -836,6 +911,8 @@
 int
 load_hdf5_empty (octave_hdf5_id loc_id, const char *name, dim_vector &d)
 {
+#if defined (HAVE_HDF5)
+
   if (! hdf5_check_attr (loc_id, "OCTAVE_EMPTY_MATRIX"))
     return 0;
 
@@ -864,18 +941,23 @@
   H5Dclose (data_hid);
 
   return (retval == 0 ? hdims : retval);
+
+#else
+  err_disabled_feature ("load_hdf5_empty", "HDF5");
+#endif
 }
 
 // save_type_to_hdf5 is not currently used, since hdf5 doesn't yet support
 // automatic float<->integer conversions:
 
-#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
-
 // return the HDF5 type id corresponding to the Octave save_type
 
 octave_hdf5_id
 save_type_to_hdf5 (save_type st)
 {
+#if defined (HAVE_HDF5)
+#  if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
+
   switch (st)
     {
     case LS_U_CHAR:
@@ -903,8 +985,14 @@
     default:
       return H5T_NATIVE_DOUBLE;
     }
+
+#  else
+  return -1;
+#  endif
+#else
+  err_disabled_feature ("save_type_to_hdf5", "HDF5");
+#endif
 }
-#endif
 
 // Add the data from TC to the HDF5 location loc_id, which could
 // be either a file or a group within a file.  Return true if
@@ -916,6 +1004,8 @@
                const std::string& name, const std::string& doc,
                bool mark_as_global, bool save_as_floats)
 {
+#if defined (HAVE_HDF5)
+
   hsize_t dims[3];
   hid_t type_id, space_id, data_id, data_type_id;
   type_id = space_id = data_id = data_type_id = -1;
@@ -992,6 +1082,10 @@
     error ("save: error while writing '%s' to hdf5 file", name.c_str ());
 
   return retval;
+
+#else
+  err_disabled_feature ("add_hdf5_data", "HDF5");
+#endif
 }
 
 // Write data from TC in HDF5 (binary) format to the stream OS,
@@ -1002,12 +1096,18 @@
                 const std::string& name, const std::string& doc,
                 bool mark_as_global, bool save_as_floats)
 {
+#if defined (HAVE_HDF5)
+
   check_hdf5_types ();
 
   hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os);
 
   return add_hdf5_data (hs.file_id, tc, name, doc,
                         mark_as_global, save_as_floats);
+
+#else
+  err_disabled_feature ("save_hdf5_data", "HDF5");
+#endif
 }
 
 #endif
--- a/libinterp/corefcn/ls-hdf5.h	Thu Feb 25 17:34:14 2016 -0500
+++ b/libinterp/corefcn/ls-hdf5.h	Thu Feb 25 18:43:08 2016 -0500
@@ -25,8 +25,6 @@
 
 #include "octave-config.h"
 
-#if defined (HAVE_HDF5)
-
 #include "oct-hdf5-types.h"
 
 // first, we need to define our own dummy stream subclass, since
@@ -112,10 +110,8 @@
   std::string doc;
 };
 
-#if defined (HAVE_HDF5_INT2FLOAT_CONVERSIONS)
 extern OCTINTERP_API octave_hdf5_id
-save_type_to_hdf5 (save_type st)
-#endif
+save_type_to_hdf5 (save_type st);
 
 extern OCTINTERP_API octave_hdf5_id
 hdf5_make_complex_type (octave_hdf5_id num_type);
@@ -163,5 +159,3 @@
                       const char *attr_name, void *buf);
 
 #endif
-
-#endif
--- a/libinterp/corefcn/module.mk	Thu Feb 25 17:34:14 2016 -0500
+++ b/libinterp/corefcn/module.mk	Thu Feb 25 18:43:08 2016 -0500
@@ -60,7 +60,6 @@
   libinterp/corefcn/oct-errno.h \
   libinterp/corefcn/oct-fstrm.h \
   libinterp/corefcn/oct-handle.h \
-  libinterp/corefcn/oct-hdf5.h \
   libinterp/corefcn/oct-hdf5-types.h \
   libinterp/corefcn/oct-hist.h \
   libinterp/corefcn/oct-iostrm.h \
@@ -107,6 +106,7 @@
   libinterp/corefcn/siglist.c
 
 NOINSTALL_COREFCN_INC = \
+  libinterp/corefcn/oct-hdf5.h \
   libinterp/corefcn/oct-opengl.h \
   libinterp/corefcn/siglist.h