H5PacketTable.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * Copyright by The HDF Group. *
  3. * Copyright by the Board of Trustees of the University of Illinois. *
  4. * All rights reserved. *
  5. * *
  6. * This file is part of HDF5. The full HDF5 copyright notice, including *
  7. * terms governing use, modification, and redistribution, is contained in *
  8. * the COPYING file, which can be found at the root of the source code *
  9. * distribution tree, or in https://www.hdfgroup.org/licenses. *
  10. * If you do not have access to either file, you may request a copy from *
  11. * help@hdfgroup.org. *
  12. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  13. /* Packet Table wrapper classes
  14. *
  15. * Wraps the H5PT Packet Table C functions in C++ objects
  16. *
  17. * Nat Furrer and James Laird
  18. * February 2004
  19. */
  20. #ifndef H5PTWRAP_H
  21. #define H5PTWRAP_H
  22. /* Public HDF5 header */
  23. #include "hdf5.h"
  24. #include "H5PTpublic.h"
  25. #include "H5api_adpt.h"
  26. class H5_HLCPPDLL PacketTable {
  27. public:
  28. /* Null constructor
  29. * Sets table_id to H5I_INVALID_HID
  30. */
  31. PacketTable();
  32. /* "Open" Constructor
  33. * Opens an existing packet table, which can contain either fixed-length or
  34. * variable-length packets.
  35. */
  36. PacketTable(hid_t fileID, const char *name);
  37. /* "Open" Constructor - will be deprecated because of char* name */
  38. PacketTable(hid_t fileID, char *name);
  39. /* Destructor
  40. * Cleans up the packet table
  41. */
  42. virtual ~PacketTable();
  43. /* IsValid
  44. * Returns true if this packet table is valid, false otherwise.
  45. * Use this after the constructor to ensure HDF did not have
  46. * any trouble making or opening the packet table.
  47. */
  48. bool IsValid() const;
  49. /* IsVariableLength
  50. * Return 1 if this packet table uses variable-length datatype,
  51. * return 0 if it is Fixed Length. Returns -1 if the table is
  52. * invalid (not open).
  53. */
  54. int IsVariableLength() const;
  55. /* ResetIndex
  56. * Sets the "current packet" index to point to the first packet in the
  57. * packet table
  58. */
  59. void ResetIndex() const;
  60. /* SetIndex
  61. * Sets the current packet to point to the packet specified by index.
  62. * Returns 0 on success, negative on failure (if index is out of bounds)
  63. */
  64. int SetIndex(hsize_t index) const;
  65. /* GetIndex
  66. * Returns the position of the current packet.
  67. * On failure, returns 0 and error is set to negative.
  68. */
  69. hsize_t GetIndex(int &error) const;
  70. /* GetPacketCount
  71. * Returns the number of packets in the packet table. Error
  72. * is set to 0 on success. On failure, returns 0 and
  73. * error is set to negative.
  74. */
  75. hsize_t GetPacketCount(int &error) const;
  76. hsize_t
  77. GetPacketCount()
  78. {
  79. int ignoreError;
  80. return GetPacketCount(ignoreError);
  81. }
  82. /* GetTableId
  83. * Returns the identifier of the packet table.
  84. */
  85. hid_t GetTableId() const;
  86. /* GetDatatype
  87. * Returns the datatype identifier used by the packet table, on success,
  88. * or FAIL, on failure.
  89. * Note: it is best to avoid using this identifier in applications, unless
  90. * the desired functionality cannot be performed via the packet table ID.
  91. */
  92. hid_t GetDatatype() const;
  93. /* GetDataset
  94. * Returns the dataset identifier associated with the packet table, on
  95. * success, or FAIL, on failure.
  96. * Note: it is best to avoid using this identifier in applications, unless
  97. * the desired functionality cannot be performed via the packet table ID.
  98. */
  99. hid_t GetDataset() const;
  100. /* FreeBuff
  101. * Frees the buffers created when variable-length packets are read.
  102. * Takes the number of hvl_t structs to be freed and a pointer to their
  103. * location in memory.
  104. * Returns 0 on success, negative on error.
  105. */
  106. int FreeBuff(size_t numStructs, hvl_t *buffer) const;
  107. protected:
  108. hid_t table_id;
  109. };
  110. class H5_HLCPPDLL FL_PacketTable : virtual public PacketTable {
  111. public:
  112. /* Constructor
  113. * Creates a packet table to store either fixed- or variable-length packets.
  114. * Takes the ID of the file the packet table will be created in, the ID of
  115. * the property list to specify compression, the name of the packet table,
  116. * the ID of the datatype, and the size of a memory chunk used in chunking.
  117. */
  118. FL_PacketTable(hid_t fileID, const char *name, hid_t dtypeID, hsize_t chunkSize = 0,
  119. hid_t plistID = H5P_DEFAULT);
  120. /* Constructors - deprecated
  121. * Creates a packet table in which to store fixed length packets.
  122. * Takes the ID of the file the packet table will be created in, the name of
  123. * the packet table, the ID of the datatype of the set, the size
  124. * of a memory chunk used in chunking, and the desired compression level
  125. * (0-9, or -1 for no compression).
  126. * Note: these overloaded constructors will be deprecated in favor of the
  127. * constructor above.
  128. */
  129. FL_PacketTable(hid_t fileID, hid_t plist_id, const char *name, hid_t dtypeID, hsize_t chunkSize);
  130. FL_PacketTable(hid_t fileID, char *name, hid_t dtypeID, hsize_t chunkSize, int compression = 0);
  131. /* "Open" Constructor
  132. * Opens an existing fixed-length packet table.
  133. * Fails if the packet table specified is variable-length.
  134. */
  135. FL_PacketTable(hid_t fileID, const char *name);
  136. /* "Open" Constructor - will be deprecated because of char* name */
  137. FL_PacketTable(hid_t fileID, char *name);
  138. /* Destructor
  139. * Cleans up the packet table
  140. */
  141. virtual ~FL_PacketTable()
  142. {
  143. }
  144. /* AppendPacket
  145. * Adds a single packet to the packet table. Takes a pointer
  146. * to the location of the data in memory.
  147. * Returns 0 on success, negative on failure
  148. */
  149. int AppendPacket(void *data);
  150. /* AppendPackets (multiple packets)
  151. * Adds multiple packets to the packet table. Takes the number of packets
  152. * to be added and a pointer to their location in memory.
  153. * Returns 0 on success, -1 on failure.
  154. */
  155. int AppendPackets(size_t numPackets, void *data);
  156. /* GetPacket (indexed)
  157. * Gets a single packet from the packet table. Takes the index
  158. * of the packet (with 0 being the first packet) and a pointer
  159. * to memory where the data should be stored.
  160. * Returns 0 on success, negative on failure
  161. */
  162. int GetPacket(hsize_t index, void *data);
  163. /* GetPackets (multiple packets)
  164. * Gets multiple packets at once, all packets between
  165. * startIndex and endIndex inclusive. Also takes a pointer to
  166. * the memory where these packets should be stored.
  167. * Returns 0 on success, negative on failure.
  168. */
  169. int GetPackets(hsize_t startIndex, hsize_t endIndex, void *data);
  170. /* GetNextPacket (single packet)
  171. * Gets the next packet in the packet table. Takes a pointer to
  172. * memory where the packet should be stored.
  173. * Returns 0 on success, negative on failure. Index
  174. * is not advanced to the next packet on failure.
  175. */
  176. int GetNextPacket(void *data);
  177. /* GetNextPackets (multiple packets)
  178. * Gets the next numPackets packets in the packet table. Takes a
  179. * pointer to memory where these packets should be stored.
  180. * Returns 0 on success, negative on failure. Index
  181. * is not advanced on failure.
  182. */
  183. int GetNextPackets(size_t numPackets, void *data);
  184. };
  185. /* Removed "#ifdef VLPT_REMOVED" block. 03/08/2016, -BMR */
  186. #endif /* H5PTWRAP_H */