def_hdf5.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. #if defined(ARMA_USE_HDF5)
  16. #if !defined(ARMA_USE_HDF5_ALT)
  17. // macros needed if the wrapper run-time library is not being used
  18. #define arma_H5Tcopy H5Tcopy
  19. #define arma_H5Tcreate H5Tcreate
  20. #define arma_H5Tinsert H5Tinsert
  21. #define arma_H5Tequal H5Tequal
  22. #define arma_H5Tclose H5Tclose
  23. #define arma_H5Dopen H5Dopen
  24. #define arma_H5Dget_type H5Dget_type
  25. #define arma_H5Dclose H5Dclose
  26. #define arma_H5Dwrite H5Dwrite
  27. #define arma_H5Dget_space H5Dget_space
  28. #define arma_H5Dread H5Dread
  29. #define arma_H5Dcreate H5Dcreate
  30. #define arma_H5Sget_simple_extent_ndims H5Sget_simple_extent_ndims
  31. #define arma_H5Sget_simple_extent_dims H5Sget_simple_extent_dims
  32. #define arma_H5Sclose H5Sclose
  33. #define arma_H5Screate_simple H5Screate_simple
  34. #define arma_H5Ovisit H5Ovisit
  35. #define arma_H5Eset_auto H5Eset_auto
  36. #define arma_H5Eget_auto H5Eget_auto
  37. #define arma_H5Fopen H5Fopen
  38. #define arma_H5Fcreate H5Fcreate
  39. #define arma_H5Fclose H5Fclose
  40. #define arma_H5Fis_hdf5 H5Fis_hdf5
  41. #define arma_H5Gcreate H5Gcreate
  42. #define arma_H5Gopen H5Gopen
  43. #define arma_H5Gclose H5Gclose
  44. #define arma_H5Lexists H5Lexists
  45. #define arma_H5Ldelete H5Ldelete
  46. #define arma_H5T_NATIVE_UCHAR H5T_NATIVE_UCHAR
  47. #define arma_H5T_NATIVE_CHAR H5T_NATIVE_CHAR
  48. #define arma_H5T_NATIVE_SHORT H5T_NATIVE_SHORT
  49. #define arma_H5T_NATIVE_USHORT H5T_NATIVE_USHORT
  50. #define arma_H5T_NATIVE_INT H5T_NATIVE_INT
  51. #define arma_H5T_NATIVE_UINT H5T_NATIVE_UINT
  52. #define arma_H5T_NATIVE_LONG H5T_NATIVE_LONG
  53. #define arma_H5T_NATIVE_ULONG H5T_NATIVE_ULONG
  54. #define arma_H5T_NATIVE_LLONG H5T_NATIVE_LLONG
  55. #define arma_H5T_NATIVE_ULLONG H5T_NATIVE_ULLONG
  56. #define arma_H5T_NATIVE_FLOAT H5T_NATIVE_FLOAT
  57. #define arma_H5T_NATIVE_DOUBLE H5T_NATIVE_DOUBLE
  58. #else
  59. // prototypes for the wrapper functions defined in the wrapper run-time library (src/wrapper.cpp)
  60. extern "C"
  61. {
  62. // Wrapper functions for H5* functions.
  63. hid_t arma_H5Tcopy(hid_t dtype_id);
  64. hid_t arma_H5Tcreate(H5T_class_t cl, size_t size);
  65. herr_t arma_H5Tinsert(hid_t dtype_id, const char* name, size_t offset, hid_t field_id);
  66. htri_t arma_H5Tequal(hid_t dtype_id1, hid_t dtype_id2);
  67. herr_t arma_H5Tclose(hid_t dtype_id);
  68. hid_t arma_H5Dopen(hid_t loc_id, const char* name, hid_t dapl_id);
  69. hid_t arma_H5Dget_type(hid_t dataset_id);
  70. herr_t arma_H5Dclose(hid_t dataset_id);
  71. hid_t arma_H5Dcreate(hid_t loc_id, const char* name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id);
  72. herr_t arma_H5Dwrite(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, const void* buf);
  73. hid_t arma_H5Dget_space(hid_t dataset_id);
  74. herr_t arma_H5Dread(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, void* buf);
  75. int arma_H5Sget_simple_extent_ndims(hid_t space_id);
  76. int arma_H5Sget_simple_extent_dims(hid_t space_id, hsize_t* dims, hsize_t* maxdims);
  77. herr_t arma_H5Sclose(hid_t space_id);
  78. hid_t arma_H5Screate_simple(int rank, const hsize_t* current_dims, const hsize_t* maximum_dims);
  79. herr_t arma_H5Ovisit(hid_t object_id, H5_index_t index_type, H5_iter_order_t order, H5O_iterate_t op, void* op_data);
  80. herr_t arma_H5Eset_auto(hid_t estack_id, H5E_auto_t func, void* client_data);
  81. herr_t arma_H5Eget_auto(hid_t estack_id, H5E_auto_t* func, void** client_data);
  82. hid_t arma_H5Fopen(const char* name, unsigned flags, hid_t fapl_id);
  83. hid_t arma_H5Fcreate(const char* name, unsigned flags, hid_t fcpl_id, hid_t fapl_id);
  84. herr_t arma_H5Fclose(hid_t file_id);
  85. htri_t arma_H5Fis_hdf5(const char* name);
  86. hid_t arma_H5Gcreate(hid_t loc_id, const char* name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id);
  87. hid_t arma_H5Gopen(hid_t loc_id, const char* name, hid_t gapl_id);
  88. herr_t arma_H5Gclose(hid_t group_id);
  89. htri_t arma_H5Lexists(hid_t loc_id, const char* name, hid_t lapl_id);
  90. herr_t arma_H5Ldelete(hid_t loc_id, const char* name, hid_t lapl_id);
  91. // Wrapper variables that represent the hid_t values for the H5T_NATIVE_*
  92. // types. Note that H5T_NATIVE_UCHAR itself is a macro that resolves to about
  93. // forty other macros, and we definitely don't want to hijack those,
  94. // so this is the best way to go about wrapping these...
  95. extern hid_t arma_H5T_NATIVE_UCHAR;
  96. extern hid_t arma_H5T_NATIVE_CHAR;
  97. extern hid_t arma_H5T_NATIVE_SHORT;
  98. extern hid_t arma_H5T_NATIVE_USHORT;
  99. extern hid_t arma_H5T_NATIVE_INT;
  100. extern hid_t arma_H5T_NATIVE_UINT;
  101. extern hid_t arma_H5T_NATIVE_LONG;
  102. extern hid_t arma_H5T_NATIVE_ULONG;
  103. extern hid_t arma_H5T_NATIVE_LLONG;
  104. extern hid_t arma_H5T_NATIVE_ULLONG;
  105. extern hid_t arma_H5T_NATIVE_FLOAT;
  106. extern hid_t arma_H5T_NATIVE_DOUBLE;
  107. }
  108. // Lastly, we have to hijack H5open() and H5check_version(), which are called
  109. // by some expanded macros of the other H5* functions. This means we can't
  110. // create arma_H5open(), because we can't modify those macros. Instead, we'll
  111. // create arma::H5open() and arma::H5check_version(), and then issue a using
  112. // directive so that arma::H5open() and arma::H5check_version() are always
  113. // called.
  114. //
  115. // There is potential danger in the use of a using directive like this, but in
  116. // this case, I can't think of a better way to solve the problem, and I doubt
  117. // this will cause problems in any situations that aren't truly bizarre. And
  118. // if it does cause problems, the user can #define ARMA_DONT_USE_WRAPPER or
  119. // #undef ARMA_USE_WRAPPER in their Armadillo configuration.
  120. herr_t H5open();
  121. herr_t H5check_version(unsigned majnum, unsigned minnum, unsigned relnum);
  122. using arma::H5open;
  123. using arma::H5check_version;
  124. #endif
  125. #endif