HdfFile.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #ifndef HDF4CPP_HDFFILE_H
  4. #define HDF4CPP_HDFFILE_H
  5. #include <string>
  6. #include <vector>
  7. #include <hdf4cpp/HdfObject.h>
  8. namespace hdf4cpp {
  9. class HdfItem;
  10. class HdfAttribute;
  11. /// Opens an hdf file and provides operations with it
  12. class HdfFile : public HdfObject {
  13. public:
  14. HdfFile(const std::string &path);
  15. HdfFile(const HdfFile &file) = delete;
  16. HdfFile(HdfFile &&file);
  17. HdfFile &operator=(const HdfFile &file) = delete;
  18. HdfFile &operator=(HdfFile &&file);
  19. ~HdfFile();
  20. int32 getSId() const;
  21. int32 getVId() const;
  22. /// \returns an item from the file with the given name
  23. /// \param name the name of the item
  24. /// \note: If there are multiple items with the same name then the first will be returned
  25. HdfItem get(const std::string &name) const;
  26. /// \returns all the items from the file with the given name
  27. /// \param name the name of the item(s)
  28. std::vector<HdfItem> getAll(const std::string &name) const;
  29. /// \returns the attribute with the given name
  30. /// \param name the name of the attribute
  31. HdfAttribute getAttribute(const std::string &name) const;
  32. class Iterator;
  33. Iterator begin() const;
  34. Iterator end() const;
  35. private:
  36. int32 getDatasetId(const std::string &name) const;
  37. int32 getGroupId(const std::string &name) const;
  38. int32 getDataId(const std::string &name) const;
  39. std::vector<int32> getDatasetIds(const std::string &name) const;
  40. std::vector<int32> getGroupDataIds(const std::string &name) const;
  41. int32 sId;
  42. int32 vId;
  43. std::vector<std::pair<int32, Type>> loneRefs;
  44. };
  45. /// HdfFile iterator, gives the possibility to iterate over the items in the file
  46. class HdfFile::Iterator : public HdfObject, public std::iterator<std::bidirectional_iterator_tag, HdfItem> {
  47. public:
  48. Iterator(const HdfFile *file, int32 index, const HdfDestroyerChain &chain)
  49. : HdfObject(HFILE, ITERATOR, chain)
  50. , file(file)
  51. , index(index) {
  52. }
  53. bool operator!=(const Iterator &it) {
  54. return index != it.index;
  55. }
  56. bool operator==(const Iterator &it) {
  57. return index == it.index;
  58. }
  59. Iterator &operator++() {
  60. ++index;
  61. return *this;
  62. }
  63. Iterator operator++(int) {
  64. Iterator it(*this);
  65. ++index;
  66. return it;
  67. }
  68. Iterator &operator--() {
  69. --index;
  70. return *this;
  71. }
  72. Iterator operator--(int) {
  73. Iterator it(*this);
  74. --index;
  75. return it;
  76. }
  77. HdfItem operator*();
  78. private:
  79. const HdfFile *file;
  80. int32 index;
  81. };
  82. }
  83. #endif // HDF4CPP_HDFFILE_H